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.