-->
Page 1 of 1

findUntil() command crashes my ESP8266 Feather Huzzah

PostPosted: Sat Mar 24, 2018 4:38 am
by Theboatbuilder
findUntil() command crashes my ESP8266 Feather Huzzah

I have used this successfully on an Ethernet Arduino combination without issue.
Moveing to the ESP8266 to do the same but on WiFi crashes the processor.

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();
}
I hope there is a simple solution.

Many thanks in advance

Mark

Re: findUntil() command crashes my ESP8266 Feather Huzzah

PostPosted: Sun Mar 25, 2018 7:54 am
by Theboatbuilder
I have found my own solution.

if(client.findUntil("station\":\"", '\0'))

should be replaced by

if(client.findUntil("station\":\"", "\n\r"))

The devil is in the detail.

Thank you to all those who took the time to read my question.