ESP8266 WifiClient Error

I’ve been writing some code for the ESP8266, using it to send sensor data to a server, to be logged and charted. I started with the WifiClient example, from the ESP8266 Arduino board manager.

I modified the example code to use multiple sensors, and came upon an issue. The board started resetting itself, leading me to think I had a hardware issue, especially since two boards were doing it.

I was receiving this error on the serial line

ets Jan  8 2013,rst cause:2, boot mode:(1,7)
ets Jan  8 2013,rst cause:4, boot mode:(1,7)
wdt reset

The watchdog seemed to be unhappy, and was resetting the processor.

I had commented out the following line, right after the data transfer had been started.

String line = client.readStringUntil('\r');

String line = client.readStringUntil(‘\r’); empties the read buffer, and is crucial, even if you don’t do anything with the results.

Putting this line back in fixes all issues.

So if you’re having issues with that sketch, with random watchdog resets, make sure you are reading the return data to clear the buffer, and keep the watchdog happy.