@@ -75,6 +75,23 @@ J *NoteNewRequest(const char *request) {
7575 return reqdoc ;
7676}
7777
78+ /**************************************************************************/
79+ /*!
80+ @brief Create a new command object to populate before sending to the Notecard.
81+ Lock for mutual exclusion, not only because access to the card must be serialized, but also because
82+ both C++ and ArduinoJSON call malloc() which is not a thread-safe operation.
83+ @param request
84+ The name of the command, for example `hub.set`.
85+ @returns a `J` cJSON object with the request name pre-populated.
86+ */
87+ /**************************************************************************/
88+ J * NoteNewCommand (const char * request ) {
89+ J * reqdoc = JCreateObject ();
90+ if (reqdoc != NULL )
91+ JAddStringToObject (reqdoc , c_cmd , request );
92+ return reqdoc ;
93+ }
94+
7895/**************************************************************************/
7996/*!
8097 @brief Send a request to the Notecard.
@@ -174,6 +191,13 @@ char *NoteRequestResponseJSON(char *reqJSON) {
174191/**************************************************************************/
175192J * NoteTransaction (J * req ) {
176193
194+ // Validate in case of memory failure of the requestor
195+ if (req == NULL )
196+ return NULL ;
197+
198+ // Determine whether or not a response will be expected, by virtue of "cmd" being present
199+ bool noResponseExpected = (JGetString (req , "req" )[0 ] == '\0' && JGetString (req , "cmd" )[0 ] != '\0' );
200+
177201 // If a reset of the module is required for any reason, do it now.
178202 // We must do this before acquiring lock.
179203 if (resetRequired ) {
@@ -198,7 +222,11 @@ J *NoteTransaction(J *req) {
198222
199223 // Pertform the transaction
200224 char * responseJSON ;
201- const char * errStr = _Transaction (json , & responseJSON );
225+ const char * errStr ;
226+ if (noResponseExpected )
227+ errStr = _Transaction (json , NULL );
228+ else
229+ errStr = _Transaction (json , & responseJSON );
202230
203231 // Free the json
204232 JFree (json );
@@ -211,6 +239,12 @@ J *NoteTransaction(J *req) {
211239 return rsp ;
212240 }
213241
242+ // Exit with a blank object (with no err field) if no response expected
243+ if (noResponseExpected ) {
244+ _UnlockNote ();
245+ return JCreateObject ();
246+ }
247+
214248 // Parse the reply from the card on the input stream
215249 J * rspdoc = JParse (responseJSON );
216250 if (rspdoc == NULL ) {
0 commit comments