[GH-ISSUE #402] resetsettings unreliable #339

Open
opened 2026-02-28 01:24:50 +03:00 by kerem · 25 comments
Owner

Originally created by @tablatronix on GitHub (Aug 29, 2017).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/402

@tzapu I need to fix resetsettings not compatible with persistent false.
And there is no api to remove wifi credentials.

Do you know if there is a reason to avoid using ESP.erase_config ?

erase config seems to erase a chunk of memory, disconnect seems to erase config only station_config
which is ssid password bssid only

I guess erase will remove static ip, phy mode, etc

Thoughts ? I would rather use a proper SDK function or write one to do as intended of this function.

Originally created by @tablatronix on GitHub (Aug 29, 2017). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/402 @tzapu I need to fix resetsettings not compatible with persistent false. And there is no api to remove wifi credentials. Do you know if there is a reason to avoid using ESP.erase_config ? erase config seems to erase a chunk of memory, disconnect seems to erase config only station_config which is ssid password bssid only I guess erase will remove static ip, phy mode, etc Thoughts ? I would rather use a proper SDK function or write one to do as intended of this function.
Author
Owner

@tzapu commented on GitHub (Aug 29, 2017):

hi,

off the top of my head, erase config should not be all that bad.

the static ip is not saved anyway and calibration params being removed from cache might actually be beneficial.

one thing to not is that erase config as far as i remember needs the esp to reset immediately after, otherwise it doesn't appear to do anything until the next restart, or if there is a begin(ssid, psk) it writes to them => no effect at all from a user's pov

my line of thought, is that the workaround for persistent will end up biting us in the arse a lot worse than forcing credentials, maybe there s a nother way to work with the sdk rather than force bending it to our will

will give it a some thought and get back to you, i hope in a couple of days max

thanks again for everything

<!-- gh-comment-id:325740081 --> @tzapu commented on GitHub (Aug 29, 2017): hi, off the top of my head, erase config should not be all that bad. the static ip is not saved anyway and calibration params being removed from cache might actually be beneficial. one thing to not is that erase config as far as i remember needs the esp to reset immediately after, otherwise it doesn't appear to do anything until the next restart, or if there is a begin(ssid, psk) it writes to them => no effect at all from a user's pov my line of thought, is that the workaround for persistent will end up biting us in the arse a lot worse than forcing credentials, maybe there s a nother way to work with the sdk rather than force bending it to our will will give it a some thought and get back to you, i hope in a couple of days max thanks again for everything
Author
Owner

@tablatronix commented on GitHub (Aug 29, 2017):

I have implemented some workarounds for now.
Although almost every device i have used requires a reboot after saving

<!-- gh-comment-id:325820209 --> @tablatronix commented on GitHub (Aug 29, 2017): I have implemented some workarounds for now. Although almost every device i have used requires a reboot after saving
Author
Owner

@tablatronix commented on GitHub (Aug 29, 2017):

Not that i want to force a restart just leveraging the esp lib if possible

<!-- gh-comment-id:325821069 --> @tablatronix commented on GitHub (Aug 29, 2017): Not that i want to force a restart just leveraging the esp lib if possible
Author
Owner

@tarzan115 commented on GitHub (Aug 30, 2017):

void WiFiManager::resetSettings() {
  DEBUG_WM(F("settings invalidated"));
  DEBUG_WM(F("THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA."));
  WiFi.persistent(true);
  WiFi.disconnect(true);
  WiFi.persistent(false);
}

try this maybe can help.

<!-- gh-comment-id:325937819 --> @tarzan115 commented on GitHub (Aug 30, 2017): ```c void WiFiManager::resetSettings() { DEBUG_WM(F("settings invalidated")); DEBUG_WM(F("THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA.")); WiFi.persistent(true); WiFi.disconnect(true); WiFi.persistent(false); } ``` try this maybe can help.
Author
Owner

@tablatronix commented on GitHub (Aug 30, 2017):

my pr it is already using that

But I added

   //tracker for wfipersistent, set esp wifi persistent state and wifimanager will restore after modifying it.
    void          setRestorePersistent(boolean persistent);

So user can control where we leave persistent , since there is no way to read its state.
User could always explicitly set it after , but this provided a wrapper in wifimanager to handle anytime we modify it or teardown.

<!-- gh-comment-id:325967016 --> @tablatronix commented on GitHub (Aug 30, 2017): my pr it is already using that But I added ``` //tracker for wfipersistent, set esp wifi persistent state and wifimanager will restore after modifying it. void setRestorePersistent(boolean persistent); ``` So user can control where we leave persistent , since there is no way to read its state. User could always explicitly set it after , but this provided a wrapper in wifimanager to handle anytime we modify it or teardown.
Author
Owner

@jwktje commented on GitHub (Jan 28, 2018):

I'm confused about this too! After resetting the settings, it still autoconnects to the last network. Does setRestorePersistent(false) force this to not happen?

<!-- gh-comment-id:361074416 --> @jwktje commented on GitHub (Jan 28, 2018): I'm confused about this too! After resetting the settings, it still autoconnects to the last network. Does setRestorePersistent(false) force this to not happen?
Author
Owner

@tablatronix commented on GitHub (Jan 28, 2018):

I will have to test this, it should work in the development branch, let me know if you find otherwise and post logs

setRestorePersistent(bool) is just what to set it back to when and if wifimanager unloads

<!-- gh-comment-id:361075705 --> @tablatronix commented on GitHub (Jan 28, 2018): I will have to test this, it should work in the development branch, let me know if you find otherwise and post logs setRestorePersistent(bool) is just what to set it back to when and if wifimanager unloads
Author
Owner

@jwktje commented on GitHub (Jan 28, 2018):

Logs show the settings being reset but it still connects. Would you like full logs?

<!-- gh-comment-id:361079641 --> @jwktje commented on GitHub (Jan 28, 2018): Logs show the settings being reset but it still connects. Would you like full logs?
Author
Owner

@tablatronix commented on GitHub (Jan 28, 2018):

yes please

<!-- gh-comment-id:361082503 --> @tablatronix commented on GitHub (Jan 28, 2018): yes please
Author
Owner

@jwktje commented on GitHub (Jan 28, 2018):

*WM: SETTINGS ERASED
*WM: THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA.
*WM: 
*WM: AutoConnect
*WM: Connecting as wifi client...
*WM: wifi station disconnect
*WM: Connecting to saved AP
*WM: connectTimeout not set, ESP waitForConnectResult...
*WM: Connection result: 
*WM: WL_CONNECTED
*WM: IP Address:
*WM: 192.168.2.25
Connected with IP address: 192.168.2.25
0:0
Server Started!
*WM: unloading
<!-- gh-comment-id:361085191 --> @jwktje commented on GitHub (Jan 28, 2018): ``` *WM: SETTINGS ERASED *WM: THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA. *WM: *WM: AutoConnect *WM: Connecting as wifi client... *WM: wifi station disconnect *WM: Connecting to saved AP *WM: connectTimeout not set, ESP waitForConnectResult... *WM: Connection result: *WM: WL_CONNECTED *WM: IP Address: *WM: 192.168.2.25 Connected with IP address: 192.168.2.25 0:0 Server Started! *WM: unloading ```
Author
Owner

@tablatronix commented on GitHub (Jan 28, 2018):

is this an example ?

<!-- gh-comment-id:361085383 --> @tablatronix commented on GitHub (Jan 28, 2018): is this an example ?
Author
Owner

@jwktje commented on GitHub (Jan 28, 2018):

This is what the Logs show me after calling the WifiManager with this in setup:

  //Manager setup
  WiFiManager wifiManager;
  wifiManager.resetSettings();
  wifiManager.setBreakAfterConfig(true);
 
  if (!wifiManager.autoConnect("WifiSetup")) {
    Serial.println("failed to connect, we should reset as see if it connects");
    delay(3000);
    ESP.restart();
    delay(5000);
  }
  
  Serial.print ( "Connected with IP address: " );
  Serial.println ( WiFi.localIP() );
<!-- gh-comment-id:361085506 --> @jwktje commented on GitHub (Jan 28, 2018): This is what the Logs show me after calling the WifiManager with this in setup: ``` //Manager setup WiFiManager wifiManager; wifiManager.resetSettings(); wifiManager.setBreakAfterConfig(true); if (!wifiManager.autoConnect("WifiSetup")) { Serial.println("failed to connect, we should reset as see if it connects"); delay(3000); ESP.restart(); delay(5000); } Serial.print ( "Connected with IP address: " ); Serial.println ( WiFi.localIP() ); ```
Author
Owner

@tablatronix commented on GitHub (Jan 28, 2018):

try reseting after resetsettings please

<!-- gh-comment-id:361086302 --> @tablatronix commented on GitHub (Jan 28, 2018): try reseting after resetsettings please
Author
Owner

@jwktje commented on GitHub (Jan 28, 2018):

But that would cause a loop if I called ESP.restart() in the Setup function. I basically just want a hardware reset to cause it to forget the SSID and password.

<!-- gh-comment-id:361086611 --> @jwktje commented on GitHub (Jan 28, 2018): But that would cause a loop if I called ESP.restart() in the Setup function. I basically just want a hardware reset to cause it to forget the SSID and password.
Author
Owner

@tablatronix commented on GitHub (Jan 28, 2018):

Do it once to see if it fixes it

<!-- gh-comment-id:361086956 --> @tablatronix commented on GitHub (Jan 28, 2018): Do it once to see if it fixes it
Author
Owner

@jwktje commented on GitHub (Jan 28, 2018):

Tried it once by adding ESP.restart(); after the resetSettings();.

As expected it started looping. And didn't fix the problem.

Is there another way to force the ESP to forget it's last credentials in Setup?

<!-- gh-comment-id:361087779 --> @jwktje commented on GitHub (Jan 28, 2018): Tried it once by adding ESP.restart(); after the resetSettings();. As expected it started looping. And didn't fix the problem. Is there another way to force the ESP to forget it's last credentials in Setup?
Author
Owner

@tablatronix commented on GitHub (Jan 28, 2018):

So after removing the reset it still autoconnects? Hmm

<!-- gh-comment-id:361088017 --> @tablatronix commented on GitHub (Jan 28, 2018): So after removing the reset it still autoconnects? Hmm
Author
Owner

@jwktje commented on GitHub (Jan 28, 2018):

Yep exactly. Weird. Because I remember the resetSettings() working fine before I updated the library to the current ESP32 branch. Everything else is very stable now but this suddenly stopped working as expected. Any idea what could be the problem?

<!-- gh-comment-id:361088235 --> @jwktje commented on GitHub (Jan 28, 2018): Yep exactly. Weird. Because I remember the resetSettings() working fine before I updated the library to the current ESP32 branch. Everything else is very stable now but this suddenly stopped working as expected. Any idea what could be the problem?
Author
Owner

@tablatronix commented on GitHub (Jan 28, 2018):

Esp32 branch has not been tested against esp8266 fully either.

<!-- gh-comment-id:361088322 --> @tablatronix commented on GitHub (Jan 28, 2018): Esp32 branch has not been tested against esp8266 fully either.
Author
Owner

@tablatronix commented on GitHub (Jan 28, 2018):

Oh which esp library version?

<!-- gh-comment-id:361091703 --> @tablatronix commented on GitHub (Jan 28, 2018): Oh which esp library version?
Author
Owner

@jwktje commented on GitHub (Jan 28, 2018):

Wemos Lolin32 which has the ESP-WROOM-32.
Running with this Library

{
  "name": "WifiManager",
  "keywords": "wifi, wi-fi",
  "description": "ESP8266 WiFi Connection manager with fallback web configuration portal",
  "repository":
  {
    "type": "git",
    "url": "https://github.com/tzapu/WiFiManager.git"
  },
  "frameworks": "arduino",
  "platforms": "espressif8266",
  "version": "0.12"
}

<!-- gh-comment-id:361092075 --> @jwktje commented on GitHub (Jan 28, 2018): Wemos Lolin32 which has the ESP-WROOM-32. Running with this Library ``` { "name": "WifiManager", "keywords": "wifi, wi-fi", "description": "ESP8266 WiFi Connection manager with fallback web configuration portal", "repository": { "type": "git", "url": "https://github.com/tzapu/WiFiManager.git" }, "frameworks": "arduino", "platforms": "espressif8266", "version": "0.12" } ```
Author
Owner

@tablatronix commented on GitHub (Jan 28, 2018):

Esp 2.4.0? Or staging?

<!-- gh-comment-id:361092461 --> @tablatronix commented on GitHub (Jan 28, 2018): Esp 2.4.0? Or staging?
Author
Owner

@tablatronix commented on GitHub (Jan 28, 2018):

Oh and keep esp32 issues in the esp32 issue for now, this is specific to esp8266

<!-- gh-comment-id:361092566 --> @tablatronix commented on GitHub (Jan 28, 2018): Oh and keep esp32 issues in the esp32 issue for now, this is specific to esp8266
Author
Owner

@tablatronix commented on GitHub (Jan 29, 2018):

@jwktje try now

<!-- gh-comment-id:361324007 --> @tablatronix commented on GitHub (Jan 29, 2018): @jwktje try now
Author
Owner

@jwktje commented on GitHub (Jan 29, 2018):

Works perfectly now! Great job, thanks! :D

<!-- gh-comment-id:361364972 --> @jwktje commented on GitHub (Jan 29, 2018): Works perfectly now! Great job, thanks! :D
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#339
No description provided.