I am trying to use a JSON string as a control string, so I can pass a bunch of arguments as a group (rather than with multiple cloud function calls).
The argument would look like this, and I am using a Particle.function() call:
{"opMode":1, "brightness":500, "period":2500,"msg":"ABC123"}
My code for the function:
int processControl(String command){
char conString[200];
command.toCharArray(conString, sizeof(conString));
StaticJsonBuffer<200> jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(conString);
if(root["brightness"]>0) {
Brightness = root["brightness"];
}
if(root["opMode"]>0) {
OperationMode=root["opMode"];
}
if(root["period"]>0) {
loopPeriod=root["period"];
}
return 0;
}
I copied this verbatim from code that I wrote 2-3 years ago that worked. Now it’s not working at all.
-
Why is this not working?
-
I am using the IFs to check if the values are >0 to validate whether or not the parameters are even in the JSON. Is there a way to know whether or not they were even included? That is, I’d like to be able to send zero as an argument, or ignore that setting if it’s absent.
-
I am having ZERO luck setting root[“stringValue”] to a String type.
thanks!