tzapu / WiFiManager

ESP8266 WiFi Connection manager with web captive portal
http://tzapu.com/esp8266-wifi-connection-manager-library-arduino-ide/
MIT License
6.58k stars 1.97k forks source link

AP Password gone when using wm.resetSettings #1455

Open 200090 opened 2 years ago

200090 commented 2 years ago

WiFimanager Branch/Release: Master

Esp8266/Esp32:

Hardware: ESP32

Description

I'm trying to reset the WiFi Credentials with the hardware button (BOOT) GPIO0. However, after the wm.resetSettings is executed my AP password is gone when the ESP restarts.

Settings in IDE

Module: ESP32 Dev Module

Additional libraries:

Sketch

#include <WiFiManager.h>
WiFiManager wm;

static const int wifiRstBtn = 0;
int btnStatePrev = HIGH;
unsigned long longPressDuration = 2000;
unsigned long btnPressMillis;
bool longPress = false;
const int intervalButton = 50;
unsigned long btnMillisPrev;
unsigned long btnPressDuration;
unsigned long currentMillis;

void setup() {
  Serial.begin(115200);
  pinMode(wifiRstBtn, INPUT);
  WiFi.mode(WIFI_STA);
  wm.setConfigPortalBlocking(false);
  wm.setConfigPortalTimeout(180);
  if(wm.autoConnect("WiFiConfig","password")){
     Serial.println("Connected");
  }
  else{
     Serial.println("Portal Running");
  }
}

void loop() {
   wm.process();
   wifiRst();
}
void wifiRst() {
    if (currentMillis - btnMillisPrev > intervalButton) {
      int btnState = digitalRead(wifiRstBtn);
    if (btnState == LOW && btnStatePrev == HIGH && !longPress) {
      btnPressMillis = currentMillis;
      btnStatePrev = LOW;
    }
    btnPressDuration = currentMillis - btnPressMillis;

    if (btnState == LOW && !longPress && btnPressDuration >= longPressDuration) {
      longPress = true;
      wm.resetSettings();
      ESP.restart();
    }
    if (btnState == HIGH && btnStatePrev == LOW) {
      btnStatePrev = HIGH;
      longPress = false;
    }

    btnMillisPrev = currentMillis;

    }
}
tablatronix commented 2 years ago

Not understanding what the problem is here.