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 diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 67761ad..1125192 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 @@ -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 @@ -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")); @@ -784,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 @@ -847,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(); @@ -867,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 @@ -914,6 +908,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 +966,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 @@ -1743,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)); @@ -1784,6 +1773,12 @@ void WiFiManager::handleWifiSave() { #endif } + if (_presavewificallback != NULL) { + _presavewificallback(); // @CALLBACK + } + + if(_paramsInWifi) doParamSave(); + String page; if(_ssid == ""){ @@ -1831,8 +1826,8 @@ void WiFiManager::handleParamSave() { void WiFiManager::doParamSave(){ // @todo use new callback for before paramsaves, is this really needed? - if ( _presavecallback != NULL) { - _presavecallback(); + if ( _presaveparamscallback != NULL) { + _presaveparamscallback(); // @CALLBACK } //parameters @@ -1870,7 +1865,7 @@ void WiFiManager::doParamSave(){ } if ( _saveparamscallback != NULL) { - _saveparamscallback(); + _saveparamscallback(); // @CALLBACK } } @@ -2516,7 +2511,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 @@ -2699,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 @@ -2718,12 +2722,12 @@ void WiFiManager::setSaveParamsCallback( std::function func ) { } /** - * setPreSaveConfigCallback, set a callback to fire before saving wifi or params + * setPreSaveParamsCallback, set a pre save params callback on params save prior to anything else * @access public * @param {[type]} void (*func)(void) */ -void WiFiManager::setPreSaveConfigCallback( std::function func ) { - _presavecallback = func; +void WiFiManager::setPreSaveParamsCallback( std::function func ) { + _presaveparamscallback = func; } /** @@ -3343,7 +3347,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 +3427,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 +3477,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 +3494,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; @@ -3752,7 +3756,7 @@ void WiFiManager::handleUpdating(){ // Use new callback for before OTA update if (_preotaupdatecallback != NULL) { - _preotaupdatecallback(); + _preotaupdatecallback(); // @CALLBACK } #ifdef ESP8266 WiFiUDP::stopAll(); diff --git a/WiFiManager.h b/WiFiManager.h index 9016ace..5a2c0d6 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 ); @@ -486,7 +489,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 +531,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 @@ -726,7 +731,8 @@ 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; std::function _preotaupdatecallback; 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{ -



+

Show Password

custom parameter


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 = "

";