[GH-ISSUE #704] Try to reset memory when button is pressed #591

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

Originally created by @tomasbond on GitHub (Aug 21, 2018).
Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/704

Basic Infos

Hardware

WiFimanager Branch/Release: Development

Esp8266: Nodemcu v3

Hardware: ESP-12e

Core Version: 2.4.0, staging

Description

Trying to make the onboard flash run a reset on the wifi memory, running the wifiManager.resetSettings() function.

Settings in IDE

Module: NodeMcu, Wemos D1

Additional libraries:

Sketch


#include <Arduino.h>
#define button 0
void setup() {
pinMode(button, INPUT);
}

void loop() {
if (digitalRead(button) == HIGH) {
Serial.println("Memory reset");
wifiManager.resetSettings();
}

Debug Messages

Where should i put that code so when i press the flash button in the board it runs a memory reset and forget the ssid and password? tryied to put it here and doesnt work. On terminal i can see a New Client but nothing happens when the button is pressed

void loop(){
  WiFiClient client = server.available();   // Listen for incoming clients
  
if (digitalRead(button) == HIGH) {
Serial.println("Memory reset");
wifiManager.resetSettings();
}

  if (client) {                             // If a new client connects,
    Serial.println("New Client.");          // print a message out in the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    
    while (client.connected()) {            // loop while the client's connected
      
      if (client.available()) {             // if there's bytes to read from the client,


Originally created by @tomasbond on GitHub (Aug 21, 2018). Original GitHub issue: https://github.com/tzapu/WiFiManager/issues/704 ### Basic Infos #### Hardware WiFimanager Branch/Release: Development Esp8266: Nodemcu v3 Hardware: ESP-12e Core Version: 2.4.0, staging ### Description Trying to make the onboard flash run a reset on the wifi memory, running the wifiManager.resetSettings() function. ### Settings in IDE Module: NodeMcu, Wemos D1 Additional libraries: ### Sketch ```cpp #include <Arduino.h> #define button 0 void setup() { pinMode(button, INPUT); } void loop() { if (digitalRead(button) == HIGH) { Serial.println("Memory reset"); wifiManager.resetSettings(); } ``` ### Debug Messages Where should i put that code so when i press the flash button in the board it runs a memory reset and forget the ssid and password? tryied to put it here and doesnt work. On terminal i can see a New Client but nothing happens when the button is pressed ``` void loop(){ WiFiClient client = server.available(); // Listen for incoming clients if (digitalRead(button) == HIGH) { Serial.println("Memory reset"); wifiManager.resetSettings(); } if (client) { // If a new client connects, Serial.println("New Client."); // print a message out in the serial port String currentLine = ""; // make a String to hold incoming data from the client while (client.connected()) { // loop while the client's connected if (client.available()) { // if there's bytes to read from the client, ```
Author
Owner

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

I think you have to reboot after erasing settings.
I mean what do you expect to happen?
What do the serial debug say?
Do a printdiag and see that its empty

<!-- gh-comment-id:414523887 --> @tablatronix commented on GitHub (Aug 21, 2018): I think you have to reboot after erasing settings. I mean what do you expect to happen? What do the serial debug say? Do a printdiag and see that its empty
Author
Owner

@tomasbond commented on GitHub (Aug 21, 2018):

Hi! Thanks for your reply! I used a Serial.print("DEBUG"); to see the loop action and the ESP serial stays in, New Client. As there is something avoiding the ESP enter again the loop. Right now im not at home but as soon as i get there ill update on this. My expectation was to add the resetSettings to a button and that should be run if the button is triggered. Of course module should restart to forget actual wifi connections (i think) and give a fresh new start. But the problem is that the code wont read the button and trigger the resetSettings function.

<!-- gh-comment-id:414753795 --> @tomasbond commented on GitHub (Aug 21, 2018): Hi! Thanks for your reply! I used a Serial.print("DEBUG"); to see the loop action and the ESP serial stays in, New Client. As there is something avoiding the ESP enter again the loop. Right now im not at home but as soon as i get there ill update on this. My expectation was to add the resetSettings to a button and that should be run if the button is triggered. Of course module should restart to forget actual wifi connections (i think) and give a fresh new start. But the problem is that the code wont read the button and trigger the resetSettings function.
Author
Owner

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

did you set the pinmode in setup ?

<!-- gh-comment-id:414813876 --> @tablatronix commented on GitHub (Aug 21, 2018): did you set the pinmode in setup ?
Author
Owner

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

you have a while loop
while (client.connected()) {
so yeah its gonna stay in there

<!-- gh-comment-id:414814168 --> @tablatronix commented on GitHub (Aug 21, 2018): you have a while loop while (client.connected()) { so yeah its gonna stay in there
Author
Owner

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

please close if solved

<!-- gh-comment-id:417012219 --> @tablatronix commented on GitHub (Aug 29, 2018): please close if solved
Author
Owner

@emry78 commented on GitHub (Apr 14, 2019):

HI All
I'm emry beginner. i read all the conversation about reset button. But i cannot emigine the reset connect to. i m using huzzah esp8266. i run autoconnect on wifimanager library. Need help to show the connection reset button and code in arduino ide. Thanks.

<!-- gh-comment-id:482908637 --> @emry78 commented on GitHub (Apr 14, 2019): HI All I'm emry beginner. i read all the conversation about reset button. But i cannot emigine the reset connect to. i m using huzzah esp8266. i run autoconnect on wifimanager library. Need help to show the connection reset button and code in arduino ide. Thanks.
Author
Owner

@zshift commented on GitHub (Apr 3, 2020):

I implemented this in conjunction with EasyButton.

// At the global level
#define FLASH_PIN 0
EasyButton resetButton(FLASH_PIN);
#define RESET_DURATION 5000

void setup() {
  resetButton.begin();
  // Allows me to set a custom duration for how long a user holds the reset button for.
  // If you want it to immediately reset, just use `resetButton.onPressed(reset);`
  // Here, `reset` is the `void reset()` function defined below. 
  // We're passing the callback function, which is called when the library detects the button is pressed for DURATION amount of ms. 
  resetButton.onPressedFor(RESET_DURATION, reset);

  // ... rest of your setup, along with WiFi manager
}

void reset() {
  Serial.println("FLASH was held for " + String(RESET_DURATION, DEC) + "ms.");
  Serial.println("Erasing stored WiFi credentials.");
  
  // clear WiFi creds.
  WiFiManager wifiManager;
  wifiManager.resetSettings();
   
  Serial.println("Restarting...");
  ESP.restart(); // builtin, safely restarts the ESP. 
}

void loop() {
  resetButton.read();
  
  // ... rest of your logic, including handling client-connections, etc.
}
<!-- gh-comment-id:608600284 --> @zshift commented on GitHub (Apr 3, 2020): I implemented this in conjunction with [EasyButton](https://github.com/evert-arias/EasyButton). ``` // At the global level #define FLASH_PIN 0 EasyButton resetButton(FLASH_PIN); #define RESET_DURATION 5000 void setup() { resetButton.begin(); // Allows me to set a custom duration for how long a user holds the reset button for. // If you want it to immediately reset, just use `resetButton.onPressed(reset);` // Here, `reset` is the `void reset()` function defined below. // We're passing the callback function, which is called when the library detects the button is pressed for DURATION amount of ms. resetButton.onPressedFor(RESET_DURATION, reset); // ... rest of your setup, along with WiFi manager } void reset() { Serial.println("FLASH was held for " + String(RESET_DURATION, DEC) + "ms."); Serial.println("Erasing stored WiFi credentials."); // clear WiFi creds. WiFiManager wifiManager; wifiManager.resetSettings(); Serial.println("Restarting..."); ESP.restart(); // builtin, safely restarts the ESP. } void loop() { resetButton.read(); // ... rest of your logic, including handling client-connections, etc. } ```
Author
Owner

@zshift commented on GitHub (Apr 3, 2020):

But on that note, this shouldn't be an issue for the WiFiManager. Restarting the ESP is independent of clearing settings. I recommend closing this issue.

<!-- gh-comment-id:608600561 --> @zshift commented on GitHub (Apr 3, 2020): But on that note, this shouldn't be an issue for the WiFiManager. Restarting the ESP is independent of clearing settings. I recommend closing this issue.
Author
Owner

@andysc commented on GitHub (Nov 24, 2021):

I'm trying to make the ESP8266 forget its wifi credentials - I've tried
wifiManager.resetSettings();
and
Wifi.disconnect(true);
with
delay(2000);
ESP.reset();
thrown in for good measure, but every time it comes back with the last successful connection details, saying:
*WM: Using last saved values, should be faster

I've even tried setting them to nonsense values (using Wifi.begin("xxx", "xxx"); but it still goes back to the old ones on next reboot.

Is there a reliable way to nuke the credentials?

<!-- gh-comment-id:978081920 --> @andysc commented on GitHub (Nov 24, 2021): I'm trying to make the ESP8266 forget its wifi credentials - I've tried `wifiManager.resetSettings();` and `Wifi.disconnect(true);` with `delay(2000);` `ESP.reset();` thrown in for good measure, but every time it comes back with the last successful connection details, saying: `*WM: Using last saved values, should be faster` I've even tried setting them to nonsense values (using `Wifi.begin("xxx", "xxx");` but it still goes back to the old ones on next reboot. Is there a reliable way to nuke the credentials?
Author
Owner

@tablatronix commented on GitHub (Nov 24, 2021):

That is supposed to work...

<!-- gh-comment-id:978102262 --> @tablatronix commented on GitHub (Nov 24, 2021): That is supposed to work...
Author
Owner

@andysc commented on GitHub (Nov 25, 2021):

oh, it looks like I'm hideously back-level!
0.15.0-beta !!!
Sorry... I'll upgrade and report back

<!-- gh-comment-id:978986326 --> @andysc commented on GitHub (Nov 25, 2021): oh, it looks like I'm hideously back-level! `0.15.0-beta` !!! Sorry... I'll upgrade and report back
Author
Owner

@andysc commented on GitHub (Nov 25, 2021):

should I be trying 2.00 or 0.16 ?? Are there breaking changes in 2.0 ?

<!-- gh-comment-id:978987545 --> @andysc commented on GitHub (Nov 25, 2021): should I be trying 2.00 or 0.16 ?? Are there breaking changes in 2.0 ?
Author
Owner

@andysc commented on GitHub (Nov 25, 2021):

OK, here's my little test case:

#include <ESP8266WiFi.h>

#include <WiFiManager.h>
WiFiManager wifiManager;

void setup() {

  Serial.begin(9600);
  delay(500);

  Serial.print("Looking for ");
  Serial.print(WiFi.SSID().c_str());
  Serial.print(" / ");
  Serial.println(WiFi.psk().c_str());

  Serial.println("*** Resetting WiFi credentials ***");
  
  wifiManager.resetSettings();
  
  delay(2000);
  ESP.reset();
}

void loop() {

}

When I run that I get...

⸮⸮⸮ԅp⸮@H6⸮0⸮⸮Looking for xxx / xxx
*** Resetting WiFi credentials ***
*WM: settings invalidated
*WM: THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA.
?)⸮)⸮⸮̍!H⸮Looking for xxx / xxx
*** Resetting WiFi credentials ***
*WM: settings invalidated
*WM: THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA.
⸮⸮⸮ԅ⸮⸮@H⸮⸮⸮⸮⸮Looking for xxx / xxx

so it the resetSettings() doesn't seem to have any effect .

This is on v0.16.0

<!-- gh-comment-id:979008854 --> @andysc commented on GitHub (Nov 25, 2021): OK, here's my little test case: ``` #include <ESP8266WiFi.h> #include <WiFiManager.h> WiFiManager wifiManager; void setup() { Serial.begin(9600); delay(500); Serial.print("Looking for "); Serial.print(WiFi.SSID().c_str()); Serial.print(" / "); Serial.println(WiFi.psk().c_str()); Serial.println("*** Resetting WiFi credentials ***"); wifiManager.resetSettings(); delay(2000); ESP.reset(); } void loop() { } ```` When I run that I get... ``` ⸮⸮⸮ԅp⸮@H6⸮0⸮⸮Looking for xxx / xxx *** Resetting WiFi credentials *** *WM: settings invalidated *WM: THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA. ?)⸮)⸮⸮̍! H⸮Looking for xxx / xxx *** Resetting WiFi credentials *** *WM: settings invalidated *WM: THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA. ⸮⸮⸮ԅ⸮⸮@H⸮⸮⸮⸮⸮Looking for xxx / xxx ``` so it the `resetSettings()` doesn't seem to have any effect . This is on `v0.16.0`
Author
Owner

@andysc commented on GitHub (Nov 25, 2021):

On v2.0.5-beta
... it works great!

** Resetting WiFi credentials ***
*wm:[1] resetSettings 
*wm:[1] SETTINGS ERASED 
H!⸮⸮L⸮⸮⸮J(⸮⸮⸮	⸮Looking for  / 
*** Resetting WiFi credentials ***
*wm:[1] resetSettings 
*wm:[1] SETTINGS ERASED 
H⸮⸮ԅ⸮⸮@H⸮⸮⸮⸮⸮Looking for  / 
*** Resetting WiFi credentials ***
*wm:[1] resetSettings 
*wm:[1] SETTINGS ERASED 
⸮⸮⸮⸮U9⸮@H⸮9⸮⸮⸮⸮Looking for  / 

OK - you can close this now :)

<!-- gh-comment-id:979015099 --> @andysc commented on GitHub (Nov 25, 2021): On `v2.0.5-beta` ... it works great! ``` ** Resetting WiFi credentials *** *wm:[1] resetSettings *wm:[1] SETTINGS ERASED H!⸮⸮L⸮⸮⸮J(⸮⸮⸮ ⸮Looking for / *** Resetting WiFi credentials *** *wm:[1] resetSettings *wm:[1] SETTINGS ERASED H⸮⸮ԅ⸮⸮@H⸮⸮⸮⸮⸮Looking for / *** Resetting WiFi credentials *** *wm:[1] resetSettings *wm:[1] SETTINGS ERASED ⸮⸮⸮⸮U9⸮@H⸮9⸮⸮⸮⸮Looking for / ``` OK - you can close this now :)
Author
Owner

@andysc commented on GitHub (Nov 25, 2021):

aha - I see there's some additional magic in this version...

    WiFi.persistent(true);
    WiFi.disconnect(true);
    WiFi.persistent(false);

Thanks :)

<!-- gh-comment-id:979020839 --> @andysc commented on GitHub (Nov 25, 2021): aha - I see there's some additional magic in this version... ``` WiFi.persistent(true); WiFi.disconnect(true); WiFi.persistent(false); ``` Thanks :)
Author
Owner

@andysc commented on GitHub (Nov 25, 2021):

looks like there's more to it than that, as just adding those lines into my sketch doesn't erase the credentials.
Anyway... latest library seems to be the answer :)

<!-- gh-comment-id:979373250 --> @andysc commented on GitHub (Nov 25, 2021): looks like there's more to it than that, as just adding those lines into my sketch doesn't erase the credentials. Anyway... latest library seems to be the answer :)
Author
Owner

@andysc commented on GitHub (Nov 25, 2021):

Cracked it :)

  WiFi.mode(WIFI_STA);
  
  WiFi.persistent(true);
  WiFi.disconnect(true);
  WiFi.persistent(false);

THAT resets the wifi credentials.
(you do not need to restart the ESP afterwards for it to take effect)

<!-- gh-comment-id:979391164 --> @andysc commented on GitHub (Nov 25, 2021): Cracked it :) ``` WiFi.mode(WIFI_STA); WiFi.persistent(true); WiFi.disconnect(true); WiFi.persistent(false); ``` THAT resets the wifi credentials. (you do not need to restart the ESP afterwards for it to take effect)
Author
Owner

@tablatronix commented on GitHub (Nov 25, 2021):

Not sure what you mean , are you trying to fix this in v0?

<!-- gh-comment-id:979425833 --> @tablatronix commented on GitHub (Nov 25, 2021): Not sure what you mean , are you trying to fix this in v0?
Author
Owner

@andysc commented on GitHub (Nov 25, 2021):

yes, I was trying to work out what you did in v2 that makes it work, that didn't work in v0.

<!-- gh-comment-id:979456798 --> @andysc commented on GitHub (Nov 25, 2021): yes, I was trying to work out what you did in v2 that makes it work, that didn't work in v0.
Author
Owner

@tablatronix commented on GitHub (Nov 26, 2021):

The whole thing was reworked, so no idea. Did not know it was not working. Ill look and maybe patch it maybe. But its totally worth switching to v2 at this time if you have the flash

<!-- gh-comment-id:979580441 --> @tablatronix commented on GitHub (Nov 26, 2021): The whole thing was reworked, so no idea. Did not know it was not working. Ill look and maybe patch it maybe. But its totally worth switching to v2 at this time if you have the flash
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#591
No description provided.