So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Theboatbuilder
#74862 I wrote a simple JSON parser which worked fine on my Ethernet Arduino board but wont transfer to my ESP8266 Feather Huzzah (Adafruit).
It appears to fall over at the client.findUntil() command.

Here is the subroutine;

void parseJSON()
{
DEBUG_PRINTLN(F("Parsing JSON"));
String tideTimeStr[7]; // time of each high or low tide as a string
String tideHeightStr[7]; // tide height at this state (not currently used)
String tideStateStr[7]; // tide state at this time
while (client.connected())
{
if (client.available())
{
DEBUG_PRINT(F("Client Available"));
if(client.findUntil("station\":\"", '\0'))
{
DEBUG_PRINTLN(F("findUntil"));
String station = client.readStringUntil('"');
DEBUG_PRINT(F("Station = "));
DEBUG_PRINTLN(station);
}
for (int i = 0 ; i < 6 ; i++) // 6 tide periods in each API call
{ // Acquire time, height, type (high or low)
if(client.findUntil("dt\":", '\0')) // adding this if statements stops it continuing when all periods are discovered
{
// Tide time as Epoch time
tideTimeStr[i] = client.readStringUntil(',');
DEBUG_PRINT(F("Tide Period "));
DEBUG_PRINT(i);
DEBUG_PRINT(F(" starting Epoch = "));
tideEpochTime[i] = tideTimeStr[i].toInt(); // convert time string to integer
DEBUG_PRINT(tideEpochTime[i]);

// Tide height
client.findUntil("height\":", '\0');
tideHeightStr[i] = client.readStringUntil(',');
DEBUG_PRINT(F(" Height = "));
tideHeight[i] = tideHeightStr[i].toFloat(); // convert tide height to a float
DEBUG_PRINTDP(tideHeight[i],3);

// Tide type
client.findUntil("type\":\"", '\0');
tideStateStr[i] = client.readStringUntil('"');
tideState[i] = tideStateStr[i].charAt(0);
DEBUG_PRINT(F(" State "));
DEBUG_PRINT(F(" = "));
DEBUG_PRINTLN(tideState[i]);
}
}
}
}
client.stop();
}

Any assistance would be most welcome.