Command-and-control architecture note.get questions

I’m working on an application of the notecard for remote control of an entry gate. I’ve used the Notehub JS library to create a simple webpage that contains a ‘gate open’ button that sends a {“command”: “open”} pair to Notehub and receive it in a data.qi file. This part works. I now need to get that to the Notecard and the Swan MCU to process it. I’m by no means a software developer, so please keep that in mind. In reading though the various guides, I see information that appears slightly different and I am not knowledgeable enough to know if both are correct and are different methods or why one is used over the other. Here is what I am talking about:

In the Notecard API documentation for note.get it provides this C code:

J *req = NoteNewRequest(“note.get”);
JAddStringToObject(req, “file”, “requests.qi”);
JAddBoolToObject(req, “delete”, true);

NoteRequest(req);

In this guide, Remote Command and Control - Blues Developers, it shows this:

J *req = notecard.newRequest(“note.get”);
JAddStringToObject(req, “file”, “data.qi”);
JAddBoolToObject(req, “delete”, true);

Why the two different versions of the J *req line? Which to use?

Also, for my application, the usage will be very low, maybe once or twice every couple of weeks or even months. It would seem that having the Notecard in continuous mode may not be necessary, but a proper periodic timeframe is impossible to know. Having my webpage also send a ‘wake up to continuous mode’ before initiating the open gate sequence would seem a logical thing to do. I searched thru the forum and found some references to using the reserved environmental variables to do this (I think). In this topic, Remote control notecard - #4 by tjvantoll, TJ suggests that

" The environment variables allow you to remotely switch your Notecard’s mode , and to change your inbound and outbound values. However, you need to run a {"req":"hub.set","reset":true} request after enabling continuous mode, as the Notecard requires a reset to set up a socket to listen for inbound .qi changes."

How does one go about running the {“req”:“hub.set”,“reset”:true} request from code either at the Notehub level or webpage? After the gate actions are complete is there a similar way to set the Notecard back to periodic? Thanks.

Hi @sn13TX,

Why the two different versions of the J *req line? Which to use?

The first is using note-c (Notecard’s C library) and the second is using note-arduino (Notecard’s Arduino library). (note-arduino actually uses note-c behind the scenes too!)

If you’re developing with Arduino, I would recommend using that library.

How does one go about running the {“req”:“hub.set”,“reset”:true} request from code either at the Notehub level or webpage? After the gate actions are complete is there a similar way to set the Notecard back to periodic?

Considering your scenario, is it feasible for the Notecard to NOT be in continuous mode? I’m just wondering, as I imagine opening/closing an entry gate should be an immediate process - not something you are waiting minutes and minutes for the Notecard to next sync?

To answer your question though, I would build that “reset” command into your firmware logic. For example, when you detect that the environment variable has changed (e.g. via an env.get request), then issue that hub.set/reset command.

Rob

Thanks for the quick response Rob.

‘If you’re developing with Arduino’ - I guess I’m not sure on this. I’m not using the Arduino IDE nor an Arduino, but I am using VSC with the Arduino.h library. So I guess I could use either or both?

In regard to the ‘is it feasible for the Notecard to NOT be in continuous mode’ question, that is what I am trying to determine. My thought is that if it is in continuous mode the cellular state is always connected and requires more power. I guess if this is the case and no data is being transmitted, then my only ‘cost’ for this is power consumption, is that correct? If I am trying to conserve power and I can switch the Notecard from periodic to continuous via an external instruction via Notehub (using the reserved environmental values) , then it seems I would only need to wait for the cellular connection to be made in order for my gate control code to be able to function. If that takes less than 2 minutes for the cellular connection that’s not really a negative for this particular application.

Hi @sn13TX,

You can use either library, but generally I would recommend note-arduino as there are some safeguards in there that don’t exist in note-c.

Keep in mind that all cellular connections are initiated from the Notecard. So even if you tried to tell a Notecard to switch from periodic to continuous mode, you’d still have to wait for the Notecard to perform its next periodic sync for it to update the mode!

The main drawback of using continuous mode is power consumption. There are some data usage considerations to keep in mind as well, but are generally minimal if you’re not transmitting much data.

Rob