From 4db3eca51e7a89b0ac9ee7255449e7165a5f7f01 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 5 Mar 2018 12:58:30 -0600 Subject: [PATCH 1/6] adds erase --- WiFiManager.cpp | 13 ++++++++++++- WiFiManager.h | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 933f6dc..becb81b 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1518,9 +1518,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(); } @@ -1529,9 +1530,19 @@ bool WiFiManager::disconnect(){ * @access public */ void WiFiManager::reboot(){ + DEBUG_WM("Restarting"); ESP.restart(); } +/** + * reboot the device + * @access public + */ +bool WiFiManager::erase(){ + DEBUG_WM("Erasing"); + return WiFi_eraseConfig(); +} + /** * [resetSettings description] diff --git a/WiFiManager.h b/WiFiManager.h index bea2de9..ef668eb 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -147,6 +147,8 @@ class WiFiManager void reboot(); // disconnect wifi, without persistent saving or erasing bool disconnect(); + // erase esp + bool erase(); //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 From 8a17ef9c03d548cf9e73f65c4a16b29f3b13533a Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 5 Mar 2018 14:03:33 -0600 Subject: [PATCH 2/6] add debugging --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 184b950..1c9d0d4 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -588,7 +588,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 { From 6e1b2ed32c9e238a1231839592cdf705b146e471 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 5 Mar 2018 14:04:41 -0600 Subject: [PATCH 3/6] remove dnsserver from readme --- README.md | 1 - 1 file changed, 1 deletion(-) 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 From 9f6cc23beb4c739f8770900a63120dfc98aed8ec Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 5 Mar 2018 16:17:49 -0600 Subject: [PATCH 4/6] adds nvs erase // #define WM_ERASE_NVS // esp32 erase() will erase NVS --- WiFiManager.cpp | 13 ++++++++++++- WiFiManager.h | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 1c9d0d4..46fa7d7 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1545,6 +1545,17 @@ void WiFiManager::reboot(){ */ bool WiFiManager::erase(){ DEBUG_WM("Erasing"); + + #if defined(WM_ERASE_NVS) + 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 : "Success"); + return; + #endif + return WiFi_eraseConfig(); } @@ -2119,4 +2130,4 @@ void WiFiManager::WiFi_autoReconnect(){ WiFi.onEvent(WiFiEvent); } #endif -} \ No newline at end of file +} diff --git a/WiFiManager.h b/WiFiManager.h index c723e5e..e40d6c7 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 NVS #ifdef ESP8266 @@ -51,6 +52,11 @@ #endif #endif + #ifdef WM_ERASE_NVS + #include + #include + #endif + #ifdef WM_MDNS #include #endif From 724447a6548306ffe4dc5a62b29e28780be909cb Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 5 Mar 2018 16:26:59 -0600 Subject: [PATCH 5/6] oops --- WiFiManager.cpp | 4 +- .../OnDemandConfigPortal.ino.cpp | 84 +++++++++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 examples/OnDemandConfigPortal/OnDemandConfigPortal.ino.cpp diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 46fa7d7..fd05d87 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1552,10 +1552,10 @@ bool WiFiManager::erase(){ err=nvs_flash_init(); DEBUG_WM("nvs_flash_init: ",err ? err : "Success"); err=nvs_flash_erase(); - DEBUG_WM("nvs_flash_erase: ", ? err : "Success"); + DEBUG_WM("nvs_flash_erase: ", err ? err : "Success"); return; #endif - + return WiFi_eraseConfig(); } diff --git a/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino.cpp b/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino.cpp new file mode 100644 index 0000000..85425f4 --- /dev/null +++ b/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino.cpp @@ -0,0 +1,84 @@ +# 1 "c:\\users\\alverson\\appdata\\local\\temp\\tmpqedruz" +#include +# 1 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" +#include +# 11 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" +#define TRIGGER_PIN 0 + +const char* modes[] = { "NULL", "STA", "AP", "STA+AP" }; +void setup(); +void loop(); +#line 21 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" +void setup() { + + + + Serial.begin(115200); + + WiFi.printDiag(Serial); + + delay(3000); + + Serial.println("\n Starting"); + + + + Serial.setDebugOutput(true); + + Serial.println(modes[WiFi.getMode()]); +# 49 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" + WiFiManager wifiManager(Serial); +# 63 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" + wifiManager.setConfigPortalTimeout(180); +# 79 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" + if(!wifiManager.autoConnect("AutoConnectAP")) { + + Serial.println("failed to connect and hit timeout"); + + } + + + + pinMode(TRIGGER_PIN, INPUT); + +} + + + + + +void loop() { + + + + if ( digitalRead(TRIGGER_PIN) == LOW ) { + + + + + + WiFiManager wifiManager(Serial); +# 121 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" + wifiManager.setConfigPortalTimeout(120); +# 145 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" + if (!wifiManager.startConfigPortal("OnDemandAP")) { + + Serial.println("failed to connect and hit timeout"); + + delay(3000); + + } else { + + + + Serial.println("connected...yeey :)"); + + } + + } + + + + + +} \ No newline at end of file From 6295d128aa676d8ec4cf0073c414b3b0122d80e0 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 5 Mar 2018 16:35:26 -0600 Subject: [PATCH 6/6] adds opt erase flag --- WiFiManager.cpp | 32 ++++--- WiFiManager.h | 3 +- .../OnDemandConfigPortal.ino.cpp | 84 ------------------- 3 files changed, 21 insertions(+), 98 deletions(-) delete mode 100644 examples/OnDemandConfigPortal/OnDemandConfigPortal.ino.cpp diff --git a/WiFiManager.cpp b/WiFiManager.cpp index fd05d87..219b81a 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1544,21 +1544,27 @@ void WiFiManager::reboot(){ * @access public */ bool WiFiManager::erase(){ - DEBUG_WM("Erasing"); - - #if defined(WM_ERASE_NVS) - 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; - #endif - - return WiFi_eraseConfig(); + 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] diff --git a/WiFiManager.h b/WiFiManager.h index e40d6c7..9814645 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -16,7 +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 NVS +// #define WM_ERASE_NVS // esp32 erase() will erase #ifdef ESP8266 @@ -156,6 +156,7 @@ class WiFiManager 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 diff --git a/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino.cpp b/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino.cpp deleted file mode 100644 index 85425f4..0000000 --- a/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino.cpp +++ /dev/null @@ -1,84 +0,0 @@ -# 1 "c:\\users\\alverson\\appdata\\local\\temp\\tmpqedruz" -#include -# 1 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" -#include -# 11 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" -#define TRIGGER_PIN 0 - -const char* modes[] = { "NULL", "STA", "AP", "STA+AP" }; -void setup(); -void loop(); -#line 21 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" -void setup() { - - - - Serial.begin(115200); - - WiFi.printDiag(Serial); - - delay(3000); - - Serial.println("\n Starting"); - - - - Serial.setDebugOutput(true); - - Serial.println(modes[WiFi.getMode()]); -# 49 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" - WiFiManager wifiManager(Serial); -# 63 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" - wifiManager.setConfigPortalTimeout(180); -# 79 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" - if(!wifiManager.autoConnect("AutoConnectAP")) { - - Serial.println("failed to connect and hit timeout"); - - } - - - - pinMode(TRIGGER_PIN, INPUT); - -} - - - - - -void loop() { - - - - if ( digitalRead(TRIGGER_PIN) == LOW ) { - - - - - - WiFiManager wifiManager(Serial); -# 121 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" - wifiManager.setConfigPortalTimeout(120); -# 145 "C:/Users/alverson/documents/projects/arduino/sketches/libraries/WiFiManager/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino" - if (!wifiManager.startConfigPortal("OnDemandAP")) { - - Serial.println("failed to connect and hit timeout"); - - delay(3000); - - } else { - - - - Serial.println("connected...yeey :)"); - - } - - } - - - - - -} \ No newline at end of file