[GH-ISSUE #1585] Can not reconnect to saved AP after config portal timeout. #1351

Open
opened 2026-02-28 01:29:43 +03:00 by kerem · 0 comments
Owner

Originally created by @olonsoft on GitHub (Apr 12, 2023).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1585

Basic Infos

Hardware

WiFimanager Branch/Release: Master latest git of 2023-04-12
Esp8266
Hardware: ESP-12e
Espressif 8266 (4.2.0) > NodeMCU 1.0 (ESP-12E Module)

Description

The case is this:
My program connects to WiFi in setup by calling wm.autoConnect(...);
In loop() I check if the WiFi is connected and if not I start the configPortal(...)
While connected, I turn off my AP so the ESP disconnects and my code starts the configPortal.
A few seconds later, I turn on my AP and wait for the captive portal to timeout (I have set it to 180 secs).
According to the WiFiManager code, when the configPortal ends, it should reconnect to the previous wifi. But instead, I see in the log "WL_STATION_WRONG_PASSWORD" and don't know where it comes from.
So my code detects that the wifi is not connected and starts the configPortal again. And this loop continues forever.

*wm:[3] Connection result: WL_CONNECTED
*wm:[2] AutoConnect: SUCCESS 
*wm:[3] Connected in 5278 ms
*wm:[2] STA IP Address: 192.168.1.241
*wm:[4] hostname: STA:  demo-app-D53FAF
0T00:00:05.578 [I] [WiFiM] Connected to wifi. 
// I turn off my WiFi AP
0T00:00:40.638 [W] {wifimanager_wrapper.cpp:227 loopWiFiManager()} [WiFiM] WiFi Disconnected. Hardware auto reconnect is being tried... 
// Here I turn on my wifi AP in time to reconnect before the captive portal starts.
0T00:00:51.070 [I] [WiFiM] WiFi reconnected.
// Here I turn off my WiFi AP again.
0T00:01:05.169 [W] {wifimanager_wrapper.cpp:227 loopWiFiManager()} [WiFiM] WiFi Disconnected. Hardware auto reconnect is being tried...       
0T00:01:35.170 [E] {wifimanager_wrapper.cpp:236 loopWiFiManager()} [WiFiM] Can not auto reconnect to WiFi within 30secs.
0T00:01:35.183 [W] {wifimanager_wrapper.cpp:256 runCaptivePortal()} [WiFiM] Starting config portal...
*wm:[3] Starting Config Portal
*wm:[3] AccessPoint set password is VALID 
*wm:[4] ap pass 12345678
*wm:[4] WiFi station disconnect
*wm:[4] WiFi_enableSTA enable
*wm:[3] Disabling STA
*wm:[3] Enabling AP
*wm:[2] StartAP with SSID:  App-18FE34D53FAF
*wm:[2] SoftAP Configuration 
*wm:[2] --------------------
*wm:[2] ssid:             App-18FE34D53FAF // <-- A
*wm:[2] password:         12345678
*wm:[2] ssid_len:         16
*wm:[2] channel:          1
*wm:[2] authmode:         3
*wm:[2] ssid_hidden:
*wm:[2] max_connection:   4
*wm:[2] country:          CN
*wm:[2] beacon_interval:  100(ms)
*wm:[2] --------------------
*wm:[2] AP IP address: 192.168.4.1    
*wm:[3] [CB] _apcallback calling
0T00:01:37.115 [W] {wifimanager_wrapper.cpp:091 captivePortalStartedCallback()} [WiFiM] Captive portal started. IP (IP unset)
*wm:[4] setupConfigPortal
*wm:[2] Starting Web Portal
*wm:[3] [CB] _webservercallback calling 
0T00:01:37.133 [W] {wifimanager_wrapper.cpp:096 webPortalStartedCallback()} [WiFiM] Web portal started. IP (IP unset)
*wm:[3] HTTP server started 
*wm:[3] WiFi Scan ASYNC started
*wm:[4] setupDNSD 
*wm:[4] dns server started with ip:  192.168.4.1
*wm:[3] Config Portal Running, non blocking (processing)
*wm:[3] Portal Timeout In 180 seconds
*wm:[3] Portal Timeout In 177 seconds    
// --------  While I am here I turn on my WiFi AP --------
*wm:[3] WiFi Scan ASYNC completed in 2289 ms
*wm:[3] WiFi Scan ASYNC found: 6
*wm:[3] Portal Timeout In 147 seconds
*wm:[3] Portal Timeout In 117 seconds
*wm:[3] Portal Timeout In 87 seconds
*wm:[3] Portal Timeout In 57 seconds
*wm:[3] Portal Timeout In 27 seconds
*wm:[2] config portal has timed out 
*wm:[4] process loop abort
*wm:[3] shutdownConfigPortal
:ur 1
*wm:[3] restoring usermode STA
*wm:[3] WiFi Reconnect, was idle 
*wm:[3] wifi status: WL_STATION_WRONG_PASSWORD  ////// <---- What password is wrong ?
*wm:[3] wifi mode: STA
*wm:[3] configportal closed
*wm:[3] [CB] config portal timeout callback
0T00:04:36.220 [W] {wifimanager_wrapper.cpp:101 portalTimeoutCallback()} [WiFiM] Captive portal timeout.
//  ---  here my code detects that the wifi is not connected and starts the configPortal again. ---
0T00:04:36.243 [W] {wifimanager_wrapper.cpp:256 runCaptivePortal()} [WiFiM] Starting config portal...
*wm:[3] Starting Config Portal 
*wm:[3] AccessPoint set password is VALID
*wm:[4] ap pass 12345678
*wm:[4] WiFi station disconnect
*wm:[4] WiFi_enableSTA enable
*wm:[3] Disabling STA
*wm:[3] Enabling AP 
*wm:[2] StartAP with SSID:  App-18FE34D53FAF
*wm:[2] SoftAP Configuration 
*wm:[2] --------------------
// ---  and loops to A ---

my code is this:

void portalTimeoutCallback() {
  app.wifi.captive_portal_started = false;
  app.wifi.run_captive_portal = false;
  olog_w(TAG, "Captive portal timeout.");
}

void setup() {
....
  if (wm.getWiFiIsSaved()) {
    wm.setConfigPortalTimeout(app.wifi.captive_portal_timeout);
    olog_w(TAG, "Portal timeout: %d secs", app.wifi.captive_portal_timeout);
  } else {
    olog_w(TAG, "No WiFi is saved. Portal timeout: infinity.");
  }
  wm.setWiFiAutoReconnect(true);
  wm.setRemoveDuplicateAPs(false);
  wm.setScanDispPerc(true);
  wm.setDarkMode(true);
  wm.setConfigPortalTimeoutCallback(portalTimeoutCallback);
  bool result;
  result = wm.autoConnect(oHelper::resolveTokens(config.Settings.application_name).c_str(), config.Settings.wifi.ap_password);
  if (!result) {
    olog_w(TAG,"Failed to connect.");
    app.wifi.run_captive_portal = true;
    app.wifi.is_connected = false;
  } else {
    olog_i(TAG,"Connected to wifi.");
    app.wifi.run_captive_portal = false;
    app.wifi.is_connected = true;
    app.wifi.last_time_connected = millis();
  }
}

void loopWiFiManager() {

  static bool wait_auto_reconnection = false;

  if (WiFi.status() != WL_CONNECTED) {
    if (app.wifi.is_connected) {              // was connected but now disconnected.
      app.wifi.is_connected = false;
      app.wifi.last_time_disconnected = millis();
      olog_w(TAG, "%s", "WiFi Disconnected. Hardware auto reconnect is being tried...");
      wait_auto_reconnection = true;
    } else {                                  // wifi was never connected
      if (!wait_auto_reconnection) {
        app.wifi.run_captive_portal = true;
      }
    }

    if (wait_auto_reconnection && oHelper::timePassedSince(app.wifi.last_time_disconnected) > 30000) {  // if can not automatically connect within this msecs
      olog_e(TAG, "%s", "Can not auto reconnect to WiFi within 30secs.");
      wait_auto_reconnection = false;
    }

  } else { // wifi is connected
    if (!app.wifi.is_connected) { // it wasn't connected, but now it is
      app.wifi.is_connected = true;
      app.wifi.last_time_connected = millis();
      app.wifi.reconnections++;
      wait_auto_reconnection = false; // reset state
      olog_i(TAG, "WiFi reconnected.");
    }
  }

  wm.process();
}

void runCaptivePortal() {
  if (!app.wifi.captive_portal_started) {
    app.wifi.captive_portal_started = true;
    olog_w(TAG, "Starting config portal...");
    wm.startConfigPortal(oHelper::resolveTokens(config.Settings.application_name).c_str(), config.Settings.wifi.ap_password);
  }
}

void loop() {
  loopWiFiManager();
  if (app.wifi.run_captive_portal) {
    runCaptivePortal();
  }
  delay(1);
}
Originally created by @olonsoft on GitHub (Apr 12, 2023). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/1585 ### Basic Infos #### Hardware WiFimanager Branch/Release: Master latest git of 2023-04-12 Esp8266 Hardware: ESP-12e Espressif 8266 (4.2.0) > NodeMCU 1.0 (ESP-12E Module) ### Description The case is this: My program connects to WiFi in setup by calling wm.autoConnect(...); In loop() I check if the WiFi is connected and if not I start the configPortal(...) While connected, I turn off my AP so the ESP disconnects and my code starts the configPortal. A few seconds later, I turn on my AP and wait for the captive portal to timeout (I have set it to 180 secs). According to the WiFiManager code, when the configPortal ends, it should reconnect to the previous wifi. But instead, I see in the log "WL_STATION_WRONG_PASSWORD" and don't know where it comes from. So my code detects that the wifi is not connected and starts the configPortal again. And this loop continues forever. ```kotlin *wm:[3] Connection result: WL_CONNECTED *wm:[2] AutoConnect: SUCCESS *wm:[3] Connected in 5278 ms *wm:[2] STA IP Address: 192.168.1.241 *wm:[4] hostname: STA: demo-app-D53FAF 0T00:00:05.578 [I] [WiFiM] Connected to wifi. // I turn off my WiFi AP 0T00:00:40.638 [W] {wifimanager_wrapper.cpp:227 loopWiFiManager()} [WiFiM] WiFi Disconnected. Hardware auto reconnect is being tried... // Here I turn on my wifi AP in time to reconnect before the captive portal starts. 0T00:00:51.070 [I] [WiFiM] WiFi reconnected. // Here I turn off my WiFi AP again. 0T00:01:05.169 [W] {wifimanager_wrapper.cpp:227 loopWiFiManager()} [WiFiM] WiFi Disconnected. Hardware auto reconnect is being tried... 0T00:01:35.170 [E] {wifimanager_wrapper.cpp:236 loopWiFiManager()} [WiFiM] Can not auto reconnect to WiFi within 30secs. 0T00:01:35.183 [W] {wifimanager_wrapper.cpp:256 runCaptivePortal()} [WiFiM] Starting config portal... *wm:[3] Starting Config Portal *wm:[3] AccessPoint set password is VALID *wm:[4] ap pass 12345678 *wm:[4] WiFi station disconnect *wm:[4] WiFi_enableSTA enable *wm:[3] Disabling STA *wm:[3] Enabling AP *wm:[2] StartAP with SSID: App-18FE34D53FAF *wm:[2] SoftAP Configuration *wm:[2] -------------------- *wm:[2] ssid: App-18FE34D53FAF // <-- A *wm:[2] password: 12345678 *wm:[2] ssid_len: 16 *wm:[2] channel: 1 *wm:[2] authmode: 3 *wm:[2] ssid_hidden: *wm:[2] max_connection: 4 *wm:[2] country: CN *wm:[2] beacon_interval: 100(ms) *wm:[2] -------------------- *wm:[2] AP IP address: 192.168.4.1 *wm:[3] [CB] _apcallback calling 0T00:01:37.115 [W] {wifimanager_wrapper.cpp:091 captivePortalStartedCallback()} [WiFiM] Captive portal started. IP (IP unset) *wm:[4] setupConfigPortal *wm:[2] Starting Web Portal *wm:[3] [CB] _webservercallback calling 0T00:01:37.133 [W] {wifimanager_wrapper.cpp:096 webPortalStartedCallback()} [WiFiM] Web portal started. IP (IP unset) *wm:[3] HTTP server started *wm:[3] WiFi Scan ASYNC started *wm:[4] setupDNSD *wm:[4] dns server started with ip: 192.168.4.1 *wm:[3] Config Portal Running, non blocking (processing) *wm:[3] Portal Timeout In 180 seconds *wm:[3] Portal Timeout In 177 seconds // -------- While I am here I turn on my WiFi AP -------- *wm:[3] WiFi Scan ASYNC completed in 2289 ms *wm:[3] WiFi Scan ASYNC found: 6 *wm:[3] Portal Timeout In 147 seconds *wm:[3] Portal Timeout In 117 seconds *wm:[3] Portal Timeout In 87 seconds *wm:[3] Portal Timeout In 57 seconds *wm:[3] Portal Timeout In 27 seconds *wm:[2] config portal has timed out *wm:[4] process loop abort *wm:[3] shutdownConfigPortal :ur 1 *wm:[3] restoring usermode STA *wm:[3] WiFi Reconnect, was idle *wm:[3] wifi status: WL_STATION_WRONG_PASSWORD ////// <---- What password is wrong ? *wm:[3] wifi mode: STA *wm:[3] configportal closed *wm:[3] [CB] config portal timeout callback 0T00:04:36.220 [W] {wifimanager_wrapper.cpp:101 portalTimeoutCallback()} [WiFiM] Captive portal timeout. // --- here my code detects that the wifi is not connected and starts the configPortal again. --- 0T00:04:36.243 [W] {wifimanager_wrapper.cpp:256 runCaptivePortal()} [WiFiM] Starting config portal... *wm:[3] Starting Config Portal *wm:[3] AccessPoint set password is VALID *wm:[4] ap pass 12345678 *wm:[4] WiFi station disconnect *wm:[4] WiFi_enableSTA enable *wm:[3] Disabling STA *wm:[3] Enabling AP *wm:[2] StartAP with SSID: App-18FE34D53FAF *wm:[2] SoftAP Configuration *wm:[2] -------------------- // --- and loops to A --- ``` my code is this: ```c++ void portalTimeoutCallback() { app.wifi.captive_portal_started = false; app.wifi.run_captive_portal = false; olog_w(TAG, "Captive portal timeout."); } void setup() { .... if (wm.getWiFiIsSaved()) { wm.setConfigPortalTimeout(app.wifi.captive_portal_timeout); olog_w(TAG, "Portal timeout: %d secs", app.wifi.captive_portal_timeout); } else { olog_w(TAG, "No WiFi is saved. Portal timeout: infinity."); } wm.setWiFiAutoReconnect(true); wm.setRemoveDuplicateAPs(false); wm.setScanDispPerc(true); wm.setDarkMode(true); wm.setConfigPortalTimeoutCallback(portalTimeoutCallback); bool result; result = wm.autoConnect(oHelper::resolveTokens(config.Settings.application_name).c_str(), config.Settings.wifi.ap_password); if (!result) { olog_w(TAG,"Failed to connect."); app.wifi.run_captive_portal = true; app.wifi.is_connected = false; } else { olog_i(TAG,"Connected to wifi."); app.wifi.run_captive_portal = false; app.wifi.is_connected = true; app.wifi.last_time_connected = millis(); } } void loopWiFiManager() { static bool wait_auto_reconnection = false; if (WiFi.status() != WL_CONNECTED) { if (app.wifi.is_connected) { // was connected but now disconnected. app.wifi.is_connected = false; app.wifi.last_time_disconnected = millis(); olog_w(TAG, "%s", "WiFi Disconnected. Hardware auto reconnect is being tried..."); wait_auto_reconnection = true; } else { // wifi was never connected if (!wait_auto_reconnection) { app.wifi.run_captive_portal = true; } } if (wait_auto_reconnection && oHelper::timePassedSince(app.wifi.last_time_disconnected) > 30000) { // if can not automatically connect within this msecs olog_e(TAG, "%s", "Can not auto reconnect to WiFi within 30secs."); wait_auto_reconnection = false; } } else { // wifi is connected if (!app.wifi.is_connected) { // it wasn't connected, but now it is app.wifi.is_connected = true; app.wifi.last_time_connected = millis(); app.wifi.reconnections++; wait_auto_reconnection = false; // reset state olog_i(TAG, "WiFi reconnected."); } } wm.process(); } void runCaptivePortal() { if (!app.wifi.captive_portal_started) { app.wifi.captive_portal_started = true; olog_w(TAG, "Starting config portal..."); wm.startConfigPortal(oHelper::resolveTokens(config.Settings.application_name).c_str(), config.Settings.wifi.ap_password); } } void loop() { loopWiFiManager(); if (app.wifi.run_captive_portal) { runCaptivePortal(); } delay(1); } ```
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#1351
No description provided.