From c6e2b1b349d8532838443c6b1c18400c7902a9aa Mon Sep 17 00:00:00 2001 From: JoergAJ <84235628+JoergAJ@users.noreply.github.com> Date: Thu, 16 Jun 2022 22:33:51 +0200 Subject: [PATCH 1/9] Updated links in README.md (#1431) * Update README.md Updated links to examples * Update README.md Updated links * Update README.md * Update README.md * Update README.md --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2d6ab65..d5d3068 100644 --- a/README.md +++ b/README.md @@ -171,8 +171,8 @@ Also see [examples](https://github.com/tzapu/WiFiManager/tree/master/examples). [PlatformIO](https://platformio.org/) is an emerging ecosystem for IoT development, and is an alternative to using the Arduino IDE. Install `WiFiManager` -using the platformio [library manager](https://docs.platformio.org/en/latest/librarymanager/index.htm) in your editor, -or using the [PlatformIO Core CLI](https://docs.platformio.org/en/latest/userguide/demo.html#library-manager), +using the platformio [library manager](https://docs.platformio.org/en/latest/librarymanager/index.html#librarymanager) in your editor, +or using the [PlatformIO Core CLI](https://docs.platformio.org/en/latest/core/index.html), or by adding it to your `platformio.ini` as shown below (recommended approach). The simplest way is to open the `platformio.ini` file at the root of your project, and `WifiManager` to the common top-level env @@ -229,7 +229,7 @@ IF YOU NEED TO SAVE PARAMETERS EVEN ON WIFI FAIL OR EMPTY, you must set `setBrea void setBreakAfterConfig(boolean shouldBreak); ``` -See [AutoConnectWithFSParameters Example](https://github.com/tzapu/WiFiManager/tree/master/examples/AutoConnectWithFSParameters). +See [AutoConnectWithFSParameters Example](https://github.com/tzapu/WiFiManager/tree/master/examples/Parameters/SPIFFS/AutoConnectWithFSParameters). ```cpp wifiManager.setSaveConfigCallback(saveConfigCallback); ``` @@ -269,7 +269,7 @@ void loop() { } } ``` -See example for a more complex version. [OnDemandConfigPortal](https://github.com/tzapu/WiFiManager/tree/master/examples/OnDemandConfigPortal) +See example for a more complex version. [OnDemandConfigPortal](https://github.com/tzapu/WiFiManager/tree/master/examples/OnDemand/OnDemandConfigPortal) #### Exiting from the Configuration Portal Normally, once entered, the configuration portal will continue to loop until WiFi credentials have been successfully entered or a timeout is reached. @@ -291,7 +291,7 @@ Usage scenario would be: ``` - if connection to AP fails, configuration portal starts and you can set /change the values (or use on demand configuration portal) -- once configuration is done and connection is established [save config callback]() is called +- once configuration is done and connection is established save config callback() is called - once WiFiManager returns control to your application, read and save the new values using the `WiFiManagerParameter` object. ```cpp mqtt_server = custom_mqtt_server.getValue(); @@ -299,7 +299,7 @@ Usage scenario would be: This feature is a lot more involved than all the others, so here are some examples to fully show how it is done. You should also take a look at adding custom HTML to your form. -- Save and load custom parameters to file system in json form [AutoConnectWithFSParameters](https://github.com/tzapu/WiFiManager/tree/master/examples/AutoConnectWithFSParameters) +- Save and load custom parameters to file system in json form [AutoConnectWithFSParameters](https://github.com/tzapu/WiFiManager/tree/master/examples/Parameters/SPIFFS/AutoConnectWithFSParameters) - *Save and load custom parameters to EEPROM* (not done yet) #### Custom IP Configuration From 0ab747c62a032f7370f5ccd4a92cf30359d6f2e2 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Fri, 17 Jun 2022 11:13:39 -0500 Subject: [PATCH 2/9] going through todos --- WiFiManager.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 7576e4f..cbff2a6 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -226,7 +226,7 @@ WiFiManager::~WiFiManager() { _params = NULL; } - // @todo remove event + // remove event // WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2)); #ifdef ESP32 WiFi.removeEvent(wm_event_id); @@ -312,7 +312,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { DEBUG_WM(F("AutoConnect: ESP Already Connected")); #endif setSTAConfig(); - // @todo not sure if this check makes sense, causes dup setSTAConfig in connectwifi, + // @todo not sure if this is safe, causes dup setSTAConfig in connectwifi, // and we have no idea WHAT we are connected to } @@ -486,7 +486,7 @@ bool WiFiManager::startAP(){ if(_debugLevel >= DEBUG_DEV) debugSoftAPConfig(); - // @todo add softAP retry here + // @todo add softAP retry here to dela with unknown failures delay(500); // slight delay to make sure we get an AP IP #ifdef WM_DEBUG_LEVEL @@ -677,7 +677,6 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo if(!validApPassword()) return false; // HANDLE issues with STA connections, shutdown sta if not connected, or else this will hang channel scanning and softap will not respond - // @todo sometimes still cannot connect to AP for no known reason, no events in log either if(_disableSTA || (!WiFi.isConnected() && _disableSTAConn)){ // this fixes most ap problems, however, simply doing mode(WIFI_AP) does not work if sta connection is hanging, must `wifi_station_disconnect` WiFi_Disconnect(); @@ -687,7 +686,6 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo #endif } else { - // @todo even if sta is connected, it is possible that softap connections will fail, IOS says "invalid password", windows says "cannot connect to this network" researching WiFi_enableSTA(true); } @@ -756,6 +754,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // status change, break // @todo what is this for, should be moved inside the processor + // I think.. this is to detect autoconnect by esp in background, there are also many open issues about autoreconnect not working if(state != WL_IDLE_STATUS){ result = (state == WL_CONNECTED); // true if connected DEBUG_WM(DEBUG_DEV,F("configportal loop break")); @@ -914,6 +913,7 @@ bool WiFiManager::shutdownConfigPortal(){ server->handleClient(); // @todo what is the proper way to shutdown and free the server up + // debug - many open issues aobut port not clearing for use with other servers server->stop(); server.reset(); @@ -971,7 +971,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) { // make sure sta is on before `begin` so it does not call enablesta->mode while persistent is ON ( which would save WM AP state to eeprom !) // WiFi.setAutoReconnect(false); if(_cleanConnect) WiFi_Disconnect(); // disconnect before begin, in case anything is hung, this causes a 2 seconds delay for connect - // @todo find out what status is when this is needed, can we detect it and handle it, say in between states or idle_status + // @todo find out what status is when this is needed, can we detect it and handle it, say in between states or idle_status to avoid these // if retry without delay (via begin()), the IDF is still busy even after returning status // E (5130) wifi:sta is connecting, return error @@ -3343,7 +3343,7 @@ boolean WiFiManager::validApPassword(){ DEBUG_WM(F("AccessPoint set password is INVALID or <8 chars")); #endif _apPassword = ""; - return false; // @todo FATAL or fallback to empty ? + return false; // @todo FATAL or fallback to empty , currently fatal, fail secure. } #ifdef WM_DEBUG_LEVEL DEBUG_WM(DEBUG_VERBOSE,F("AccessPoint set password is VALID")); @@ -3423,7 +3423,7 @@ bool WiFiManager::WiFiSetCountry(){ // ret = esp_wifi_set_bandwidth(WIFI_IF_AP,WIFI_BW_HT20); // WIFI_BW_HT40 #ifdef ESP32 esp_err_t err = ESP_OK; - // @todo check if wifi is init, no idea how, doesnt seem to be exposed atm ( might be now! ) + // @todo check if wifi is init, no idea how, doesnt seem to be exposed atm ( check again it might be now! ) if(WiFi.getMode() == WIFI_MODE_NULL){ DEBUG_WM(DEBUG_ERROR,"[ERROR] cannot set country, wifi not init"); } // exception if wifi not init! @@ -3473,7 +3473,7 @@ bool WiFiManager::WiFi_Mode(WiFiMode_t m,bool persistent) { return ret; #elif defined(ESP32) if(persistent && esp32persistent) WiFi.persistent(true); - ret = WiFi.mode(m); // @todo persistent check persistant mode , NI + ret = WiFi.mode(m); // @todo persistent check persistant mode, was eventually added to esp lib, but have to add version checking probably if(persistent && esp32persistent) WiFi.persistent(false); return ret; #endif @@ -3490,7 +3490,7 @@ bool WiFiManager::WiFi_Disconnect() { #ifdef WM_DEBUG_LEVEL DEBUG_WM(DEBUG_DEV,F("WiFi station disconnect")); #endif - ETS_UART_INTR_DISABLE(); // @todo probably not needed + ETS_UART_INTR_DISABLE(); // @todo possibly not needed ret = wifi_station_disconnect(); ETS_UART_INTR_ENABLE(); return ret; From ca4b63220c1cc60e97f36b05593c7ff0c5834a9d Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Fri, 17 Jun 2022 11:36:21 -0500 Subject: [PATCH 3/9] remove double non blocking timeout handler --- WiFiManager.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index cbff2a6..d66da7c 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -783,12 +783,7 @@ boolean WiFiManager::process(){ MDNS.update(); #endif - if(configPortalActive && !_configPortalIsBlocking){ - if(configPortalHasTimeout()) shutdownConfigPortal(); - } - if(webPortalActive || (configPortalActive && !_configPortalIsBlocking)){ - // if timed out or abort, break if(_allowExit && (configPortalHasTimeout() || abort)){ #ifdef WM_DEBUG_LEVEL From b257590e98508655c1d037e11cfea63d79997f9a Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Fri, 17 Jun 2022 11:46:49 -0500 Subject: [PATCH 4/9] comments --- WiFiManager.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WiFiManager.h b/WiFiManager.h index 9016ace..ad11faf 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -486,7 +486,8 @@ class WiFiManager uint8_t _connectRetries = 1; // number of sta connect retries, force reconnect, wait loop (connectimeout) does not always work and first disconnect bails bool _aggresiveReconn = true; // use an agrressive reconnect strategy, WILL delay conxs // on some conn failure modes will add delays and many retries to work around esp and ap bugs, ie, anti de-auth protections - bool _allowExit = true; // allow exit non blocking + // https://github.com/tzapu/WiFiManager/issues/1067 + bool _allowExit = true; // allow exit in nonblocking, else user exit/abort calls will be ignored including cptimeout #ifdef ESP32 wifi_event_id_t wm_event_id = 0; @@ -527,6 +528,7 @@ class WiFiManager // internal options // wifiscan notes + // currently disabled due to issues with caching, sometimes first scan is empty esp32 wifi not init yet race, or portals hit server nonstop flood // The following are background wifi scanning optimizations // experimental to make scans faster, preload scans after starting cp, and visiting home page, so when you click wifi its already has your list // ideally we would add async and xhr here but I am holding off on js requirements atm From 1af8f4540d29094aaf2e81e90a070d7111dd4e8f Mon Sep 17 00:00:00 2001 From: Martijn Hendriks Date: Fri, 17 Jun 2022 19:35:17 +0200 Subject: [PATCH 5/9] Update strings_en.h (#1430) show/hide wifi password during input --- strings_en.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/strings_en.h b/strings_en.h index a656ef6..bc487f8 100644 --- a/strings_en.h +++ b/strings_en.h @@ -30,7 +30,9 @@ const char HTTP_SCRIPT[] PROGMEM = ""; // @todo add button states, disable on click , show ack , spinner etc +"if(p)document.getElementById('p').focus();};" +"function f() {var x = document.getElementById('p');x.type==='password'?x.type='text':x.type='password';}" +""; // @todo add button states, disable on click , show ack , spinner etc const char HTTP_HEAD_END[] PROGMEM = "
"; // {c} = _bodyclass // example of embedded logo, base64 encoded inline, No styling here @@ -58,7 +60,7 @@ const char HTTP_ITEM[] PROGMEM = "
{v} {R} {r}% {q} {e}
"; // test all tokens const char HTTP_FORM_START[] PROGMEM = "
"; -const char HTTP_FORM_WIFI[] PROGMEM = "
"; +const char HTTP_FORM_WIFI[] PROGMEM = "
Show Password"; const char HTTP_FORM_WIFI_END[] PROGMEM = ""; const char HTTP_FORM_STATIC_HEAD[] PROGMEM = "

"; const char HTTP_FORM_END[] PROGMEM = "

"; From 7078bd1786c02a0d4da33772a534eedf20069288 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Fri, 17 Jun 2022 12:35:53 -0500 Subject: [PATCH 6/9] add template js #1430 --- extras/WiFiManager.template.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extras/WiFiManager.template.html b/extras/WiFiManager.template.html index 8d3589e..d928a8c 100644 --- a/extras/WiFiManager.template.html +++ b/extras/WiFiManager.template.html @@ -203,6 +203,7 @@ button:hover{ p = l.nextElementSibling.classList.contains('l'); document.getElementById('p').disabled = !p; if(p)document.getElementById('p').focus()}; + function f() {var x = document.getElementById('p');x.type==='password'?x.type='text':x.type='password';} @@ -250,7 +251,7 @@ button:hover{
{v}
-



+

Show Password

custom parameter


From b5671834e4934b401a24fd5863661f54ada402e6 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Fri, 17 Jun 2022 13:50:33 -0500 Subject: [PATCH 7/9] Moves presavecallback after static ip copy #1429 --- WiFiManager.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index d66da7c..91b691a 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -594,7 +594,7 @@ void WiFiManager::setupHTTPServer(){ #ifdef WM_DEBUG_LEVEL DEBUG_WM(DEBUG_VERBOSE,F("[CB] _webservercallback calling")); #endif - _webservercallback(); + _webservercallback(); // @CALLBACK } // @todo add a new callback maybe, after webserver started, callback cannot override handlers, but can grab them first @@ -841,7 +841,7 @@ uint8_t WiFiManager::processConfigPortal(){ #ifdef WM_DEBUG_LEVEL DEBUG_WM(DEBUG_VERBOSE,F("[CB] _savewificallback calling")); #endif - _savewificallback(); + _savewificallback(); // @CALLBACK } if(!_connectonsave) return WL_IDLE_STATUS; if(_disableConfigPortal) shutdownConfigPortal(); @@ -861,7 +861,7 @@ uint8_t WiFiManager::processConfigPortal(){ #ifdef WM_DEBUG_LEVEL DEBUG_WM(DEBUG_VERBOSE,F("[CB] WiFi/Param save callback")); #endif - _savewificallback(); + _savewificallback(); // @CALLBACK } if(_disableConfigPortal) shutdownConfigPortal(); return WL_CONNECT_FAILED; // CONNECT FAIL @@ -1738,17 +1738,11 @@ void WiFiManager::handleWifiSave() { #endif handleRequest(); - // @todo use new callback for before paramsaves - if (!_paramsInWifi && _presavecallback != NULL) { - _presavecallback(); - } - //SAVE/connect here _ssid = server->arg(F("s")).c_str(); _pass = server->arg(F("p")).c_str(); - if(_paramsInWifi) doParamSave(); - + // set static ips from server args if (server->arg(FPSTR(S_ip)) != "") { //_sta_static_ip.fromString(server->arg(FPSTR(S_ip)); String ip = server->arg(FPSTR(S_ip)); @@ -1779,6 +1773,13 @@ void WiFiManager::handleWifiSave() { #endif } + // @todo use new callback for before paramsaves + if (!_paramsInWifi && _presavecallback != NULL) { + _presavecallback(); // @CALLBACK + } + + if(_paramsInWifi) doParamSave(); + String page; if(_ssid == ""){ @@ -1827,7 +1828,7 @@ void WiFiManager::handleParamSave() { void WiFiManager::doParamSave(){ // @todo use new callback for before paramsaves, is this really needed? if ( _presavecallback != NULL) { - _presavecallback(); + _presavecallback(); // @CALLBACK } //parameters @@ -1865,7 +1866,7 @@ void WiFiManager::doParamSave(){ } if ( _saveparamscallback != NULL) { - _saveparamscallback(); + _saveparamscallback(); // @CALLBACK } } @@ -2511,7 +2512,7 @@ void WiFiManager::resetSettings() { WiFi_enableSTA(true,true); // must be sta to disconnect erase delay(500); // ensure sta is enabled if (_resetcallback != NULL){ - _resetcallback(); + _resetcallback(); // @CALLBACK } #ifdef ESP32 @@ -3747,7 +3748,7 @@ void WiFiManager::handleUpdating(){ // Use new callback for before OTA update if (_preotaupdatecallback != NULL) { - _preotaupdatecallback(); + _preotaupdatecallback(); // @CALLBACK } #ifdef ESP8266 WiFiUDP::stopAll(); From 317c026952173d03fdb6d310a43fc70b3f232e80 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Fri, 17 Jun 2022 14:07:11 -0500 Subject: [PATCH 8/9] adds setPreSaveParamsCallback //called when saving params before anything else happens void setPreSaveParamsCallback( std::function func ); --- WiFiManager.cpp | 18 +++++++++++++----- WiFiManager.h | 10 +++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 91b691a..9e8dcb4 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1773,11 +1773,10 @@ void WiFiManager::handleWifiSave() { #endif } - // @todo use new callback for before paramsaves - if (!_paramsInWifi && _presavecallback != NULL) { + if (_presavecallback != NULL) { _presavecallback(); // @CALLBACK } - + if(_paramsInWifi) doParamSave(); String page; @@ -1827,8 +1826,8 @@ void WiFiManager::handleParamSave() { void WiFiManager::doParamSave(){ // @todo use new callback for before paramsaves, is this really needed? - if ( _presavecallback != NULL) { - _presavecallback(); // @CALLBACK + if ( _presaveparamscallback != NULL) { + _presaveparamscallback(); // @CALLBACK } //parameters @@ -2713,6 +2712,15 @@ void WiFiManager::setSaveParamsCallback( std::function func ) { _saveparamscallback = func; } +/** + * setPreSaveParamsCallback, set a pre save params callback on params save prior to anything else + * @access public + * @param {[type]} void (*func)(void) + */ +void WiFiManager::setPreSaveParamsCallback( std::function func ) { + _presaveparamscallback = func; +} + /** * setPreSaveConfigCallback, set a callback to fire before saving wifi or params * @access public diff --git a/WiFiManager.h b/WiFiManager.h index ad11faf..81c3c4f 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -244,12 +244,15 @@ class WiFiManager //called when wifi settings have been changed and connection was successful ( or setBreakAfterConfig(true) ) void setSaveConfigCallback( std::function func ); - //called when saving either params-in-wifi or params page - void setSaveParamsCallback( std::function func ); - //called when saving params-in-wifi or params before anything else happens (eg wifi) void setPreSaveConfigCallback( std::function func ); + //called when saving params before anything else happens + void setPreSaveParamsCallback( std::function func ); + + //called when saving either params-in-wifi or params page + void setSaveParamsCallback( std::function func ); + //called just before doing OTA update void setPreOtaUpdateCallback( std::function func ); @@ -729,6 +732,7 @@ class WiFiManager std::function _webservercallback; std::function _savewificallback; std::function _presavecallback; + std::function _presaveparamscallback; std::function _saveparamscallback; std::function _resetcallback; std::function _preotaupdatecallback; From a2c33744f65450b1cf1933def268df62988cbad3 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Fri, 17 Jun 2022 14:21:13 -0500 Subject: [PATCH 9/9] rename wifi callbacks --- WiFiManager.cpp | 22 +++++++++++----------- WiFiManager.h | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 9e8dcb4..fbcbbd9 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1773,8 +1773,8 @@ void WiFiManager::handleWifiSave() { #endif } - if (_presavecallback != NULL) { - _presavecallback(); // @CALLBACK + if (_presavewificallback != NULL) { + _presavewificallback(); // @CALLBACK } if(_paramsInWifi) doParamSave(); @@ -2694,6 +2694,15 @@ void WiFiManager::setSaveConfigCallback( std::function func ) { _savewificallback = func; } +/** + * setPreSaveConfigCallback, set a callback to fire before saving wifi or params + * @access public + * @param {[type]} void (*func)(void) + */ +void WiFiManager::setPreSaveConfigCallback( std::function func ) { + _presavewificallback = func; +} + /** * setConfigResetCallback, set a callback to occur when a resetSettings() occurs * @access public @@ -2721,15 +2730,6 @@ void WiFiManager::setPreSaveParamsCallback( std::function func ) { _presaveparamscallback = func; } -/** - * setPreSaveConfigCallback, set a callback to fire before saving wifi or params - * @access public - * @param {[type]} void (*func)(void) - */ -void WiFiManager::setPreSaveConfigCallback( std::function func ) { - _presavecallback = func; -} - /** * setPreOtaUpdateCallback, set a callback to fire before OTA update * @access public diff --git a/WiFiManager.h b/WiFiManager.h index 81c3c4f..5a2c0d6 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -731,7 +731,7 @@ class WiFiManager std::function _apcallback; std::function _webservercallback; std::function _savewificallback; - std::function _presavecallback; + std::function _presavewificallback; std::function _presaveparamscallback; std::function _saveparamscallback; std::function _resetcallback;