[GH-ISSUE #700] stored SSID and PSK are replaced by empty string if timeout occurs after startConfigPortal #585

Closed
opened 2026-02-28 01:25:58 +03:00 by kerem · 1 comment
Owner

Originally created by @thomasfla on GitHub (Aug 15, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/700

Hi,
when a startConfigPortal is called, but no client sends new config before timeout, the default credentials are erased. And WiFi.begin(); can't connect anymore...

We may want to call startConfigPortal before trying to connect for example when a custom parameter needs to be updated but the SSID/PWK are the same..

Development branch, commit 915023ccb9
This wasn't the case with a quite early version of the lib (like a year ago..)

The setup function below shows the problem and allows a fix on the user side by copying the SSID/PWK before calling startConfigPortal..

#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino

//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager
#include <time.h>
char timeZone[6] = "1";
char ssid[80] = {0};
char pwd[80] = {0};

int8_t tz = 1;
WiFiManagerParameter custom_timeZone("timeZone", "UTC+", timeZone, 6);
void setup() {
    Serial.begin(9600);
    WiFiManager wifiManager;
    wifiManager.setDebugOutput(1);
    wifiManager.setSaveConfigCallback(saveConfigCallback);
    wifiManager.addParameter(&custom_timeZone);
    wifiManager.setTimeout(30);
    Serial.println("Going to open an WIFI access point for user configuration, closing in 30s! SSID:NixieClockConfig");
    Serial.printf("stored SSID: %s\r\n", WiFi.SSID().c_str());
    Serial.printf("stored PSK: %s\r\n", WiFi.psk().c_str());
    strncpy(ssid, WiFi.SSID().c_str(), sizeof(ssid)-1); // Bug in WiFiManager? default SSID and PWD are replaced by empty string if timeout occur.
    strncpy(pwd, WiFi.psk().c_str(), sizeof(pwd)-1);   // Bug in WiFiManager? default SSID and PWD are replaced by empty string if timeout occur.
    wifiManager.startConfigPortal("NixieClockConfig");
    Serial.println("End of AP");
    WiFi.disconnect();
    delay(500);
    Serial.printf("stored SSID: %s\r\n", WiFi.SSID().c_str());
    Serial.printf("stored PSK: %s\r\n", WiFi.psk().c_str());
    Serial.printf("backup SSID: %s\r\n", ssid);
    Serial.printf("backup PSK: %s\r\n",pwd);
    if (WiFi.SSID() == '\0')
    {
      Serial.println("No SSID received; Use backup SSID, PWD");
      WiFi.mode(WIFI_STA);
      //WiFi.begin(ssid,pwd);  //DOES WORK
      WiFi.begin();            //DOES NOT WORK
      int i=0;
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
        if (i>100)
        {
          Serial.print("Did not connect; reboot...");
          ESP.reset();
        }
        i++;
      }
    }
}
⸮D⸮*?*WM: [3] allocating params bytes: 20
*WM: [2] Added Parameter: timeZone
Going to open an WIFI access point for user configuration, closing in 30s! SSID:NixieClockConfig
stored SSID: TOMTOMETNANARD
stored PSK: fakefake
*WM: [3] WIFI station disconnect 
*WM: [3] WiFi station enable 
*WM: [2] Disabling STA 
*WM: [2] Enabling AP 
*WM: [1] StartAP with SSID:  NixieClockConfig
*WM: [2] AP has anonymous access! 
*WM: [1] AP IP address: 192.168.4.1
*WM: [3] setupConfigPortal 
*WM: [1] Starting Web Portal 
*WM: [3] dns server started with ip:  192.168.4.1
*WM: [2] HTTP server started 
*WM: [2] WiFi Scan done in 2182ms
*WM: [2] Config Portal Running, blocking, waiting for clients... 
*WM: [2] Portal Timeout In 0 seconds
*WM: [1] config portal has timed out 
*WM: [3] configportal abort 
*WM: [2] disconnect configportal 
*WM: [2] restoring usermode STA
*WM: [2] WiFi Reconnect, was idle 
*WM: [2] wifi status: WL_DISCONNECTED
*WM: [2] wifi mode: STA
*WM: [1] config portal exiting 
End of AP
stored SSID: 
stored PSK: 
backup SSID: TOMTOMETNANARD
backup PSK: fakefake
No SSID received; Use backup SSID, PWD
......................................................................................................Did not connect; reboot..⸮⸮⸮⸮L⸮⸮⸮
Originally created by @thomasfla on GitHub (Aug 15, 2018). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/700 Hi, when a startConfigPortal is called, but no client sends new config before timeout, the default credentials are erased. And WiFi.begin(); can't connect anymore... We may want to call startConfigPortal before trying to connect for example when a custom parameter needs to be updated but the SSID/PWK are the same.. Development branch, commit 915023ccb95054d1f0e126823aff0f9df80b94e7 This wasn't the case with a quite early version of the lib (like a year ago..) The setup function below shows the problem and allows a fix on the user side by copying the SSID/PWK before calling startConfigPortal.. ``` c #include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino //needed for library #include <DNSServer.h> #include <ESP8266WebServer.h> #include <WiFiManager.h> //https://github.com/tzapu/WiFiManager #include <time.h> char timeZone[6] = "1"; char ssid[80] = {0}; char pwd[80] = {0}; int8_t tz = 1; WiFiManagerParameter custom_timeZone("timeZone", "UTC+", timeZone, 6); void setup() { Serial.begin(9600); WiFiManager wifiManager; wifiManager.setDebugOutput(1); wifiManager.setSaveConfigCallback(saveConfigCallback); wifiManager.addParameter(&custom_timeZone); wifiManager.setTimeout(30); Serial.println("Going to open an WIFI access point for user configuration, closing in 30s! SSID:NixieClockConfig"); Serial.printf("stored SSID: %s\r\n", WiFi.SSID().c_str()); Serial.printf("stored PSK: %s\r\n", WiFi.psk().c_str()); strncpy(ssid, WiFi.SSID().c_str(), sizeof(ssid)-1); // Bug in WiFiManager? default SSID and PWD are replaced by empty string if timeout occur. strncpy(pwd, WiFi.psk().c_str(), sizeof(pwd)-1); // Bug in WiFiManager? default SSID and PWD are replaced by empty string if timeout occur. wifiManager.startConfigPortal("NixieClockConfig"); Serial.println("End of AP"); WiFi.disconnect(); delay(500); Serial.printf("stored SSID: %s\r\n", WiFi.SSID().c_str()); Serial.printf("stored PSK: %s\r\n", WiFi.psk().c_str()); Serial.printf("backup SSID: %s\r\n", ssid); Serial.printf("backup PSK: %s\r\n",pwd); if (WiFi.SSID() == '\0') { Serial.println("No SSID received; Use backup SSID, PWD"); WiFi.mode(WIFI_STA); //WiFi.begin(ssid,pwd); //DOES WORK WiFi.begin(); //DOES NOT WORK int i=0; while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); if (i>100) { Serial.print("Did not connect; reboot..."); ESP.reset(); } i++; } } } ``` ``` ⸮D⸮*?*WM: [3] allocating params bytes: 20 *WM: [2] Added Parameter: timeZone Going to open an WIFI access point for user configuration, closing in 30s! SSID:NixieClockConfig stored SSID: TOMTOMETNANARD stored PSK: fakefake *WM: [3] WIFI station disconnect *WM: [3] WiFi station enable *WM: [2] Disabling STA *WM: [2] Enabling AP *WM: [1] StartAP with SSID: NixieClockConfig *WM: [2] AP has anonymous access! *WM: [1] AP IP address: 192.168.4.1 *WM: [3] setupConfigPortal *WM: [1] Starting Web Portal *WM: [3] dns server started with ip: 192.168.4.1 *WM: [2] HTTP server started *WM: [2] WiFi Scan done in 2182ms *WM: [2] Config Portal Running, blocking, waiting for clients... *WM: [2] Portal Timeout In 0 seconds *WM: [1] config portal has timed out *WM: [3] configportal abort *WM: [2] disconnect configportal *WM: [2] restoring usermode STA *WM: [2] WiFi Reconnect, was idle *WM: [2] wifi status: WL_DISCONNECTED *WM: [2] wifi mode: STA *WM: [1] config portal exiting End of AP stored SSID: stored PSK: backup SSID: TOMTOMETNANARD backup PSK: fakefake No SSID received; Use backup SSID, PWD ......................................................................................................Did not connect; reboot..⸮⸮⸮⸮L⸮⸮⸮ ```
kerem 2026-02-28 01:25:58 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@tablatronix commented on GitHub (Aug 15, 2018):

They are not replace, persistent is reenabled in the decontructor, do a WiFi.peristent(true) then begin and it will work. I need to fix this

<!-- gh-comment-id:413376279 --> @tablatronix commented on GitHub (Aug 15, 2018): They are not replace, persistent is reenabled in the decontructor, do a WiFi.peristent(true) then begin and it will work. I need to fix this
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#585
No description provided.