Reasonable frequency to check environmental variables

I have several Environmental Variables defined. A few of these will not change often and some will be updated more frequently. My question is when running this code(below) to get the EV what is a reasonable frequency to check? Once per minute, second hour. I am trying to avoid making too many requests on notehub.io.
J* req = notecard.newRequest(“env.get”);
if (req != NULL) {
JAddStringToObject(req, “name”, “reading_interval”);
J* rsp = notecard.requestAndResponse(req);
int readingIntervalEnvVar = atoi(JGetString(rsp, “text”));
if (readingIntervalEnvVar > 0) {
sensorIntervalSeconds = readingIntervalEnvVar;
}
notecard.deleteResponse(rsp);
}
defaultInterval=sensorIntervalSeconds;

Hi @TJK,

Just to be clear - a call to env.get is a request to the Notecard, not Notehub. Environment variables are synced only when the Notecard and Notehub are in communication. It’s really up to you how often you connect/sync with Notehub. If data usage is a concern I would recommend looking at our guide on data usage estimates to find the right balance of settings and sync cadence.

The best technique for polling the Notecard is to poll using env.modified every 15 seconds or however often it is convenient for the host. Only if env.modified indicates that an environment variable has changed would you then call env.get to refresh the environment variable values on the host.

Rob

1 Like

Thank you. I understand.
Can you please point me in the direction of a tutorial illustrating the implementation of the concept? I assume I will provide the time of the last lookup or save the previous returned time. Unix time suggests millis() may not be the best choice.

Hi @TJK,

We have a couple of environment variable resources to share:

  1. This guide on Understanding Environment Variables is a good place to start
  2. All of these open source Accelerator apps use environment variables extensively, so there should be a code example or two to borrow from.

Let us know if you need any help though!
Rob

2 Likes