Hi guys. This code reads the information received from a webhook.
I want to call the “myHandler” function every 6 seconds in a loop to read if there is updated data. At the moment for some reason the function “myHandler” after being called about 5 times stops and does not return to consult the data.
I am new in this language, I hope I am not asking a very silly question.
I appreciate any help!! Thank you very much.
Regards!!
Right now myHandler is the callback for the webhook subscription. Why do you want to call it every 6 seconds when it should only run in response to the webhook?
You may need to rethink what you are trying to achieve.
Hi @nrobinson2000 thanks for your response. The truth, I feel a little lost with the functioning of webhooks.
What happens is that when I update the data from Firebase, the webhook immediately updates perfectly showing in console the new values. But the "myHandler" function that is responsible for interpreting the Json is not recalled, this causes the variables "tempMax" and "tempMin" to obtain the values of the initial call and then when the webhook is updated, these variables do not make.
I hope you understand what I'm trying to explain, I apologize for my bad English.
Try printing out the raw data and event name strings to see whether your webhook-response is what you expect.
Also check the console, whether the subscribe filter matches what your response even is.
Post screenshots of the console event log plus the raw data.
Squanchy please do, i’m really interested myself. thanks for all the help here! appreciating a lot. i need lots of help with my site https://suppsforlife.to/category/pct/ as there something isn’t well going out. thanks
Then I update the data in Firebase and I see that the webhook brings the data correctly ({“tempMax”: 20, “tempMin”: 12}). But what really interests me is that the variables “max” and “min” update their new values. Currently it remains with the first value obtained.
This would suggest the jsonParser has some issues validating the incoming data.
In order to locate issues with your code one of the steps you always should take first is to add as many Serial.print() statements as you can to see what your code is internally doing and where it’s failing to do what you want.
e.g.
void myHandler(const char *event, const char *data) {
bool b;
Serial.printlnf("%s: %s", event, data);
b = jsonParser.addString(data);
Serial.printlnf("addString() returned %s", b ? "true" : "false");
Serial.printlnf("Buffer contains '%s' (%d)", jsonParser.getBuffer(), jsonParser.getBufferLen());
if (jsonParser.parse()) {
b = jsonParser.getOuterValueByKey("tempMax", tempMax);
Serial.printlnf("getOuterValueByKey(%s, %d) returned %s", "tempMax", tempMax, b ? "true" : "false");
b = jsonParser.getOuterValueByKey("tempMin", tempMin);
Serial.printlnf("getOuterValueByKey(%s, %d) returned %s", "tempMin", tempMin, b ? "true" : "false");
}
else
Serial.println("parse() failed");
}
But what I think is happening is that you always add data to the end of the JSON buffer, but keep parsing from the beginning which still starts with the old data.
Try adding a jsonParser.clear() call before adding data.
@ScruffR you gave me a double solution!! The "myHandler" method worked perfectly, but I also tried using jsonParser.clear () before calling data and it also worked perfect!
Thank you very much!!
Squanchy please do, i’m really interested myself. thanks for all the help here! appreciating a lot.
@Markmand I hope the help I received has served you too.
Thanks to everyone who helped me, especially to@ScruffR
Regards!!