[GH-ISSUE #1394] Example on using wifimanager with deep sleep #1193

Open
opened 2026-02-28 01:28:57 +03:00 by kerem · 5 comments
Owner

Originally created by @kargarisaac on GitHub (Apr 14, 2022).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1394

Hi,

Is there any simple esp32 example on how to use wifimanager with deep sleep? I have to configure wifi credentials after each deep sleep/wake up round. I couldn't find any example over the internet.

Thank you

Originally created by @kargarisaac on GitHub (Apr 14, 2022). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1394 Hi, Is there any simple esp32 example on how to use wifimanager with deep sleep? I have to configure wifi credentials after each deep sleep/wake up round. I couldn't find any example over the internet. Thank you
Author
Owner

@tablatronix commented on GitHub (Apr 14, 2022):

hmm perhaps try rebooting after save, wifi creds should be persistent.

do you have example code? I have not used it much or tested it

<!-- gh-comment-id:1099422683 --> @tablatronix commented on GitHub (Apr 14, 2022): hmm perhaps try rebooting after save, wifi creds should be persistent. do you have example code? I have not used it much or tested it
Author
Owner

@gfaman commented on GitHub (Aug 14, 2022):

Hi,
I spent countless time to try to find a reconnection solution with WM after deep sleep or light sleep. It never reconnect by itself.
Read many comments, proposals. Seems it should be reconnected by itself but never in my case.

The first solution but not recommended by Tablatronix was to add a loop with wifiManager.autoConnect("ESP_AP", "12345678") after the sleep if Wifi not connected. It works sometimes but also it create self reset. Not reliable.

Finally, it seems I found a solution for light_sleep (need test on deep_sleep):

  • Add esp_wifi_stop(0 before the call light_sleep and esp_wifi_start() after the sleep instruction.
  • Then test Wifi connection, if not connected, WiFi.reconnect()
  • If still not connected WiFi.begin();

I didn t figure out yet which part makes the connection, the reconnect or the begin but definitively, the stop and start make the job.
Hope it is helping.

Laurent

<!-- gh-comment-id:1214395638 --> @gfaman commented on GitHub (Aug 14, 2022): Hi, I spent countless time to try to find a reconnection solution with WM after deep sleep or light sleep. It never reconnect by itself. Read many comments, proposals. Seems it should be reconnected by itself but never in my case. The first solution but not recommended by Tablatronix was to add a loop with wifiManager.autoConnect("ESP_AP", "12345678") after the sleep if Wifi not connected. It works sometimes but also it create self reset. Not reliable. Finally, it seems I found a solution for light_sleep (need test on deep_sleep): - Add esp_wifi_stop(0 before the call light_sleep and esp_wifi_start() after the sleep instruction. - Then test Wifi connection, if not connected, WiFi.reconnect() - If still not connected WiFi.begin(); I didn t figure out yet which part makes the connection, the reconnect or the begin but definitively, the stop and start make the job. Hope it is helping. Laurent
Author
Owner

@tablatronix commented on GitHub (Aug 14, 2022):

hmm i started a test somewhere and forgot about it, you definitely have to manually handle the wifi state, I know i found at least one bug in wm for this, I think i fixed it, but not in reconnect, only autoconnect

<!-- gh-comment-id:1214461364 --> @tablatronix commented on GitHub (Aug 14, 2022): hmm i started a test somewhere and forgot about it, you definitely have to manually handle the wifi state, I know i found at least one bug in wm for this, I think i fixed it, but not in reconnect, only autoconnect
Author
Owner

@gfaman commented on GitHub (Aug 15, 2022):

Thanks Shawn for your consideration. So far, that workaround is working. Only one reset during the night (after multiple tentatives for reconnection).
Honestly, I'm quite surprising that not many people discussed about this reconnection issue after sleep mode. Not sure it is only me and my particular case.
For sake of clarity, please find the workaround I'm using:

esp_wifi_stop();
ret = esp_light_sleep_start();  /////////////////////////////////////////////////// SLEEP //////////////////////////////////////////////
Serial.printf("light_sleep: %d\n", ret);
esp_wifi_start();
TRACE_WAKE_UP;

// delay(period * 1000);
delay(500);
uint16_t loop = 0;
if(WiFi.status() != WL_CONNECTED)
{
TRACE_WIFI_DISCONNECTED_SLEEP;
WiFi.reconnect();
delay(1000);
if(WiFi.status() != WL_CONNECTED)
{
WiFi.begin();
}
}
while(WiFi.status() != WL_CONNECTED)
{
Serial.println("Wifi disconnected. Need reconnect");
Serial.println("failed to connect and hit timeout");
delay(300);
if(loop++ >= (31560))// 15 min
{
TRACE_WIFI_SLEEP;
ESP.restart();
delay(5000);
}
}

<!-- gh-comment-id:1214673779 --> @gfaman commented on GitHub (Aug 15, 2022): Thanks Shawn for your consideration. So far, that workaround is working. Only one reset during the night (after multiple tentatives for reconnection). Honestly, I'm quite surprising that not many people discussed about this reconnection issue after sleep mode. Not sure it is only me and my particular case. For sake of clarity, please find the workaround I'm using: esp_wifi_stop(); ret = esp_light_sleep_start(); /////////////////////////////////////////////////// SLEEP ////////////////////////////////////////////// Serial.printf("light_sleep: %d\n", ret); esp_wifi_start(); TRACE_WAKE_UP; // delay(period * 1000); delay(500); uint16_t loop = 0; if(WiFi.status() != WL_CONNECTED) { TRACE_WIFI_DISCONNECTED_SLEEP; WiFi.reconnect(); delay(1000); if(WiFi.status() != WL_CONNECTED) { WiFi.begin(); } } while(WiFi.status() != WL_CONNECTED) { Serial.println("Wifi disconnected. Need reconnect"); Serial.println("failed to connect and hit timeout"); delay(300); if(loop++ >= (3*15*60))// 15 min { TRACE_WIFI_SLEEP; ESP.restart(); delay(5000); } }
Author
Owner

@gfaman commented on GitHub (Aug 17, 2022):

After few days on 2 different devices, results is soso. One device reset only one time per day. It is fine. But the other one, probably link to the Wifi router configuration, continuously reset after each light_sleep. Need fallback to delay() instead of light_sleep. No solution for that device. Only, before, by recall wifiManager.autoConnect after the sleep, it works sometimes.

<!-- gh-comment-id:1218005086 --> @gfaman commented on GitHub (Aug 17, 2022): After few days on 2 different devices, results is soso. One device reset only one time per day. It is fine. But the other one, probably link to the Wifi router configuration, continuously reset after each light_sleep. Need fallback to delay() instead of light_sleep. No solution for that device. Only, before, by recall wifiManager.autoConnect after the sleep, it works sometimes.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/WiFiManager#1193
No description provided.