diff --git a/README.md b/README.md index 52cd77d..edd8f0d 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,6 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are ### Known Issues * :exclamation: ESP32 must be patched with webserver library, see [https://github.com/tzapu/WiFiManager/issues/513](https://github.com/tzapu/WiFiManager/issues/513) -* :exclamation: ESP32 espressif/dnsserver contains bugs that prevent captive portal from working, see [https://github.com/tzapu/WiFiManager/issues/513](https://github.com/tzapu/WiFiManager/issues/513) * Documentation needs to be updated, see [https://github.com/tzapu/WiFiManager/issues/500](https://github.com/tzapu/WiFiManager/issues/500) ## Contents diff --git a/WiFiManager.cpp b/WiFiManager.cpp index acc0ca7..2a9d5bc 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -591,7 +591,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) { } else { // connect using saved ssid if there is one if (WiFi_hasAutoConnect()) { - DEBUG_WM(F("Connecting to saved AP")); + DEBUG_WM(F("Connecting to saved AP:"),WiFi_SSID()); WiFi_enableSTA(true,storeSTAmode); WiFi.begin(); } else { @@ -1526,9 +1526,10 @@ void WiFiManager::reportStatus(String &page){ */ bool WiFiManager::disconnect(){ if(WiFi.status() != WL_CONNECTED){ - DEBUG_WM("Disconnect: Not connected"); + DEBUG_WM("Disconnecting: Not connected"); return false; } + DEBUG_WM("Disconnecting"); return WiFi_Disconnect(); } @@ -1537,9 +1538,36 @@ bool WiFiManager::disconnect(){ * @access public */ void WiFiManager::reboot(){ + DEBUG_WM("Restarting"); ESP.restart(); } +/** + * reboot the device + * @access public + */ +bool WiFiManager::erase(){ + return erase(false); +} + +bool WiFiManager::erase(bool opt){ + DEBUG_WM("Erasing"); + + #if defined(ESP32) && defined(WM_ERASE_NVS) + // if opt true, do nvs erase + if(opt){ + DEBUG_WM("Erasing NVS"); + int err; + err=nvs_flash_init(); + DEBUG_WM("nvs_flash_init: ",err ? err : "Success"); + err=nvs_flash_erase(); + DEBUG_WM("nvs_flash_erase: ", err ? err : "Success"); + return err; + } + #endif + + return WiFi_eraseConfig(); +} /** * [resetSettings description] @@ -2111,4 +2139,4 @@ void WiFiManager::WiFi_autoReconnect(){ WiFi.onEvent(WiFiEvent); } #endif -} \ No newline at end of file +} diff --git a/WiFiManager.h b/WiFiManager.h index a2645b4..9814645 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -16,6 +16,7 @@ #define WM_WEBSERVERSHIM // use webserver shim lib // #define WM_MDNS // use MDNS // #define WM_FIXERASECONFIG // use erase flash fix +// #define WM_ERASE_NVS // esp32 erase() will erase #ifdef ESP8266 @@ -51,6 +52,11 @@ #endif #endif + #ifdef WM_ERASE_NVS + #include + #include + #endif + #ifdef WM_MDNS #include #endif @@ -148,6 +154,9 @@ class WiFiManager void reboot(); // disconnect wifi, without persistent saving or erasing bool disconnect(); + // erase esp + bool erase(); + bool erase(bool opt); //sets timeout before AP,webserver loop ends and exits even if there has been no setup. //useful for devices that failed to connect at some point and got stuck in a webserver loop