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

User avatar
By timj_1
#68340 Hi there

I wonder if anyone would be kind enough to help me with a small problem. I have built and designed a small circuit that uses the esp8266 to send data to Thingspeak.com. It works brilliantly except for one small or big flaw. It is battery operated and uses deep sleep to save power, however it drains the battery when the internet connection is down or fails to connect by constant repeated attempts to connect.
I wish to limit the connection attempts to say 3 goes and then simply miss the current reading and go to deep sleep as would happen normally.

My code is the standard connection routine

WiFi.disconnect();
WiFi.begin("VM172234-2G","Pasword");
while ((!(WiFi.status() == WL_CONNECTED))){
delay(300); }

I am sure a simple and elegant solution is easy

Thanks in advance

Tim
User avatar
By btidey
#68374 initialise a variable attempts = 0 before the while loop, increment attempts inside the loop and change the condition to terminate if either status is OK or attempts > 3