This is my udp read function, which calls a SparkJson parsing function when it works.
The first call is flawless, I am definitely receiving a good data packet over UDP (The packet is ~772 bytes). After that, the JSON object in the second function at the bottom doesn’t appear to update anymore, and the values I pull from thee JSON object don’t change. But I have verified that they are changing.
So I don’t know if the UDP is returning the same data for some reason, or if the parser is not working.
void checkUdp()
{
int rxErr = 0;
int count = udp.receivePacket(tempStatus, 1023); //tempStatus is declared as a global char tempStatus[1024]
if (count >= 0 && count < 1024) {
tempStatus[count] = 0;
rxErr = 0;
parseTempStatus(tempStatus);
} else if (count < -1) {
rxErr = count;
// need to re-initialize on error
udp.begin(udpListenPort);
}
if (!rxErr) {
//No Error code, but this could mean count = -1, which is no packet
}
}
void parseTempStatus(char* tempJSON)
{
StaticJsonBuffer<4096> jsonBuffer; //This is probably bigger than it needs to be, but not by much
JsonObject& root = jsonBuffer.parseObject(tempJSON);
displayInfo[0] = "Temp: " + String::format("%.1fF",root["Sensor"]["temp"]);
displayInfo[1] = String(Time.local());
displayInfo[2] = "Last: " + String::format("%d", root["Sensor"]["TS"]);
blinkLED();
}