logo elektroda
logo elektroda
X
logo elektroda

ESP8266 limiting WiFi connection attempts and deep sleep

pier 471 1
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18505490
    pier
    Level 24  
    Welcome.

    I have an ESP8266 based weather sensor powered by a solar assisted battery. The esp is most of the time in deep sleep, wakes up every 30min or so and sends measurement data.
    The problem occurs when the esp doesn't see the wifi network, then instead of going to sleep after trying to connect indefinitely I guess it tries to connect and drains the battery unnecessarily.

    How do I make the ESP make say five attempts at intervals of a few seconds and if it fails to connect go to sleep for another 30min?

    Code: C / C++
    Log in, to see the code
    .
  • ADVERTISEMENT
  • #2 18505576
    khoam
    Level 42  
    Use WiFi.status() after WiFi.begin(). Check for as long as you like - if there is no connection, put it to sleep.
    Right now, in a loop() you are "draining" the battery by calling WiFi.begin() continuously, without checking the connection status.

    https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/readme.html#quick-start
    https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/readme.html#check-return-codes

    I don't understand why you put ESP.deepSleep() in loop(). Waking up from deep-sleep is like a reset (it just doesn't clear some memory for the RTC).
    So putting WiFi.begin() and Blynk.begin() in loop() is also pointless, it should be in setup().
ADVERTISEMENT