Environment variable question

Hello,
I have set an environment variable in Notehub in the device specific location. The key is ENV_test the value is 999.
With this code:
J *req = NoteNewRequest(“env.get”);
JAddStringToObject(req, “name”, “ENV_Test”);
NoteRequest(req);

In the serial monitor I get this: [INFO] {“text”:“999”}

My question is how do I extract the value 999 to use in my code? For instance if I want to add 1 to 999?
Thank you for your help.
Tom

Hey @TJK,

You’ll need to use the Notecard SDK’s requestAndResponse method to retrieve the value out of the response. Try this:

int env_test = 0;
J *req = NoteNewRequest("env.get");
JAddStringToObject(req, "name", "ENV_Test");
if (J *rsp = notecard.requestAndResponse(req))
{
    env_test = JGetNumber(rsp, "text");
    notecard.deleteResponse(rsp);
}

TJ

1 Like

Thank you TJ,
I did this:
int env_test = 111;
J req = NoteNewRequest(“env.get”);
JAddStringToObject(req, “name”, “ENV_Test”);
if (J rsp = notecard.requestAndResponse(req))
{
env_test = JGetNumber(rsp, “text”);
notecard.deleteResponse(rsp);
}
Serial.print("
“);
Serial.print(env_test);
Serial.println(”
******");

The statement Serial.print(env_test); prints zero. I changed the initialization form zero to 111 to see if that was the hangup but no, it still prints 0

I just tried the Lat and long code you just posted a few minutes ago. I get zeros for lat and long as well

Ah that’s right it comes back as a string. Try this:

env_test = atoi(JGetString(rsp, "text"));

TJ

1 Like

Thank you TJ. You are my favorite genius.
Tom

1 Like