Hi guys. First of all I want to apologize for my English, I am a native speaker of Spanish.
Days ago I’m trying to read the data I get from a webhook that connects to a Firebase database. I just want to read two data sent in a Firebase json (temMax and tempMin).
This is my code to test that function (provided by the webhook that I created):
void setup() {
Particle.subscribe("hook-response/seteoTemperatura", myHandler, MY_DEVICES);
}
void loop() {
String data = String(10);
Particle.publish("seteoTemperatura", data, PRIVATE);
delay(6000);
}
void myHandler(const char *event, const char *data) {
// In this function I do not know what to do.
}
The data contained in the json file are just these: {"tempMax":15,"tempMin":10}
If you observe, Particle.publish (“set Temperature”, data, PRIVATE); print the value 10 on the console. If only I could read the other value (15) my problem would be serious, but I do not know what to do anymore.
There are many ways to do this. One way is to use a JSON parser library; I like JsonParserGeneratorRK.
Add a global variable:
JsonParserStatic<512, 50> jsonParser;
Add this in myHandler:
jsonParser.addString(data);
if (jsonParser.parse()) {
int tempMax;
jsonParser.getOuterValueByKey("tempMax", tempMax);
int tempMin;
jsonParser.getOuterValueByKey("tempMin", tempMin);
// Put code to do something with tempMin and tempMax here
}
I feel like I’m asking stupid questions and I’m very embarrassed, but I reached the limit that I had no choice but to go and bother them with questions