From ccf04aa5b0cffd80c0f7170ab842e7b6034eb1fc Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Wed, 15 Mar 2023 17:54:47 -0500 Subject: [PATCH 01/31] added some http debugging --- WiFiManager.cpp | 20 +++++++++++++++++++- WiFiManager.h | 11 ++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 45698b894..b7ec23983 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1041,6 +1041,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) { #endif } // if ssid argument provided connect to that + // NOTE: this also catches preload() _defaultssid @todo rework if (ssid != "") { wifiConnectNew(ssid,pass,connect); // @todo connect=false seems to disconnect sta in begin() so not sure if _connectonsave is useful at all @@ -1812,6 +1813,22 @@ void WiFiManager::handleWifiSave() { _ssid = server->arg(F("s")).c_str(); _pass = server->arg(F("p")).c_str(); + #ifdef WM_DEBUG_LEVEL + String requestinfo = "SERVER_REQUEST\n----------------\n"; + requestinfo += "URI: "; + requestinfo += server->uri(); + requestinfo += "\nMethod: "; + requestinfo += (server->method() == HTTP_GET) ? "GET" : "POST"; + requestinfo += "\nArguments: "; + requestinfo += server->args(); + requestinfo += "\n"; + for (uint8_t i = 0; i < server->args(); i++) { + requestinfo += " " + server->argName(i) + ": " + server->arg(i) + "\n"; + } + + DEBUG_WM(DEBUG_MAX,requestinfo); + #endif + // set static ips from server args if (server->arg(FPSTR(S_ip)) != "") { //_sta_static_ip.fromString(server->arg(FPSTR(S_ip)); @@ -3289,7 +3306,7 @@ template void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { if(!_debug || _debugLevel < level) return; - if(_debugLevel >= DEBUG_MAX){ + if(_debugLevel > DEBUG_MAX){ #ifdef ESP8266 // uint32_t free; // uint16_t max; @@ -3312,6 +3329,7 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { _debugPort.printf("[MEM] free: %5d | max: %5d | frag: %3d%% \n", free, max, frag); #endif } + _debugPort.print(_debugPrefix); if(_debugLevel >= debugLvlShow) _debugPort.print("["+(String)level+"] "); _debugPort.print(text); diff --git a/WiFiManager.h b/WiFiManager.h index 36fe03989..7b7cc728c 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -760,11 +760,12 @@ class WiFiManager // debugging typedef enum { - DEBUG_ERROR = 0, - DEBUG_NOTIFY = 1, // default stable - DEBUG_VERBOSE = 2, - DEBUG_DEV = 3, // default dev - DEBUG_MAX = 4 + DEBUG_SILENT = 0, // debug OFF but still compiled for runtime + DEBUG_ERROR = 1, // error only + DEBUG_NOTIFY = 2, // default stable,INFO + DEBUG_VERBOSE = 3, // move verbose info + DEBUG_DEV = 4, // development useful debugging info + DEBUG_MAX = 5 // MAX extra dev auditing, var dumps etc (MAX+1 will print timing,mem and frag info) } wm_debuglevel_t; boolean _debug = true; From 4c0d7fa77780558ee058ce5335a6bb585db96fd9 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Wed, 15 Mar 2023 20:58:45 -0500 Subject: [PATCH 02/31] Adds es_ES strings sample for WM_STRINGS_FILE add strings file `build_flags = -DWM_DEBUG_PORT=Serial -DWM_DEBUG_LEVEL=4 -DWM_STRINGS_FILE="\"wm_strings_es.h\""` --- extras/WiFiManager.template.html | 1 + wm_strings_es.h | 282 +++++++++++++++++++++++++++++++ 2 files changed, 283 insertions(+) create mode 100644 wm_strings_es.h diff --git a/extras/WiFiManager.template.html b/extras/WiFiManager.template.html index 20787e139..afe90aaf6 100644 --- a/extras/WiFiManager.template.html +++ b/extras/WiFiManager.template.html @@ -227,6 +227,7 @@

/





+


diff --git a/wm_strings_es.h b/wm_strings_es.h new file mode 100644 index 000000000..781d0553c --- /dev/null +++ b/wm_strings_es.h @@ -0,0 +1,282 @@ +/** + * SAMPLE SAMPLE SAMPLE + * + * wm_strings_es.h + * spanish strings for + * WiFiManager, a library for the ESPX/Arduino platform + * for configuration of WiFi credentials using a Captive Portal + * + * @author Creator tzapu + * @author tablatronix + * @version 0.0.0 + * @license MIT + */ + +#ifndef _WM_STRINGS_EN_H_ +#define _WM_STRINGS_EN_H_ + + +/** + * ADD TO BUILD FLAGS + * -DWM_STRINGS_FILE="\"wm_strings_es.h\"" + */ + +#ifndef WIFI_MANAGER_OVERRIDE_STRINGS +// !!! ABOVE WILL NOT WORK if you define in your sketch, must be build flag, if anyone one knows how to order includes to be able to do this it would be neat.. I have seen it done.. + +// strings files must include a consts file! +// Copy and change to custom locale tokens if necessary, but strings should be good enough +#include "wm_consts_en.h" // include constants, tokens, routes + +const char WM_LANGUAGE[] PROGMEM = "es-ES"; // i18n lang code + +const char HTTP_HEAD_START[] PROGMEM = "" +"" +"" +"" +"" +"{v}"; + +const char HTTP_SCRIPT[] PROGMEM = ""; // @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 +// const char HTTP_ROOT_MAIN[] PROGMEM = "

{v}

WiFiManager

"; +const char HTTP_ROOT_MAIN[] PROGMEM = "

{t}

{v}

"; + +const char * const HTTP_PORTAL_MENU[] PROGMEM = { +"

\n", // MENU_WIFI +"

\n", // MENU_WIFINOSCAN +"

\n", // MENU_INFO +"

\n",//MENU_PARAM +"

\n", // MENU_CLOSE +"

\n",// MENU_RESTART +"

\n", // MENU_EXIT +"

\n", // MENU_ERASE +"

\n",// MENU_UPDATE +"

" // MENU_SEP +}; + +// const char HTTP_PORTAL_OPTIONS[] PROGMEM = strcat(HTTP_PORTAL_MENU[0] , HTTP_PORTAL_MENU[3] , HTTP_PORTAL_MENU[7]); +const char HTTP_PORTAL_OPTIONS[] PROGMEM = ""; +const char HTTP_ITEM_QI[] PROGMEM = ""; // rssi icons +const char HTTP_ITEM_QP[] PROGMEM = "
{r}%
"; // rssi percentage {h} = hidden showperc pref +const char HTTP_ITEM[] PROGMEM = "
{v}{qi}{qp}
"; // {q} = HTTP_ITEM_QI, {r} = HTTP_ITEM_QP +// 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 = "
Mostrar contraseña"; +const char HTTP_FORM_WIFI_END[] PROGMEM = ""; +const char HTTP_FORM_STATIC_HEAD[] PROGMEM = "

"; +const char HTTP_FORM_END[] PROGMEM = "

"; +const char HTTP_FORM_LABEL[] PROGMEM = ""; +const char HTTP_FORM_PARAM_HEAD[] PROGMEM = "

"; +const char HTTP_FORM_PARAM[] PROGMEM = "
\n"; // do not remove newline! + +const char HTTP_SCAN_LINK[] PROGMEM = "
"; +const char HTTP_SAVED[] PROGMEM = "
Saving Credentials
Trying to connect ESP to network.
If it fails reconnect to AP to try again
"; +const char HTTP_PARAMSAVED[] PROGMEM = "
Saved
"; +const char HTTP_END[] PROGMEM = "
"; +const char HTTP_ERASEBTN[] PROGMEM = "
"; +const char HTTP_UPDATEBTN[] PROGMEM = "
"; +const char HTTP_BACKBTN[] PROGMEM = "

"; + +const char HTTP_STATUS_ON[] PROGMEM = "
Conectado a {v}
con IP {i}
"; +const char HTTP_STATUS_OFF[] PROGMEM = "
No conectado a {v}{r}
"; // {c=class} {v=ssid} {r=status_off} +const char HTTP_STATUS_OFFPW[] PROGMEM = "
Authentication Failure"; // STATION_WRONG_PASSWORD, no eps32 +const char HTTP_STATUS_OFFNOAP[] PROGMEM = "
No Encontrado"; // WL_NO_SSID_AVAIL +const char HTTP_STATUS_OFFFAIL[] PROGMEM = "
No se pudo conectar"; // WL_CONNECT_FAILED +const char HTTP_STATUS_NONE[] PROGMEM = "
Sin AP establecido
"; +const char HTTP_BR[] PROGMEM = "
"; + +const char HTTP_STYLE[] PROGMEM = ""; + +#ifndef WM_NOHELP +const char HTTP_HELP[] PROGMEM = + "

Available Pages


" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
PageFunction
/Menu page.
/wifiShow WiFi scan results and enter WiFi configuration.(/0wifi noscan)
/wifisaveSave WiFi configuration information and configure device. Needs variables supplied.
/paramParameter page
/infoInformation page
/uOTA Update
/closeClose the captiveportal popup,configportal will remain active
/exitExit Config Portal, configportal will close
/restartReboot the device
/eraseErase WiFi configuration and reboot Device. Device will not reconnect to a network until new WiFi configuration data is entered.
" + "

Github https://github.com/tzapu/WiFiManager."; +#else +const char HTTP_HELP[] PROGMEM = ""; +#endif + +const char HTTP_UPDATE[] PROGMEM = "Upload New Firmware

* May not function inside captive portal, Open in browser http://192.168.4.1"; +const char HTTP_UPDATE_FAIL[] PROGMEM = "
Update Failed!
Reboot device and try again
"; +const char HTTP_UPDATE_SUCCESS[] PROGMEM = "
Update Successful.
Device Rebooting now...
"; + +#ifdef WM_JSTEST +const char HTTP_JS[] PROGMEM = +""; +#endif + +// Info html +// @todo remove html elements from progmem, repetetive strings +#ifdef ESP32 + const char HTTP_INFO_esphead[] PROGMEM = "

esp32


"; + const char HTTP_INFO_chiprev[] PROGMEM = "
Chip Rev
{1}
"; + const char HTTP_INFO_lastreset[] PROGMEM = "
Last reset reason
CPU0: {1}
CPU1: {2}
"; + const char HTTP_INFO_aphost[] PROGMEM = "
Access Point Hostname
{1}
"; + const char HTTP_INFO_psrsize[] PROGMEM = "
PSRAM Size
{1} bytes
"; + const char HTTP_INFO_temp[] PROGMEM = "
Temperature
{1} C° / {2} F°
Hall
{3}
"; +#else + const char HTTP_INFO_esphead[] PROGMEM = "

esp8266


"; + const char HTTP_INFO_fchipid[] PROGMEM = "
Flash Chip ID
{1}
"; + const char HTTP_INFO_corever[] PROGMEM = "
Core Version
{1}
"; + const char HTTP_INFO_bootver[] PROGMEM = "
Boot Version
{1}
"; + const char HTTP_INFO_lastreset[] PROGMEM = "
Last reset reason
{1}
"; + const char HTTP_INFO_flashsize[] PROGMEM = "
Real Flash Size
{1} bytes
"; +#endif + +const char HTTP_INFO_memsmeter[] PROGMEM = "
"; +const char HTTP_INFO_memsketch[] PROGMEM = "
Memory - Sketch Size
Used / Total bytes
{1} / {2}"; +const char HTTP_INFO_freeheap[] PROGMEM = "
Memory - Free Heap
{1} bytes available
"; +const char HTTP_INFO_wifihead[] PROGMEM = "

WiFi


"; +const char HTTP_INFO_uptime[] PROGMEM = "
Uptime
{1} Mins {2} Secs
"; +const char HTTP_INFO_chipid[] PROGMEM = "
Chip ID
{1}
"; +const char HTTP_INFO_idesize[] PROGMEM = "
Flash Size
{1} bytes
"; +const char HTTP_INFO_sdkver[] PROGMEM = "
SDK Version
{1}
"; +const char HTTP_INFO_cpufreq[] PROGMEM = "
CPU Frequency
{1}MHz
"; +const char HTTP_INFO_apip[] PROGMEM = "
Access Point IP
{1}
"; +const char HTTP_INFO_apmac[] PROGMEM = "
Access Point MAC
{1}
"; +const char HTTP_INFO_apssid[] PROGMEM = "
Access Point SSID
{1}
"; +const char HTTP_INFO_apbssid[] PROGMEM = "
BSSID
{1}
"; +const char HTTP_INFO_stassid[] PROGMEM = "
Station SSID
{1}
"; +const char HTTP_INFO_staip[] PROGMEM = "
Station IP
{1}
"; +const char HTTP_INFO_stagw[] PROGMEM = "
Station Gateway
{1}
"; +const char HTTP_INFO_stasub[] PROGMEM = "
Station Subnet
{1}
"; +const char HTTP_INFO_dnss[] PROGMEM = "
DNS Server
{1}
"; +const char HTTP_INFO_host[] PROGMEM = "
Hostname
{1}
"; +const char HTTP_INFO_stamac[] PROGMEM = "
Station MAC
{1}
"; +const char HTTP_INFO_conx[] PROGMEM = "
Connected
{1}
"; +const char HTTP_INFO_autoconx[] PROGMEM = "
Autoconnect
{1}
"; + +const char HTTP_INFO_aboutver[] PROGMEM = "
WiFiManager
{1}
"; +const char HTTP_INFO_aboutarduino[] PROGMEM = "
Arduino
{1}
"; +const char HTTP_INFO_aboutsdk[] PROGMEM = "
ESP-SDK/IDF
{1}
"; +const char HTTP_INFO_aboutdate[] PROGMEM = "
Build Date
{1}
"; + +const char S_brand[] PROGMEM = "WiFiManager"; +const char S_debugPrefix[] PROGMEM = "*wm:"; +const char S_y[] PROGMEM = "Yes"; +const char S_n[] PROGMEM = "No"; +const char S_enable[] PROGMEM = "Enabled"; +const char S_disable[] PROGMEM = "Disabled"; +const char S_GET[] PROGMEM = "GET"; +const char S_POST[] PROGMEM = "POST"; +const char S_NA[] PROGMEM = "Unknown"; +const char S_passph[] PROGMEM = "********"; +const char S_titlewifisaved[] PROGMEM = "Credentials Saved"; +const char S_titlewifisettings[] PROGMEM = "Settings Saved"; +const char S_titlewifi[] PROGMEM = "Config ESP"; +const char S_titleinfo[] PROGMEM = "Info"; +const char S_titleparam[] PROGMEM = "Setup"; +const char S_titleparamsaved[] PROGMEM = "Setup Saved"; +const char S_titleexit[] PROGMEM = "Exit"; +const char S_titlereset[] PROGMEM = "Reset"; +const char S_titleerase[] PROGMEM = "Erase"; +const char S_titleclose[] PROGMEM = "Close"; +const char S_options[] PROGMEM = "options"; +const char S_nonetworks[] PROGMEM = "No networks found. Refresh to scan again."; +const char S_staticip[] PROGMEM = "Static IP"; +const char S_staticgw[] PROGMEM = "Static Gateway"; +const char S_staticdns[] PROGMEM = "Static DNS"; +const char S_subnet[] PROGMEM = "Subnet"; +const char S_exiting[] PROGMEM = "Exiting"; +const char S_resetting[] PROGMEM = "Module will reset in a few seconds."; +const char S_closing[] PROGMEM = "You can close the page, portal will continue to run"; +const char S_error[] PROGMEM = "An Error Occured"; +const char S_notfound[] PROGMEM = "File Not Found\n\n"; +const char S_uri[] PROGMEM = "URI: "; +const char S_method[] PROGMEM = "\nMethod: "; +const char S_args[] PROGMEM = "\nArguments: "; +const char S_parampre[] PROGMEM = "param_"; + +// debug strings +const char D_HR[] PROGMEM = "--------------------"; + + +// softap ssid default prefix +#ifdef ESP8266 + const char S_ssidpre[] PROGMEM = "ESP"; +#elif defined(ESP32) + const char S_ssidpre[] PROGMEM = "ESP32"; +#else + const char S_ssidpre[] PROGMEM = "WM"; +#endif + +// END WIFI_MANAGER_OVERRIDE_STRINGS +#endif + +#endif From ca5df00d60ab1d295b9ead8a44eb5c1aa7ed9980 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Wed, 15 Mar 2023 21:17:46 -0500 Subject: [PATCH 03/31] fix HTTPSend copy --- WiFiManager.cpp | 2 +- WiFiManager.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index b7ec23983..ea7f09899 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1291,7 +1291,7 @@ String WiFiManager::getHTTPHead(String title){ return page; } -void WiFiManager::HTTPSend(String content){ +void WiFiManager::HTTPSend(const String &content){ server->send(200, FPSTR(HTTP_HEAD_CT), content); } diff --git a/WiFiManager.h b/WiFiManager.h index 7b7cc728c..8c415888b 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -646,7 +646,7 @@ class WiFiManager void updateConxResult(uint8_t status); // webserver handlers - void HTTPSend(String content); + void HTTPSend(const String &content); void handleRoot(); void handleWifi(boolean scan); void handleWifiSave(); From 8cf3b43efb91aa17a50492aa0efe96c416063098 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Wed, 15 Mar 2023 21:24:44 -0500 Subject: [PATCH 04/31] Remove hacky scope check, param length 0 --- WiFiManager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index ea7f09899..d2802856a 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -31,7 +31,7 @@ WiFiManagerParameter::WiFiManagerParameter() { WiFiManagerParameter::WiFiManagerParameter(const char *custom) { _id = NULL; _label = NULL; - _length = 1; + _length = 0; _value = nullptr; _labelPlacement = WFM_LABEL_DEFAULT; _customHTML = custom; @@ -58,7 +58,7 @@ void WiFiManagerParameter::init(const char *id, const char *label, const char *d _label = label; _labelPlacement = labelPlacement; _customHTML = custom; - _length = 1; + _length = 0; _value = nullptr; setValue(defaultValue,length); } @@ -1734,7 +1734,7 @@ String WiFiManager::getParamOut(){ for (int i = 0; i < _paramsCount; i++) { //Serial.println((String)_params[i]->_length); - if (_params[i] == NULL || _params[i]->_length == 0 || _params[i]->_length > 99999) { + if (_params[i] == NULL || _params[i]->_length > 99999) { // try to detect param scope issues, doesnt always catch but works ok #ifdef WM_DEBUG_LEVEL DEBUG_WM(DEBUG_ERROR,F("[ERROR] WiFiManagerParameter is out of scope")); From 4611c75dfbdb8b1efb3b2bcf662d3bfe2596b67a Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Wed, 22 Mar 2023 19:35:57 -0500 Subject: [PATCH 05/31] fix #1540 --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index d2802856a..76d07e22f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -365,7 +365,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { } #ifdef WM_DEBUG_LEVEL - DEBUG_WM(F("AutoConnect: FAILED")); + DEBUG_WM(F("AutoConnect: FAILED for "),(String)((millis()-_startconn)) + " ms"); #endif // } // else { @@ -1051,7 +1051,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) { connRes = waitForConnectResult(_saveTimeout); // use default save timeout for saves to prevent bugs in esp->waitforconnectresult loop } else { - connRes = waitForConnectResult(0); + connRes = waitForConnectResult(); } // } } From aa8856adf30b55d3e26100212d4b42b5f29717f4 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Tue, 2 May 2023 15:03:29 -0500 Subject: [PATCH 06/31] #1583 missed this one --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 76d07e22f..5723305a0 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1928,7 +1928,7 @@ void WiFiManager::doParamSave(){ #endif for (int i = 0; i < _paramsCount; i++) { - if (_params[i] == NULL || _params[i]->_length == 0) { + if (_params[i] == NULL || _params[i]->_length > 99999) { #ifdef WM_DEBUG_LEVEL DEBUG_WM(DEBUG_ERROR,F("[ERROR] WiFiManagerParameter is out of scope")); #endif From 88c378f0a24a99e7b9a007ea31ea43cacce924ac Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Thu, 11 May 2023 13:40:19 -0500 Subject: [PATCH 07/31] v2.0.16-rc.2 --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 6b92d24a6..417cf64c8 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "WiFiManager", - "version": "2.0.15-rc.1", + "version": "2.0.16-rc.2", "keywords": "wifi,wi-fi,esp,esp8266,esp32,espressif8266,espressif32,nodemcu,wemos,arduino", "description": "WiFi Configuration manager with web configuration portal for ESP boards", "authors": diff --git a/library.properties b/library.properties index d35882361..784f07217 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WiFiManager -version=2.0.15-rc.1 +version=2.0.16-rc.2 author=tzapu maintainer=tablatronix sentence=WiFi Configuration manager with web configuration portal for Espressif ESPx boards, by tzapu From e9bbb6c588bab438c7f69841f5cca6286653a84d Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Tue, 16 May 2023 20:14:38 -0500 Subject: [PATCH 08/31] fixes #1608 --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 5723305a0..b264af100 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2266,7 +2266,7 @@ String WiFiManager::getInfoData(String id){ // temperature is not calibrated, varying large offsets are present, use for relative temp changes only p = FPSTR(HTTP_INFO_temp); p.replace(FPSTR(T_1),(String)temperatureRead()); - p.replace(FPSTR(T_2),(String)((temperatureRead()+32)*1.8)); + p.replace(FPSTR(T_2),(String)((temperatureRead()+32)*1.8f)); } // else if(id==F("hall")){ // p = FPSTR(HTTP_INFO_hall); From cad9ffc83fa9f6bdc8ba9b7aa0db2991af5a695b Mon Sep 17 00:00:00 2001 From: Pascal Wagler Date: Wed, 17 May 2023 03:17:39 +0200 Subject: [PATCH 09/31] Make *Show Password* a label so one can click on it (#1595) --- extras/WiFiManager.template.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/WiFiManager.template.html b/extras/WiFiManager.template.html index afe90aaf6..934c03394 100644 --- a/extras/WiFiManager.template.html +++ b/extras/WiFiManager.template.html @@ -252,7 +252,7 @@

/wifi


-


Show Password
+


custom parameter


From b735c61f6ec97c299c457ced4efe1e0c27bdb87e Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Tue, 16 May 2023 20:19:57 -0500 Subject: [PATCH 10/31] #1587 menutokens pointers not actually in progmem --- wm_consts_en.h | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/wm_consts_en.h b/wm_consts_en.h index fc21b42ff..b1c615f46 100644 --- a/wm_consts_en.h +++ b/wm_consts_en.h @@ -19,20 +19,32 @@ const char WM_VERSION_STR[] PROGMEM = "v2.0.15-rc.1"; -const uint8_t _nummenutokens = 11; -const char * const _menutokens[_nummenutokens] PROGMEM = { - "wifi", - "wifinoscan", - "info", - "param", - "close", - "restart", - "exit", - "erase", - "update", - "sep", - "custom" +static const char _wifi_token[] PROGMEM = "wifi"; +static const char _wifinoscan_token[] PROGMEM = "wifinoscan"; +static const char _info_token[] PROGMEM = "info"; +static const char _param_token[] PROGMEM = "param"; +static const char _close_token[] PROGMEM = "close"; +static const char _restart_token[] PROGMEM = "restart"; +static const char _exit_token[] PROGMEM = "exit"; +static const char _erase_token[] PROGMEM = "erase"; +static const char _update_token[] PROGMEM = "update"; +static const char _sep_token[] PROGMEM = "sep"; +static const char _custom_token[] PROGMEM = "custom"; +static PGM_P _menutokens[] PROGMEM = { + _wifi_token, + _wifinoscan_token, + _info_token, + _param_token, + _close_token, + _restart_token, + _exit_token, + _erase_token, + _update_token, + _sep_token, + _custom_token }; +const uint8_t _nummenutokens = (sizeof(_menutokens) / sizeof(PGM_P)); + const char R_root[] PROGMEM = "/"; const char R_wifi[] PROGMEM = "/wifi"; From 9b8de0d77f65928347e49403ee0f38cae7f4487b Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Thu, 18 May 2023 22:51:04 -0500 Subject: [PATCH 11/31] #1610 quick fix dirty fix, will have to add proper flashstring helper casts instead probably --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index b264af100..7ae05b0ac 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -3125,7 +3125,7 @@ void WiFiManager::setMenu(const char * menu[], uint8_t size){ _menuIds.clear(); for(size_t i = 0; i < size; i++){ for(size_t j = 0; j < _nummenutokens; j++){ - if(menu[i] == _menutokens[j]){ + if((String)menu[i] == String(_menutokens[j])){ if((String)menu[i] == "param") _paramsInWifi = false; // param auto flag _menuIds.push_back(j); } @@ -3152,7 +3152,7 @@ void WiFiManager::setMenu(std::vector& menu){ _menuIds.clear(); for(auto menuitem : menu ){ for(size_t j = 0; j < _nummenutokens; j++){ - if(menuitem == _menutokens[j]){ + if((String)menuitem == String(_menutokens[j])){ if((String)menuitem == "param") _paramsInWifi = false; // param auto flag _menuIds.push_back(j); } From 3a303eeb45de78dba9987808bc5bef6440a0f8f8 Mon Sep 17 00:00:00 2001 From: Avi B <474746+abrender@users.noreply.github.com> Date: Sat, 10 Jun 2023 21:53:21 -0400 Subject: [PATCH 12/31] Update CMakeLists.txt (#1624) Change `REQUIRES` to `PRIV_REQUIRES` because the public API of this package does not require users of this package to know about `arduino`. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bd408a5e..c87bb2035 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.5) idf_component_register( SRCS "WiFiManager.cpp" INCLUDE_DIRS "." - REQUIRES arduino + PRIV_REQUIRES arduino ) project(WiFiManager) From eb27c525e33e6ce558bd27496685ec657f2cb23e Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Fri, 8 Sep 2023 13:27:15 -0500 Subject: [PATCH 13/31] move 404 handler public, remove 404 info, add examples for overrides --- WiFiManager.cpp | 24 +++++++++++-------- WiFiManager.h | 5 +++- .../OnDemandConfigPortal.ino | 13 ++++++++-- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 7ae05b0ac..98dfe49c8 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2386,16 +2386,20 @@ void WiFiManager::handleNotFound() { if (captivePortal()) return; // If captive portal redirect instead of displaying the page handleRequest(); String message = FPSTR(S_notfound); // @token notfound - message += FPSTR(S_uri); // @token uri - message += server->uri(); - message += FPSTR(S_method); // @token method - message += ( server->method() == HTTP_GET ) ? FPSTR(S_GET) : FPSTR(S_POST); - message += FPSTR(S_args); // @token args - message += server->args(); - message += F("\n"); - - for ( uint8_t i = 0; i < server->args(); i++ ) { - message += " " + server->argName ( i ) + ": " + server->arg ( i ) + "\n"; + + bool verbose404 = false; // show info in 404 body, uri,method, args + if(verbose404){ + message += FPSTR(S_uri); // @token uri + message += server->uri(); + message += FPSTR(S_method); // @token method + message += ( server->method() == HTTP_GET ) ? FPSTR(S_GET) : FPSTR(S_POST); + message += FPSTR(S_args); // @token args + message += server->args(); + message += F("\n"); + + for ( uint8_t i = 0; i < server->args(); i++ ) { + message += " " + server->argName ( i ) + ": " + server->arg ( i ) + "\n"; + } } server->sendHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate")); // @HTTPHEAD send cache server->sendHeader(F("Pragma"), F("no-cache")); diff --git a/WiFiManager.h b/WiFiManager.h index 8c415888b..66830ae0b 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -646,13 +646,16 @@ class WiFiManager void updateConxResult(uint8_t status); // webserver handlers +public: + void handleNotFound(); +private: void HTTPSend(const String &content); void handleRoot(); void handleWifi(boolean scan); void handleWifiSave(); void handleInfo(); void handleReset(); - void handleNotFound(); + void handleExit(); void handleClose(); // void handleErase(); diff --git a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino index 2546c6afb..fe1820d4a 100644 --- a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -72,8 +72,12 @@ void saveParamCallback(){ } void bindServerCallback(){ - wm.server->on("/custom",handleRoute); // this is now crashing esp32 for some reason - // wm.server->on("/info",handleRoute); // you can override wm! + wm.server->on("/custom",handleRoute); + + // you can override wm route endpoints, I have not found a way to remove handlers, but this would let you disable them or add auth etc. + // wm.server->on("/info",handleNotFound); + // wm.server->on("/update",handleNotFound); + wm.server->on("/erase",handleNotFound); } void handleRoute(){ @@ -81,6 +85,11 @@ void handleRoute(){ wm.server->send(200, "text/plain", "hello from user code"); } +void handleNotFound(){ + Serial.println("[HTTP] handle route"); + wm.handleNotFound(); +} + void handlePreOtaUpdateCallback(){ Update.onProgress([](unsigned int progress, unsigned int total) { Serial.printf("CUSTOM Progress: %u%%\r", (progress / (total / 100))); From 465b44d73405da2624bcb4404b8042b62dcfc255 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Mon, 18 Sep 2023 18:14:18 -0500 Subject: [PATCH 14/31] localize debuglevel enum, add method --- WiFiManager.cpp | 383 ++++++++++++++++++++++++------------------------ WiFiManager.h | 25 ++-- 2 files changed, 208 insertions(+), 200 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 7ae05b0ac..b5da15a41 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -137,7 +137,7 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { for (size_t i = 0; i < strlen(p->getID()); i++){ if(!(isAlphaNumeric(p->getID()[i])) && !(p->getID()[i]=='_')){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] parameter IDs can only contain alpha numeric chars")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] parameter IDs can only contain alpha numeric chars")); #endif return false; } @@ -147,7 +147,7 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { // init params if never malloc if(_params == NULL){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("allocating params bytes:"),_max_params * sizeof(WiFiManagerParameter*)); + DEBUG_WM(WM_DEBUG_DEV,F("allocating params bytes:"),_max_params * sizeof(WiFiManagerParameter*)); #endif _params = (WiFiManagerParameter**)malloc(_max_params * sizeof(WiFiManagerParameter*)); } @@ -156,8 +156,8 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { if(_paramsCount == _max_params){ _max_params += WIFI_MANAGER_MAX_PARAMS; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Updated _max_params:"),_max_params); - DEBUG_WM(DEBUG_DEV,F("re-allocating params bytes:"),_max_params * sizeof(WiFiManagerParameter*)); + DEBUG_WM(WM_DEBUG_DEV,F("Updated _max_params:"),_max_params); + DEBUG_WM(WM_DEBUG_DEV,F("re-allocating params bytes:"),_max_params * sizeof(WiFiManagerParameter*)); #endif WiFiManagerParameter** new_params = (WiFiManagerParameter**)realloc(_params, _max_params * sizeof(WiFiManagerParameter*)); #ifdef WM_DEBUG_LEVEL @@ -169,7 +169,7 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { _params = new_params; } else { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] failed to realloc params, size not increased!")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] failed to realloc params, size not increased!")); #endif return false; } @@ -179,7 +179,7 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { _paramsCount++; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Added Parameter:"),p->getID()); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Added Parameter:"),p->getID()); #endif return true; } @@ -217,7 +217,7 @@ WiFiManager::WiFiManager() { void WiFiManager::WiFiManagerInit(){ setMenu(_menuIdsDefault); - if(_debug && _debugLevel >= DEBUG_DEV) debugPlatformInfo(); + if(_debug && _debugLevel >= WM_DEBUG_DEV) debugPlatformInfo(); _max_params = WIFI_MANAGER_MAX_PARAMS; } @@ -228,7 +228,7 @@ WiFiManager::~WiFiManager() { // @todo below belongs to wifimanagerparameter if (_params != NULL){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("freeing allocated params!")); + DEBUG_WM(WM_DEBUG_DEV,F("freeing allocated params!")); #endif free(_params); _params = NULL; @@ -241,7 +241,7 @@ WiFiManager::~WiFiManager() { #endif #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("unloading")); + DEBUG_WM(WM_DEBUG_DEV,F("unloading")); #endif } @@ -308,7 +308,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { if(!WiFi.enableSTA(true)){ // handle failure mode Brownout detector etc. #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[FATAL] Unable to enable wifi!")); + DEBUG_WM(WM_DEBUG_ERROR,F("[FATAL] Unable to enable wifi!")); #endif return false; } @@ -350,7 +350,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { //connected #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("AutoConnect: SUCCESS")); - DEBUG_WM(DEBUG_VERBOSE,F("Connected in"),(String)((millis()-_startconn)) + " ms"); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Connected in"),(String)((millis()-_startconn)) + " ms"); DEBUG_WM(F("STA IP Address:"),WiFi.localIP()); #endif // Serial.println("Connected in " + (String)((millis()-_startconn)) + " ms"); @@ -358,7 +358,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { if(_hostname != ""){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("hostname: STA: "),getWiFiHostname()); + DEBUG_WM(WM_DEBUG_DEV,F("hostname: STA: "),getWiFiHostname()); #endif } return true; // connected success @@ -377,7 +377,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { // possibly skip the config portal if (!_enableConfigPortal) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("enableConfigPortal: FALSE, skipping ")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("enableConfigPortal: FALSE, skipping ")); #endif return false; // not connected and not cp @@ -391,25 +391,25 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { bool WiFiManager::setupHostname(bool restart){ if(_hostname == "") { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("No Hostname to set")); + DEBUG_WM(WM_DEBUG_DEV,F("No Hostname to set")); #endif return false; } else { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Setting Hostnames: "),_hostname); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Setting Hostnames: "),_hostname); #endif } bool res = true; #ifdef ESP8266 #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Setting WiFi hostname")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Setting WiFi hostname")); #endif res = WiFi.hostname(_hostname.c_str()); // #ifdef ESP8266MDNS_H #ifdef WM_MDNS #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Setting MDNS hostname, tcp 80")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Setting MDNS hostname, tcp 80")); #endif if(MDNS.begin(_hostname.c_str())){ MDNS.addService("http", "tcp", 80); @@ -421,7 +421,7 @@ bool WiFiManager::setupHostname(bool restart){ // same for S2, must set it before mode(STA) now #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Setting WiFi hostname")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Setting WiFi hostname")); #endif res = WiFi.setHostname(_hostname.c_str()); @@ -435,7 +435,7 @@ bool WiFiManager::setupHostname(bool restart){ // #ifdef ESP32MDNS_H #ifdef WM_MDNS #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Setting MDNS hostname, tcp 80")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Setting MDNS hostname, tcp 80")); #endif if(MDNS.begin(_hostname.c_str())){ MDNS.addService("http", "tcp", 80); @@ -444,12 +444,12 @@ bool WiFiManager::setupHostname(bool restart){ #endif #ifdef WM_DEBUG_LEVEL - if(!res)DEBUG_WM(DEBUG_ERROR,F("[ERROR] hostname: set failed!")); + if(!res)DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] hostname: set failed!")); #endif if(restart && (WiFi.status() == WL_CONNECTED)){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("reconnecting to set new hostname")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("reconnecting to set new hostname")); #endif // WiFi.reconnect(); // This does not reset dhcp WiFi_Disconnect(); @@ -470,7 +470,7 @@ bool WiFiManager::startAP(){ // @bug workaround for bug #4372 https://github.com/esp8266/Arduino/issues/4372 if(!WiFi.enableAP(true)) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] enableAP failed!")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] enableAP failed!")); #endif return false; } @@ -484,7 +484,7 @@ bool WiFiManager::startAP(){ #endif if(!WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn)){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] softAPConfig failed!")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] softAPConfig failed!")); #endif } } @@ -498,7 +498,7 @@ bool WiFiManager::startAP(){ if(channel>0){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Starting AP on channel:"),channel); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Starting AP on channel:"),channel); #endif } @@ -513,7 +513,7 @@ bool WiFiManager::startAP(){ } } else { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("AP has anonymous access!")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("AP has anonymous access!")); #endif if(channel>0){ ret = WiFi.softAP(_apName.c_str(),"",channel,_apHidden); @@ -523,13 +523,13 @@ bool WiFiManager::startAP(){ } } - if(_debugLevel >= DEBUG_DEV) debugSoftAPConfig(); + if(_debugLevel >= WM_DEBUG_DEV) debugSoftAPConfig(); // @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 - if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] There was a problem starting the AP")); + if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] There was a problem starting the AP")); DEBUG_WM(F("AP IP address:"),WiFi.softAPIP()); #endif @@ -538,9 +538,9 @@ bool WiFiManager::startAP(){ if(ret && _hostname != ""){ bool res = WiFi.softAPsetHostname(_hostname.c_str()); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("setting softAP Hostname:"),_hostname); - if(!res)DEBUG_WM(DEBUG_ERROR,F("[ERROR] hostname: AP set failed!")); - DEBUG_WM(DEBUG_DEV,F("hostname: AP: "),WiFi.softAPgetHostname()); + DEBUG_WM(WM_DEBUG_VERBOSE,F("setting softAP Hostname:"),_hostname); + if(!res)DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] hostname: AP set failed!")); + DEBUG_WM(WM_DEBUG_DEV,F("hostname: AP: "),WiFi.softAPgetHostname()); #endif } #endif @@ -568,7 +568,7 @@ void WiFiManager::startWebPortal() { void WiFiManager::stopWebPortal() { if(!configPortalActive && !webPortalActive) return; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Stopping Web Portal")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Stopping Web Portal")); #endif webPortalActive = false; shutdownConfigPortal(); @@ -584,7 +584,7 @@ boolean WiFiManager::configPortalHasTimeout(){ if(millis() - timer > logintvl){ timer = millis(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("NUM CLIENTS: "),(String)WiFi_softap_num_stations()); + DEBUG_WM(WM_DEBUG_VERBOSE,F("NUM CLIENTS: "),(String)WiFi_softap_num_stations()); #endif } _configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts @@ -606,7 +606,7 @@ boolean WiFiManager::configPortalHasTimeout(){ if((millis() - timer) > logintvl){ timer = millis(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Portal Timeout In"),(String)((_configPortalStart + _configPortalTimeout-millis())/1000) + (String)F(" seconds")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Portal Timeout In"),(String)((_configPortalStart + _configPortalTimeout-millis())/1000) + (String)F(" seconds")); #endif } } @@ -622,7 +622,7 @@ void WiFiManager::setupHTTPServer(){ if(_httpPort != 80) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("http server started with custom port: "),_httpPort); // @todo not showing ip + DEBUG_WM(WM_DEBUG_VERBOSE,F("http server started with custom port: "),_httpPort); // @todo not showing ip #endif } @@ -631,7 +631,7 @@ void WiFiManager::setupHTTPServer(){ if ( _webservercallback != NULL) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[CB] _webservercallback calling")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] _webservercallback calling")); #endif _webservercallback(); // @CALLBACK } @@ -659,7 +659,7 @@ void WiFiManager::setupHTTPServer(){ server->begin(); // Web server start #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("HTTP server started")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("HTTP server started")); #endif } @@ -670,7 +670,7 @@ void WiFiManager::setupDNSD(){ dnsServer->setErrorReplyCode(DNSReplyCode::NoError); #ifdef WM_DEBUG_LEVEL // DEBUG_WM("dns server started port: ",DNS_PORT); - DEBUG_WM(DEBUG_DEV,F("dns server started with ip: "),WiFi.softAPIP()); // @todo not showing ip + DEBUG_WM(WM_DEBUG_DEV,F("dns server started with ip: "),WiFi.softAPIP()); // @todo not showing ip #endif dnsServer->start(DNS_PORT, F("*"), WiFi.softAPIP()); } @@ -698,7 +698,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo if(configPortalActive){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Starting Config Portal FAILED, is already running")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Starting Config Portal FAILED, is already running")); #endif return false; } @@ -708,7 +708,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo _apPassword = apPassword; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Starting Config Portal")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Starting Config Portal")); #endif if(_apName == "") _apName = getDefaultAPName(); @@ -724,7 +724,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo WiFi_Disconnect(); WiFi_enableSTA(false); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Disabling STA")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Disabling STA")); #endif } else { @@ -740,7 +740,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // start access point #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Enabling AP")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Enabling AP")); #endif startAP(); WiFiSetCountry(); @@ -748,27 +748,27 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // do AP callback if set if ( _apcallback != NULL) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[CB] _apcallback calling")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] _apcallback calling")); #endif _apcallback(this); } // init configportal #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("setupConfigPortal")); + DEBUG_WM(WM_DEBUG_DEV,F("setupConfigPortal")); #endif setupConfigPortal(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("setupDNSD")); + DEBUG_WM(WM_DEBUG_DEV,F("setupDNSD")); #endif setupDNSD(); if(!_configPortalIsBlocking){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Config Portal Running, non blocking (processing)")); - if(_configPortalTimeout > 0) DEBUG_WM(DEBUG_VERBOSE,F("Portal Timeout In"),(String)(_configPortalTimeout/1000) + (String)F(" seconds")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Config Portal Running, non blocking (processing)")); + if(_configPortalTimeout > 0) DEBUG_WM(WM_DEBUG_VERBOSE,F("Portal Timeout In"),(String)(_configPortalTimeout/1000) + (String)F(" seconds")); #endif return result; // skip blocking loop } @@ -776,8 +776,8 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // enter blocking loop, waiting for config #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Config Portal Running, blocking, waiting for clients...")); - if(_configPortalTimeout > 0) DEBUG_WM(DEBUG_VERBOSE,F("Portal Timeout In"),(String)(_configPortalTimeout/1000) + (String)F(" seconds")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Config Portal Running, blocking, waiting for clients...")); + if(_configPortalTimeout > 0) DEBUG_WM(WM_DEBUG_VERBOSE,F("Portal Timeout In"),(String)(_configPortalTimeout/1000) + (String)F(" seconds")); #endif while(1){ @@ -785,13 +785,13 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // if timed out or abort, break if(configPortalHasTimeout() || abort){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("configportal loop abort")); + DEBUG_WM(WM_DEBUG_DEV,F("configportal loop abort")); #endif shutdownConfigPortal(); result = abort ? portalAbortResult : portalTimeoutResult; // false, false if (_configportaltimeoutcallback != NULL) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[CB] config portal timeout callback")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] config portal timeout callback")); #endif _configportaltimeoutcallback(); // @CALLBACK } @@ -805,7 +805,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // 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")); + DEBUG_WM(WM_DEBUG_DEV,F("configportal loop break")); break; } @@ -815,7 +815,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo } #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_NOTIFY,F("config portal exiting")); + DEBUG_WM(WM_DEBUG_NOTIFY,F("config portal exiting")); #endif return result; } @@ -835,13 +835,13 @@ boolean WiFiManager::process(){ // if timed out or abort, break if(_allowExit && (configPortalHasTimeout() || abort)){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("process loop abort")); + DEBUG_WM(WM_DEBUG_DEV,F("process loop abort")); #endif webPortalActive = false; shutdownConfigPortal(); if (_configportaltimeoutcallback != NULL) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[CB] config portal timeout callback")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] config portal timeout callback")); #endif _configportaltimeoutcallback(); // @CALLBACK } @@ -874,14 +874,14 @@ uint8_t WiFiManager::processConfigPortal(){ if(connect) { connect = false; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("processing save")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("processing save")); #endif if(_enableCaptivePortal) delay(_cpclosedelay); // keeps the captiveportal from closing to fast. // skip wifi if no ssid if(_ssid == ""){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("No ssid, skipping wifi save")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("No ssid, skipping wifi save")); #endif } else{ @@ -900,7 +900,7 @@ uint8_t WiFiManager::processConfigPortal(){ if ( _savewificallback != NULL) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[CB] _savewificallback calling")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] _savewificallback calling")); #endif _savewificallback(); // @CALLBACK } @@ -909,7 +909,7 @@ uint8_t WiFiManager::processConfigPortal(){ return WL_CONNECTED; // CONNECT SUCCESS } #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] Connect to new AP Failed")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] Connect to new AP Failed")); #endif } @@ -920,7 +920,7 @@ uint8_t WiFiManager::processConfigPortal(){ // confirm or verify data was saved to make this more accurate callback if ( _savewificallback != NULL) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[CB] WiFi/Param save callback")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[CB] WiFi/Param save callback")); #endif _savewificallback(); // @CALLBACK } @@ -935,12 +935,12 @@ uint8_t WiFiManager::processConfigPortal(){ WiFi_Disconnect(); WiFi_enableSTA(false); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Processing - Disabling STA")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Processing - Disabling STA")); #endif } else{ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Portal is non blocking - remaining open")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Portal is non blocking - remaining open")); #endif } } @@ -955,7 +955,7 @@ uint8_t WiFiManager::processConfigPortal(){ */ bool WiFiManager::shutdownConfigPortal(){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("shutdownConfigPortal")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("shutdownConfigPortal")); #endif if(webPortalActive) return false; @@ -990,23 +990,23 @@ bool WiFiManager::shutdownConfigPortal(){ ret = WiFi.softAPdisconnect(false); #ifdef WM_DEBUG_LEVEL - if(!ret)DEBUG_WM(DEBUG_ERROR,F("[ERROR] disconnect configportal - softAPdisconnect FAILED")); - DEBUG_WM(DEBUG_VERBOSE,F("restoring usermode"),getModeString(_usermode)); + if(!ret)DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] disconnect configportal - softAPdisconnect FAILED")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("restoring usermode"),getModeString(_usermode)); #endif delay(1000); WiFi_Mode(_usermode); // restore users wifi mode, BUG https://github.com/esp8266/Arduino/issues/4372 if(WiFi.status()==WL_IDLE_STATUS){ WiFi.reconnect(); // restart wifi since we disconnected it in startconfigportal #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Reconnect, was idle")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Reconnect, was idle")); #endif } #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("wifi status:"),getWLStatusString(WiFi.status())); - DEBUG_WM(DEBUG_VERBOSE,F("wifi mode:"),getModeString(WiFi.getMode())); + DEBUG_WM(WM_DEBUG_VERBOSE,F("wifi status:"),getWLStatusString(WiFi.status())); + DEBUG_WM(WM_DEBUG_VERBOSE,F("wifi mode:"),getModeString(WiFi.getMode())); #endif configPortalActive = false; - DEBUG_WM(DEBUG_VERBOSE,F("configportal closed")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("configportal closed")); _end(); return ret; } @@ -1016,7 +1016,7 @@ bool WiFiManager::shutdownConfigPortal(){ // clean up, flow is convoluted, and causes bugs uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Connecting as wifi client...")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Connecting as wifi client...")); #endif uint8_t retry = 1; uint8_t connRes = (uint8_t)WL_NO_SSID_AVAIL; @@ -1069,7 +1069,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) { } #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Connection result:"),getWLStatusString(connRes)); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Connection result:"),getWLStatusString(connRes)); #endif retry++; } @@ -1103,16 +1103,16 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass, bool connect) { bool WiFiManager::wifiConnectNew(String ssid, String pass,bool connect){ bool ret = false; #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_DEV,F("CONNECTED: "),WiFi.status() == WL_CONNECTED ? "Y" : "NO"); + // DEBUG_WM(WM_DEBUG_DEV,F("CONNECTED: "),WiFi.status() == WL_CONNECTED ? "Y" : "NO"); DEBUG_WM(F("Connecting to NEW AP:"),ssid); - DEBUG_WM(DEBUG_DEV,F("Using Password:"),pass); + DEBUG_WM(WM_DEBUG_DEV,F("Using Password:"),pass); #endif WiFi_enableSTA(true,storeSTAmode); // storeSTAmode will also toggle STA on in default opmode (persistent) if true (default) WiFi.persistent(true); ret = WiFi.begin(ssid.c_str(), pass.c_str(), 0, NULL, connect); WiFi.persistent(false); #ifdef WM_DEBUG_LEVEL - if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] wifi begin failed")); + if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] wifi begin failed")); #endif return ret; } @@ -1127,21 +1127,21 @@ bool WiFiManager::wifiConnectDefault(){ #ifdef WM_DEBUG_LEVEL DEBUG_WM(F("Connecting to SAVED AP:"),WiFi_SSID(true)); - DEBUG_WM(DEBUG_DEV,F("Using Password:"),WiFi_psk(true)); + DEBUG_WM(WM_DEBUG_DEV,F("Using Password:"),WiFi_psk(true)); #endif ret = WiFi_enableSTA(true,storeSTAmode); delay(500); // THIS DELAY ? #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Mode after delay: "),getModeString(WiFi.getMode())); - if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] wifi enableSta failed")); + DEBUG_WM(WM_DEBUG_DEV,F("Mode after delay: "),getModeString(WiFi.getMode())); + if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] wifi enableSta failed")); #endif ret = WiFi.begin(); #ifdef WM_DEBUG_LEVEL - if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] wifi begin failed")); + if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] wifi begin failed")); #endif return ret; @@ -1155,34 +1155,34 @@ bool WiFiManager::wifiConnectDefault(){ */ bool WiFiManager::setSTAConfig(){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("STA static IP:"),_sta_static_ip); + DEBUG_WM(WM_DEBUG_DEV,F("STA static IP:"),_sta_static_ip); #endif bool ret = true; if (_sta_static_ip) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Custom static IP/GW/Subnet/DNS")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Custom static IP/GW/Subnet/DNS")); #endif if(_sta_static_dns) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Custom static DNS")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Custom static DNS")); #endif ret = WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn, _sta_static_dns); } else { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Custom STA IP/GW/Subnet")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Custom STA IP/GW/Subnet")); #endif ret = WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn); } #ifdef WM_DEBUG_LEVEL - if(!ret) DEBUG_WM(DEBUG_ERROR,F("[ERROR] wifi config failed")); + if(!ret) DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] wifi config failed")); else DEBUG_WM(F("STA IP set:"),WiFi.localIP()); #endif } else { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("setSTAConfig static ip not set, skipping")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("setSTAConfig static ip not set, skipping")); #endif } return ret; @@ -1202,21 +1202,21 @@ void WiFiManager::updateConxResult(uint8_t status){ // if(_lastconxresult == WL_CONNECT_FAILED){ if(_lastconxresult == WL_CONNECT_FAILED || _lastconxresult == WL_DISCONNECTED){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("lastconxresulttmp:"),getWLStatusString(_lastconxresulttmp)); + DEBUG_WM(WM_DEBUG_DEV,F("lastconxresulttmp:"),getWLStatusString(_lastconxresulttmp)); #endif if(_lastconxresulttmp != WL_IDLE_STATUS){ _lastconxresult = _lastconxresulttmp; // _lastconxresulttmp = WL_IDLE_STATUS; } } - DEBUG_WM(DEBUG_DEV,F("lastconxresult:"),getWLStatusString(_lastconxresult)); + DEBUG_WM(WM_DEBUG_DEV,F("lastconxresult:"),getWLStatusString(_lastconxresult)); #endif } uint8_t WiFiManager::waitForConnectResult() { #ifdef WM_DEBUG_LEVEL - if(_connectTimeout > 0) DEBUG_WM(DEBUG_DEV,_connectTimeout,F("ms connectTimeout set")); + if(_connectTimeout > 0) DEBUG_WM(WM_DEBUG_DEV,_connectTimeout,F("ms connectTimeout set")); #endif return waitForConnectResult(_connectTimeout); } @@ -1236,7 +1236,7 @@ uint8_t WiFiManager::waitForConnectResult(uint32_t timeout) { unsigned long timeoutmillis = millis() + timeout; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,timeout,F("ms timeout, waiting for connect...")); + DEBUG_WM(WM_DEBUG_VERBOSE,timeout,F("ms timeout, waiting for connect...")); #endif uint8_t status = WiFi.status(); @@ -1247,7 +1247,7 @@ uint8_t WiFiManager::waitForConnectResult(uint32_t timeout) { return status; } #ifdef WM_DEBUG_LEVEL - DEBUG_WM (DEBUG_VERBOSE,F(".")); + DEBUG_WM (WM_DEBUG_VERBOSE,F(".")); #endif delay(100); } @@ -1312,13 +1312,13 @@ void WiFiManager::handleRequest() { bool testauth = false; if(!testauth) return; - DEBUG_WM(DEBUG_DEV,F("DOING AUTH")); + DEBUG_WM(WM_DEBUG_DEV,F("DOING AUTH")); bool res = server->authenticate("admin","12345"); if(!res){ #ifndef WM_NOAUTH server->requestAuthentication(HTTPAuthMethod::BASIC_AUTH); // DIGEST_AUTH #endif - DEBUG_WM(DEBUG_DEV,F("AUTH FAIL")); + DEBUG_WM(WM_DEBUG_DEV,F("AUTH FAIL")); } } @@ -1327,7 +1327,7 @@ void WiFiManager::handleRequest() { */ void WiFiManager::handleRoot() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Root")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Root")); #endif if (captivePortal()) return; // If captive portal redirect instead of displaying the page handleRequest(); @@ -1353,13 +1353,13 @@ void WiFiManager::handleRoot() { */ void WiFiManager::handleWifi(boolean scan) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Wifi")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Wifi")); #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titlewifi)); // @token titlewifi if (scan) { #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_DEV,"refresh flag:",server->hasArg(F("refresh"))); + // DEBUG_WM(WM_DEBUG_DEV,"refresh flag:",server->hasArg(F("refresh"))); #endif WiFi_scanNetworks(server->hasArg(F("refresh")),false); //wifiscan, force if arg refresh page += getScanItemOut(); @@ -1400,7 +1400,7 @@ void WiFiManager::handleWifi(boolean scan) { HTTPSend(page); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Sent config page")); + DEBUG_WM(WM_DEBUG_DEV,F("Sent config page")); #endif } @@ -1409,7 +1409,7 @@ void WiFiManager::handleWifi(boolean scan) { */ void WiFiManager::handleParam(){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Param")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Param")); #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titleparam)); // @token titlewifi @@ -1429,7 +1429,7 @@ void WiFiManager::handleParam(){ HTTPSend(page); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Sent param page")); + DEBUG_WM(WM_DEBUG_DEV,F("Sent param page")); #endif } @@ -1458,8 +1458,8 @@ void WiFiManager::WiFi_scanComplete(int networksFound){ _lastscan = millis(); _numNetworks = networksFound; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC completed"), "in "+(String)(_lastscan - _startscan)+" ms"); - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC found:"),_numNetworks); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan ASYNC completed"), "in "+(String)(_lastscan - _startscan)+" ms"); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan ASYNC found:"),_numNetworks); #endif } @@ -1475,15 +1475,15 @@ bool WiFiManager::WiFi_scanNetworks(unsigned int cachetime){ } bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_DEV,"scanNetworks async:",async == true); - // DEBUG_WM(DEBUG_DEV,_numNetworks,(millis()-_lastscan )); - // DEBUG_WM(DEBUG_DEV,"scanNetworks force:",force == true); + // DEBUG_WM(WM_DEBUG_DEV,"scanNetworks async:",async == true); + // DEBUG_WM(WM_DEBUG_DEV,_numNetworks,(millis()-_lastscan )); + // DEBUG_WM(WM_DEBUG_DEV,"scanNetworks force:",force == true); #endif // if 0 networks, rescan @note this was a kludge, now disabling to test real cause ( maybe wifi not init etc) // enable only if preload failed? if(_numNetworks == 0 && _autoforcerescan){ - DEBUG_WM(DEBUG_DEV,"NO APs found forcing new scan"); + DEBUG_WM(WM_DEBUG_DEV,"NO APs found forcing new scan"); force = true; } @@ -1499,38 +1499,38 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ #ifdef ESP8266 #ifndef WM_NOASYNC // no async available < 2.4.0 #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); #endif using namespace std::placeholders; // for `_1` WiFi.scanNetworksAsync(std::bind(&WiFiManager::WiFi_scanComplete,this,_1)); #else - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan SYNC started")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan SYNC started")); res = WiFi.scanNetworks(); #endif #else #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); #endif res = WiFi.scanNetworks(true); #endif return false; } else{ - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan SYNC started")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan SYNC started")); res = WiFi.scanNetworks(); } if(res == WIFI_SCAN_FAILED){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] scan failed")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] scan failed")); #endif } else if(res == WIFI_SCAN_RUNNING){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] scan waiting")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] scan waiting")); #endif while(WiFi.scanComplete() == WIFI_SCAN_RUNNING){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,"."); + DEBUG_WM(WM_DEBUG_ERROR,"."); #endif delay(100); } @@ -1539,13 +1539,13 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ else if(res >=0 ) _numNetworks = res; _lastscan = millis(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan completed"), "in "+(String)(_lastscan - _startscan)+" ms"); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFi Scan completed"), "in "+(String)(_lastscan - _startscan)+" ms"); #endif return true; } else { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Scan is cached"),(String)(millis()-_lastscan )+" ms ago"); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Scan is cached"),(String)(millis()-_lastscan )+" ms ago"); #endif } return false; @@ -1599,7 +1599,7 @@ String WiFiManager::WiFiManager::getScanItemOut(){ for (int j = i + 1; j < n; j++) { if (cssid == WiFi.SSID(indices[j])) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("DUP AP:"),WiFi.SSID(indices[j])); + DEBUG_WM(WM_DEBUG_VERBOSE,F("DUP AP:"),WiFi.SSID(indices[j])); #endif indices[j] = -1; // set dup aps to index -1 } @@ -1628,7 +1628,7 @@ String WiFiManager::WiFiManager::getScanItemOut(){ if (indices[i] == -1) continue; // skip dups #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("AP: "),(String)WiFi.RSSI(indices[i]) + " " + (String)WiFi.SSID(indices[i])); + DEBUG_WM(WM_DEBUG_VERBOSE,F("AP: "),(String)WiFi.RSSI(indices[i]) + " " + (String)WiFi.SSID(indices[i])); #endif int rssiperc = getRSSIasQuality(WiFi.RSSI(indices[i])); @@ -1654,13 +1654,13 @@ String WiFiManager::WiFiManager::getScanItemOut(){ } } #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,item); + DEBUG_WM(WM_DEBUG_DEV,item); #endif page += item; delay(0); } else { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Skipping , does not meet _minimumQuality")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Skipping , does not meet _minimumQuality")); #endif } @@ -1689,7 +1689,7 @@ String WiFiManager::getStaticOut(){ String page; if ((_staShowStaticFields || _sta_static_ip) && _staShowStaticFields>=0) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("_staShowStaticFields")); + DEBUG_WM(WM_DEBUG_DEV,F("_staShowStaticFields")); #endif page += FPSTR(HTTP_FORM_STATIC_HEAD); // @todo how can we get these accurate settings from memory , wifi_get_ip_info does not seem to reveal if struct ip_info is static or not @@ -1714,7 +1714,7 @@ String WiFiManager::getParamOut(){ String page; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("getParamOut"),_paramsCount); + DEBUG_WM(WM_DEBUG_DEV,F("getParamOut"),_paramsCount); #endif if(_paramsCount > 0){ @@ -1737,7 +1737,7 @@ String WiFiManager::getParamOut(){ if (_params[i] == NULL || _params[i]->_length > 99999) { // try to detect param scope issues, doesnt always catch but works ok #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] WiFiManagerParameter is out of scope")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] WiFiManagerParameter is out of scope")); #endif return ""; } @@ -1788,7 +1788,7 @@ String WiFiManager::getParamOut(){ void WiFiManager::handleWiFiStatus(){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP WiFi status ")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP WiFi status ")); #endif handleRequest(); String page; @@ -1804,8 +1804,8 @@ void WiFiManager::handleWiFiStatus(){ */ void WiFiManager::handleWifiSave() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP WiFi save ")); - DEBUG_WM(DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST)); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP WiFi save ")); + DEBUG_WM(WM_DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST)); #endif handleRequest(); @@ -1826,7 +1826,7 @@ void WiFiManager::handleWifiSave() { requestinfo += " " + server->argName(i) + ": " + server->arg(i) + "\n"; } - DEBUG_WM(DEBUG_MAX,requestinfo); + DEBUG_WM(WM_DEBUG_MAX,requestinfo); #endif // set static ips from server args @@ -1835,28 +1835,28 @@ void WiFiManager::handleWifiSave() { String ip = server->arg(FPSTR(S_ip)); optionalIPFromString(&_sta_static_ip, ip.c_str()); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("static ip:"),ip); + DEBUG_WM(WM_DEBUG_DEV,F("static ip:"),ip); #endif } if (server->arg(FPSTR(S_gw)) != "") { String gw = server->arg(FPSTR(S_gw)); optionalIPFromString(&_sta_static_gw, gw.c_str()); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("static gateway:"),gw); + DEBUG_WM(WM_DEBUG_DEV,F("static gateway:"),gw); #endif } if (server->arg(FPSTR(S_sn)) != "") { String sn = server->arg(FPSTR(S_sn)); optionalIPFromString(&_sta_static_sn, sn.c_str()); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("static netmask:"),sn); + DEBUG_WM(WM_DEBUG_DEV,F("static netmask:"),sn); #endif } if (server->arg(FPSTR(S_dns)) != "") { String dns = server->arg(FPSTR(S_dns)); optionalIPFromString(&_sta_static_dns, dns.c_str()); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("static DNS:"),dns); + DEBUG_WM(WM_DEBUG_DEV,F("static DNS:"),dns); #endif } @@ -1884,7 +1884,7 @@ void WiFiManager::handleWifiSave() { HTTPSend(page); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Sent wifi save page")); + DEBUG_WM(WM_DEBUG_DEV,F("Sent wifi save page")); #endif connect = true; //signal ready to connect/reset process in processConfigPortal @@ -1893,10 +1893,10 @@ void WiFiManager::handleWifiSave() { void WiFiManager::handleParamSave() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Param save ")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Param save ")); #endif #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST)); + DEBUG_WM(WM_DEBUG_DEV,F("Method:"),server->method() == HTTP_GET ? (String)FPSTR(S_GET) : (String)FPSTR(S_POST)); #endif handleRequest(); @@ -1910,7 +1910,7 @@ void WiFiManager::handleParamSave() { HTTPSend(page); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Sent param save page")); + DEBUG_WM(WM_DEBUG_DEV,F("Sent param save page")); #endif } @@ -1923,14 +1923,14 @@ void WiFiManager::doParamSave(){ //parameters if(_paramsCount > 0){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Parameters")); - DEBUG_WM(DEBUG_VERBOSE,FPSTR(D_HR)); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Parameters")); + DEBUG_WM(WM_DEBUG_VERBOSE,FPSTR(D_HR)); #endif for (int i = 0; i < _paramsCount; i++) { if (_params[i] == NULL || _params[i]->_length > 99999) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] WiFiManagerParameter is out of scope")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] WiFiManagerParameter is out of scope")); #endif break; // @todo might not be needed anymore } @@ -1946,11 +1946,11 @@ void WiFiManager::doParamSave(){ //store it in params array value.toCharArray(_params[i]->_value, _params[i]->_length+1); // length+1 null terminated #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,(String)_params[i]->getID() + ":",value); + DEBUG_WM(WM_DEBUG_VERBOSE,(String)_params[i]->getID() + ":",value); #endif } #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,FPSTR(D_HR)); + DEBUG_WM(WM_DEBUG_VERBOSE,FPSTR(D_HR)); #endif } @@ -1965,7 +1965,7 @@ void WiFiManager::doParamSave(){ */ void WiFiManager::handleInfo() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Info")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Info")); #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titleinfo)); // @token titleinfo @@ -2067,7 +2067,7 @@ void WiFiManager::handleInfo() { HTTPSend(page); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("Sent info page")); + DEBUG_WM(WM_DEBUG_DEV,F("Sent info page")); #endif } @@ -2310,7 +2310,7 @@ String WiFiManager::getInfoData(String id){ */ void WiFiManager::handleExit() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Exit")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Exit")); #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit @@ -2327,7 +2327,7 @@ void WiFiManager::handleExit() { */ void WiFiManager::handleReset() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Reset")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP Reset")); #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titlereset)); //@token titlereset @@ -2352,7 +2352,7 @@ void WiFiManager::handleReset() { // } void WiFiManager::handleErase(boolean opt) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_NOTIFY,F("<- HTTP Erase")); + DEBUG_WM(WM_DEBUG_NOTIFY,F("<- HTTP Erase")); #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titleerase)); // @token titleerase @@ -2363,7 +2363,7 @@ void WiFiManager::handleErase(boolean opt) { else { page += FPSTR(S_error); // @token erroroccur #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] WiFi EraseConfig failed")); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] WiFi EraseConfig failed")); #endif } @@ -2410,7 +2410,7 @@ void WiFiManager::handleNotFound() { */ boolean WiFiManager::captivePortal() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_MAX,"-> " + server->hostHeader()); + DEBUG_WM(WM_DEBUG_MAX,"-> " + server->hostHeader()); #endif if(!_enableCaptivePortal) return false; // skip redirections, @todo maybe allow redirection even when no cp ? might be useful @@ -2418,11 +2418,10 @@ boolean WiFiManager::captivePortal() { String serverLoc = toStringIp(server->client().localIP()); if(_httpPort != 80) serverLoc += ":" + (String)_httpPort; // add port if not default bool doredirect = serverLoc != server->hostHeader(); // redirect if hostheader not server ip, prevent redirect loops - // doredirect = !isIp(server->hostHeader()) // old check if (doredirect) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- Request redirected to captive portal")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- Request redirected to captive portal")); #endif server->sendHeader(F("Location"), (String)F("http://") + serverLoc, true); // @HTTPHEAD send redirect server->send ( 302, FPSTR(HTTP_HEAD_CT2), ""); // Empty content inhibits Content-length header so we have to close the socket ourselves. @@ -2439,10 +2438,10 @@ void WiFiManager::stopCaptivePortal(){ // HTTPD CALLBACK, handle close, stop captive portal, if not enabled undefined void WiFiManager::handleClose(){ - DEBUG_WM(DEBUG_VERBOSE,F("Disabling Captive Portal")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Disabling Captive Portal")); stopCaptivePortal(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP close")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- HTTP close")); #endif handleRequest(); String page = getHTTPHead(FPSTR(S_titleclose)); // @token titleclose @@ -2452,8 +2451,8 @@ void WiFiManager::handleClose(){ void WiFiManager::reportStatus(String &page){ // updateConxResult(WiFi.status()); // @todo: this defeats the purpose of last result, update elsewhere or add logic here - DEBUG_WM(DEBUG_DEV,F("[WIFI] reportStatus prev:"),getWLStatusString(_lastconxresult)); - DEBUG_WM(DEBUG_DEV,F("[WIFI] reportStatus current:"),getWLStatusString(WiFi.status())); + DEBUG_WM(WM_DEBUG_DEV,F("[WIFI] reportStatus prev:"),getWLStatusString(_lastconxresult)); + DEBUG_WM(WM_DEBUG_DEV,F("[WIFI] reportStatus current:"),getWLStatusString(WiFi.status())); String str; if (WiFi_SSID() != ""){ if (WiFi.status()==WL_CONNECTED){ @@ -2520,7 +2519,7 @@ bool WiFiManager::stopConfigPortal(){ bool WiFiManager::disconnect(){ if(WiFi.status() != WL_CONNECTED){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("Disconnecting: Not connected")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("Disconnecting: Not connected")); #endif return false; } @@ -2563,11 +2562,11 @@ bool WiFiManager::erase(bool opt){ esp_err_t err; err = nvs_flash_init(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("nvs_flash_init: "),err!=ESP_OK ? (String)err : "Success"); + DEBUG_WM(WM_DEBUG_VERBOSE,F("nvs_flash_init: "),err!=ESP_OK ? (String)err : "Success"); #endif err = nvs_flash_erase(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("nvs_flash_erase: "), err!=ESP_OK ? (String)err : "Success"); + DEBUG_WM(WM_DEBUG_VERBOSE,F("nvs_flash_erase: "), err!=ESP_OK ? (String)err : "Success"); #endif return err == ESP_OK; } @@ -2580,7 +2579,7 @@ bool WiFiManager::erase(bool opt){ #endif bool ret = SPIFFS.format(); #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("spiffs erase: "),ret ? "Success" : "ERROR"); + DEBUG_WM(WM_DEBUG_VERBOSE,F("spiffs erase: "),ret ? "Success" : "ERROR"); #endif } else{ #ifdef WM_DEBUG_LEVEL @@ -2698,7 +2697,8 @@ void WiFiManager::setSaveConnect(bool connect) { */ void WiFiManager::setDebugOutput(boolean debug) { _debug = debug; - if(_debug && _debugLevel == DEBUG_DEV) debugPlatformInfo(); + if(_debug && _debugLevel == WM_DEBUG_DEV) debugPlatformInfo(); + if(_debug && _debugLevel >= WM_DEBUG_NOTIFY) DEBUG_WM((String)WM_VERSION_STR + " L:"+(String)_debugLevel); } void WiFiManager::setDebugOutput(boolean debug, String prefix) { @@ -2706,6 +2706,13 @@ void WiFiManager::setDebugOutput(boolean debug, String prefix) { setDebugOutput(debug); } +void WiFiManager::setDebugOutput(boolean debug, wm_debuglevel_t level) { + _debugLevel = level; + // _debugPrefix = prefix; + setDebugOutput(debug); +} + + /** * [setAPStaticIPConfig description] * @access public @@ -3120,7 +3127,7 @@ void WiFiManager::setTitle(String title){ */ void WiFiManager::setMenu(const char * menu[], uint8_t size){ #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_DEV,"setmenu array"); + // DEBUG_WM(WM_DEBUG_DEV,"setmenu array"); #endif _menuIds.clear(); for(size_t i = 0; i < size; i++){ @@ -3147,7 +3154,7 @@ void WiFiManager::setMenu(const char * menu[], uint8_t size){ */ void WiFiManager::setMenu(std::vector& menu){ #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_DEV,"setmenu vector"); + // DEBUG_WM(WM_DEBUG_DEV,"setmenu vector"); #endif _menuIds.clear(); for(auto menuitem : menu ){ @@ -3159,7 +3166,7 @@ void WiFiManager::setMenu(std::vector& menu){ } } #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_DEV,getMenuOut()); + // DEBUG_WM(WM_DEBUG_DEV,getMenuOut()); #endif } @@ -3289,7 +3296,7 @@ String WiFiManager::getWiFiPass(bool persistent){ // @todo fix DEBUG_WM(0,0); template void WiFiManager::DEBUG_WM(Generic text) { - DEBUG_WM(DEBUG_NOTIFY,text,""); + DEBUG_WM(WM_DEBUG_NOTIFY,text,""); } template @@ -3299,14 +3306,14 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text) { template void WiFiManager::DEBUG_WM(Generic text,Genericb textb) { - DEBUG_WM(DEBUG_NOTIFY,text,textb); + DEBUG_WM(WM_DEBUG_NOTIFY,text,textb); } template void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { if(!_debug || _debugLevel < level) return; - if(_debugLevel > DEBUG_MAX){ + if(_debugLevel > WM_DEBUG_MAX){ #ifdef ESP8266 // uint32_t free; // uint16_t max; @@ -3459,8 +3466,8 @@ boolean WiFiManager::validApPassword(){ 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")); - DEBUG_WM(DEBUG_DEV,"ap pass",_apPassword); + DEBUG_WM(WM_DEBUG_VERBOSE,F("AccessPoint set password is VALID")); + DEBUG_WM(WM_DEBUG_DEV,"ap pass",_apPassword); #endif } return true; @@ -3519,7 +3526,7 @@ bool WiFiManager::WiFiSetCountry(){ if(_wificountry == "") return false; // skip not set #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("WiFiSetCountry to"),_wificountry); + DEBUG_WM(WM_DEBUG_VERBOSE,F("WiFiSetCountry to"),_wificountry); #endif /* @@ -3538,7 +3545,7 @@ bool WiFiManager::WiFiSetCountry(){ esp_err_t err = ESP_OK; // @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"); + DEBUG_WM(WM_DEBUG_ERROR,"[ERROR] cannot set country, wifi not init"); } // exception if wifi not init! // Assumes that _wificountry is set to one of the supported country codes : "01"(world safe mode) "AT","AU","BE","BG","BR", // "CA","CH","CN","CY","CZ","DE","DK","EE","ES","FI","FR","GB","GR","HK","HR","HU", @@ -3551,15 +3558,15 @@ bool WiFiManager::WiFiSetCountry(){ #ifndef WM_NOCOUNTRY err = esp_wifi_set_country_code(_wificountry.c_str(), true); #else - DEBUG_WM(DEBUG_ERROR,"[ERROR] esp wifi set country is not available"); + DEBUG_WM(WM_DEBUG_ERROR,"[ERROR] esp wifi set country is not available"); err = true; #endif } #ifdef WM_DEBUG_LEVEL if(err){ - if(err == ESP_ERR_WIFI_NOT_INIT) DEBUG_WM(DEBUG_ERROR,"[ERROR] ESP_ERR_WIFI_NOT_INIT"); - else if(err == ESP_ERR_INVALID_ARG) DEBUG_WM(DEBUG_ERROR,"[ERROR] ESP_ERR_WIFI_ARG (invalid country code)"); - else if(err != ESP_OK)DEBUG_WM(DEBUG_ERROR,"[ERROR] unknown error",(String)err); + if(err == ESP_ERR_WIFI_NOT_INIT) DEBUG_WM(WM_DEBUG_ERROR,"[ERROR] ESP_ERR_WIFI_NOT_INIT"); + else if(err == ESP_ERR_INVALID_ARG) DEBUG_WM(WM_DEBUG_ERROR,"[ERROR] ESP_ERR_WIFI_ARG (invalid country code)"); + else if(err != ESP_OK)DEBUG_WM(WM_DEBUG_ERROR,"[ERROR] unknown error",(String)err); } #endif ret = err == ESP_OK; @@ -3570,13 +3577,13 @@ bool WiFiManager::WiFiSetCountry(){ else if(_wificountry == "JP") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_JP); else if(_wificountry == "CN") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_CN); #ifdef WM_DEBUG_LEVEL - else DEBUG_WM(DEBUG_ERROR,F("[ERROR] country code not found")); + else DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] country code not found")); #endif #endif #ifdef WM_DEBUG_LEVEL - if(ret) DEBUG_WM(DEBUG_VERBOSE,F("[OK] esp_wifi_set_country: "),_wificountry); - else DEBUG_WM(DEBUG_ERROR,F("[ERROR] esp_wifi_set_country failed")); + if(ret) DEBUG_WM(WM_DEBUG_VERBOSE,F("[OK] esp_wifi_set_country: "),_wificountry); + else DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] esp_wifi_set_country failed")); #endif return ret; } @@ -3610,7 +3617,7 @@ bool WiFiManager::WiFi_Disconnect() { if((WiFi.getMode() & WIFI_STA) != 0) { bool ret; #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("WiFi station disconnect")); + DEBUG_WM(WM_DEBUG_DEV,F("WiFi station disconnect")); #endif ETS_UART_INTR_DISABLE(); // @todo possibly not needed ret = wifi_station_disconnect(); @@ -3619,7 +3626,7 @@ bool WiFiManager::WiFi_Disconnect() { } #elif defined(ESP32) #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("WiFi station disconnect")); + DEBUG_WM(WM_DEBUG_DEV,F("WiFi station disconnect")); #endif return WiFi.disconnect(); // not persistent atm #endif @@ -3629,7 +3636,7 @@ bool WiFiManager::WiFi_Disconnect() { // toggle STA without persistent bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("WiFi_enableSTA"),(String) enable? "enable" : "disable"); + DEBUG_WM(WM_DEBUG_DEV,F("WiFi_enableSTA"),(String) enable? "enable" : "disable"); #endif #ifdef ESP8266 WiFiMode_t newMode; @@ -3641,7 +3648,7 @@ bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) { if((isEnabled != enable) || persistent) { if(enable) { #ifdef WM_DEBUG_LEVEL - if(persistent) DEBUG_WM(DEBUG_DEV,F("enableSTA PERSISTENT ON")); + if(persistent) DEBUG_WM(WM_DEBUG_DEV,F("enableSTA PERSISTENT ON")); #endif return WiFi_Mode(newMode,persistent); } @@ -3666,7 +3673,7 @@ bool WiFiManager::WiFi_enableSTA(bool enable) { bool WiFiManager::WiFi_eraseConfig() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_DEV,F("WiFi_eraseConfig")); + DEBUG_WM(WM_DEBUG_DEV,F("WiFi_eraseConfig")); #endif #ifdef ESP8266 @@ -3774,7 +3781,7 @@ String WiFiManager::WiFi_psk(bool persistent) const { #endif if(!_hasBegun){ #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_VERBOSE,"[ERROR] WiFiEvent, not ready"); + // DEBUG_WM(WM_DEBUG_VERBOSE,"[ERROR] WiFiEvent, not ready"); #endif // Serial.println(F("\n[EVENT] WiFiEvent logging (wm debug not available)")); // Serial.print(F("[EVENT] ID: ")); @@ -3782,25 +3789,25 @@ String WiFiManager::WiFi_psk(bool persistent) const { return; } #ifdef WM_DEBUG_LEVEL - // DEBUG_WM(DEBUG_VERBOSE,"[EVENT]",event); + // DEBUG_WM(WM_DEBUG_VERBOSE,"[EVENT]",event); #endif if(event == ARDUINO_EVENT_WIFI_STA_DISCONNECTED){ #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[EVENT] WIFI_REASON: "),info.wifi_sta_disconnected.reason); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[EVENT] WIFI_REASON: "),info.wifi_sta_disconnected.reason); #endif if(info.wifi_sta_disconnected.reason == WIFI_REASON_AUTH_EXPIRE || info.wifi_sta_disconnected.reason == WIFI_REASON_AUTH_FAIL){ _lastconxresulttmp = 7; // hack in wrong password internally, sdk emit WIFI_REASON_AUTH_EXPIRE on some routers on auth_fail } else _lastconxresulttmp = WiFi.status(); #ifdef WM_DEBUG_LEVEL - if(info.wifi_sta_disconnected.reason == WIFI_REASON_NO_AP_FOUND) DEBUG_WM(DEBUG_VERBOSE,F("[EVENT] WIFI_REASON: NO_AP_FOUND")); + if(info.wifi_sta_disconnected.reason == WIFI_REASON_NO_AP_FOUND) DEBUG_WM(WM_DEBUG_VERBOSE,F("[EVENT] WIFI_REASON: NO_AP_FOUND")); if(info.wifi_sta_disconnected.reason == WIFI_REASON_ASSOC_FAIL){ if(_aggresiveReconn) _connectRetries+=4; - DEBUG_WM(DEBUG_VERBOSE,F("[EVENT] WIFI_REASON: AUTH FAIL")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[EVENT] WIFI_REASON: AUTH FAIL")); } #endif #ifdef esp32autoreconnect #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("[Event] SYSTEM_EVENT_STA_DISCONNECTED, reconnecting")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("[Event] SYSTEM_EVENT_STA_DISCONNECTED, reconnecting")); #endif WiFi.reconnect(); #endif @@ -3819,7 +3826,7 @@ void WiFiManager::WiFi_autoReconnect(){ // if(_wifiAutoReconnect){ // @todo move to seperate method, used for event listener now #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("ESP32 event handler enabled")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("ESP32 event handler enabled")); #endif using namespace std::placeholders; if(wm_event_id == 0) wm_event_id = WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2)); @@ -3830,7 +3837,7 @@ void WiFiManager::WiFi_autoReconnect(){ // Called when /update is requested void WiFiManager::handleUpdate() { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("<- Handle update")); + DEBUG_WM(WM_DEBUG_VERBOSE,F("<- Handle update")); #endif if (captivePortal()) return; // If captive portal redirect instead of displaying the page String page = getHTTPHead(_title); // @token options @@ -3888,7 +3895,7 @@ void WiFiManager::handleUpdating(){ #endif #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,"[OTA] Update file: ", upload.filename.c_str()); + DEBUG_WM(WM_DEBUG_VERBOSE,"[OTA] Update file: ", upload.filename.c_str()); #endif // Update.onProgress(THandlerFunction_Progress fn); @@ -3898,7 +3905,7 @@ void WiFiManager::handleUpdating(){ if (!Update.begin(maxSketchSpace)) { // start with max available size #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] OTA Update ERROR"), Update.getError()); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] OTA Update ERROR"), Update.getError()); #endif error = true; Update.end(); // Not sure the best way to abort, I think client will keep sending.. @@ -3909,7 +3916,7 @@ void WiFiManager::handleUpdating(){ // Serial.print("."); if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) { #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_ERROR,F("[ERROR] OTA Update WRITE ERROR"), Update.getError()); + DEBUG_WM(WM_DEBUG_ERROR,F("[ERROR] OTA Update WRITE ERROR"), Update.getError()); //Update.printError(Serial); // write failure #endif error = true; @@ -3919,7 +3926,7 @@ void WiFiManager::handleUpdating(){ else if (upload.status == UPLOAD_FILE_END) { if (Update.end(true)) { // true to set the size to the current progress #ifdef WM_DEBUG_LEVEL - DEBUG_WM(DEBUG_VERBOSE,F("\n\n[OTA] OTA FILE END bytes: "), upload.totalSize); + DEBUG_WM(WM_DEBUG_VERBOSE,F("\n\n[OTA] OTA FILE END bytes: "), upload.totalSize); // Serial.printf("Updated: %u bytes\r\nRebooting...\r\n", upload.totalSize); #endif } @@ -3940,7 +3947,7 @@ void WiFiManager::handleUpdating(){ // upload and ota done, show status void WiFiManager::handleUpdateDone() { - DEBUG_WM(DEBUG_VERBOSE, F("<- Handle update done")); + DEBUG_WM(WM_DEBUG_VERBOSE, F("<- Handle update done")); // if (captivePortal()) return; // If captive portal redirect instead of displaying the page String page = getHTTPHead(FPSTR(S_options)); // @token options diff --git a/WiFiManager.h b/WiFiManager.h index 8c415888b..dbb0a7447 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -235,6 +235,16 @@ class WiFiManagerParameter { }; + // debugging + typedef enum { + WM_DEBUG_SILENT = 0, // debug OFF but still compiled for runtime + WM_DEBUG_ERROR = 1, // error only + WM_DEBUG_NOTIFY = 2, // default stable,INFO + WM_DEBUG_VERBOSE = 3, // move verbose info + WM_DEBUG_DEV = 4, // development useful debugging info + WM_DEBUG_MAX = 5 // MAX extra dev auditing, var dumps etc (MAX+1 will print timing,mem and frag info) + } wm_debuglevel_t; + class WiFiManager { public: @@ -339,6 +349,7 @@ class WiFiManager // toggle debug output void setDebugOutput(boolean debug); void setDebugOutput(boolean debug, String prefix); // log line prefix, default "*wm:" + void setDebugOutput(boolean debug, wm_debuglevel_t level ); // log line prefix, default "*wm:" //set min quality percentage to include in scan, defaults to 8% if not specified void setMinimumSignalQuality(int quality = 8); @@ -758,27 +769,17 @@ class WiFiManager int _max_params; WiFiManagerParameter** _params = NULL; - // debugging - typedef enum { - DEBUG_SILENT = 0, // debug OFF but still compiled for runtime - DEBUG_ERROR = 1, // error only - DEBUG_NOTIFY = 2, // default stable,INFO - DEBUG_VERBOSE = 3, // move verbose info - DEBUG_DEV = 4, // development useful debugging info - DEBUG_MAX = 5 // MAX extra dev auditing, var dumps etc (MAX+1 will print timing,mem and frag info) - } wm_debuglevel_t; - boolean _debug = true; String _debugPrefix = FPSTR(S_debugPrefix); - wm_debuglevel_t debugLvlShow = DEBUG_VERBOSE; // at which level start showing [n] level tags + wm_debuglevel_t debugLvlShow = WM_DEBUG_VERBOSE; // at which level start showing [n] level tags // build debuglevel support // @todo use DEBUG_ESP_x? // Set default debug level #ifndef WM_DEBUG_LEVEL - #define WM_DEBUG_LEVEL DEBUG_NOTIFY + #define WM_DEBUG_LEVEL WM_DEBUG_NOTIFY #endif // override debug level OFF From 5a8e869a7ee0b7998bd5aa82d279a2717caa7270 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Mon, 18 Sep 2023 18:18:12 -0500 Subject: [PATCH 15/31] add workaround for #1543 @etoten thanks, slight change, Might have to add ipv6 detection instead and handle it that way --- WiFiManager.cpp | 10 ++++++++++ WiFiManager.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index b5da15a41..8ec7131b5 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2416,6 +2416,16 @@ boolean WiFiManager::captivePortal() { if(!_enableCaptivePortal) return false; // skip redirections, @todo maybe allow redirection even when no cp ? might be useful String serverLoc = toStringIp(server->client().localIP()); + + // fallback for ipv6 bug + if(serverloc = 0.0.0.0){ + if ((WiFi.status()) != WL_CONNECTED) + serverLoc = toStringIp(WiFi.softAPIP()); + else + serverLoc = toStringIp(WiFi.localIP()); + } + } + if(_httpPort != 80) serverLoc += ":" + (String)_httpPort; // add port if not default bool doredirect = serverLoc != server->hostHeader(); // redirect if hostheader not server ip, prevent redirect loops diff --git a/WiFiManager.h b/WiFiManager.h index dbb0a7447..ce0de1225 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -618,6 +618,9 @@ class WiFiManager // but not limited to, we could run continuous background scans on various page hits, or xhr hits // which would be better coupled with asyncscan // atm preload is only done on root hit and startcp + // + // preload scanning causes AP to delay showing for users, but also caches and lets the cp load faster once its open + // my scan takes 7-10 seconds boolean _preloadwifiscan = true; // preload wifiscan if true unsigned int _scancachetime = 30000; // ms cache time for preload scans boolean _asyncScan = true; // perform wifi network scan async From d6bf07fd712b10299b0767dc93b12bf5d4cf9b1b Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Mon, 18 Sep 2023 18:20:45 -0500 Subject: [PATCH 16/31] Update OnDemandConfigPortal.ino --- .../OnDemandConfigPortal/OnDemandConfigPortal.ino | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino index 2546c6afb..7509ba101 100644 --- a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -92,8 +92,10 @@ void setup() { // put your setup code here, to run once: Serial.begin(115200); + delay(3000); + Serial.setDebugOutput(true); - // Serial.setDebugOutput(true); + WiFi.setTxPower(WIFI_POWER_8_5dBm); Serial.println("\n Starting"); // WiFi.setSleepMode(WIFI_NONE_SLEEP); // disable sleep, can improve ap stability @@ -109,7 +111,7 @@ void setup() { // WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL); // wifi_sort_method_t sortMethod - WIFI_CONNECT_AP_BY_SIGNAL,WIFI_CONNECT_AP_BY_SECURITY // WiFi.setMinSecurity(WIFI_AUTH_WPA2_PSK); - wm.setDebugOutput(true); + wm.setDebugOutput(true, DEBUG_DEV); wm.debugPlatformInfo(); //reset settings - for testing @@ -127,7 +129,7 @@ void setup() { WiFiManagerParameter custom_input_type("input_pwd", "input pass", "", 15,"type='password'"); // custom input attrs (ip mask) const char _customHtml_checkbox[] = "type=\"checkbox\""; - WiFiManagerParameter custom_checkbox("my_checkbox", "My Checkbox", "T", 2, _customHtml_checkbox,WFM_LABEL_AFTER); + WiFiManagerParameter custom_checkbox("my_checkbox", "My Checkbox", "T", 2, _customHtml_checkbox, WFM_LABEL_AFTER); const char *bufferStr = R"( @@ -313,7 +315,7 @@ void setup() { void wifiInfo(){ // can contain gargbage on esp32 if wifi is not ready yet - Serial.println("[WIFI] WIFI INFO DEBUG"); + Serial.println("[WIFI] WIFI_INFO DEBUG"); // WiFi.printDiag(Serial); Serial.println("[WIFI] SAVED: " + (String)(wm.getWiFiIsSaved() ? "YES" : "NO")); Serial.println("[WIFI] SSID: " + (String)wm.getWiFiSSID()); From 6a92492bee047a903e085608816db046032bc734 Mon Sep 17 00:00:00 2001 From: Nicolas T Date: Thu, 21 Sep 2023 15:59:06 +0200 Subject: [PATCH 17/31] Update WiFiManager.cpp (#1657) --- WiFiManager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index a8ea2537d..d0b180834 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2422,12 +2422,11 @@ boolean WiFiManager::captivePortal() { String serverLoc = toStringIp(server->client().localIP()); // fallback for ipv6 bug - if(serverloc = 0.0.0.0){ + if(serverLoc = "0.0.0.0"){ if ((WiFi.status()) != WL_CONNECTED) serverLoc = toStringIp(WiFi.softAPIP()); else serverLoc = toStringIp(WiFi.localIP()); - } } if(_httpPort != 80) serverLoc += ":" + (String)_httpPort; // add port if not default From ba3f1986f2cff8a577d5a9d03043d1102edf93f3 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Thu, 28 Sep 2023 23:41:35 -0500 Subject: [PATCH 18/31] Revert "#1587" This reverts commit b735c61f6ec97c299c457ced4efe1e0c27bdb87e. --- wm_consts_en.h | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/wm_consts_en.h b/wm_consts_en.h index b1c615f46..fc21b42ff 100644 --- a/wm_consts_en.h +++ b/wm_consts_en.h @@ -19,32 +19,20 @@ const char WM_VERSION_STR[] PROGMEM = "v2.0.15-rc.1"; -static const char _wifi_token[] PROGMEM = "wifi"; -static const char _wifinoscan_token[] PROGMEM = "wifinoscan"; -static const char _info_token[] PROGMEM = "info"; -static const char _param_token[] PROGMEM = "param"; -static const char _close_token[] PROGMEM = "close"; -static const char _restart_token[] PROGMEM = "restart"; -static const char _exit_token[] PROGMEM = "exit"; -static const char _erase_token[] PROGMEM = "erase"; -static const char _update_token[] PROGMEM = "update"; -static const char _sep_token[] PROGMEM = "sep"; -static const char _custom_token[] PROGMEM = "custom"; -static PGM_P _menutokens[] PROGMEM = { - _wifi_token, - _wifinoscan_token, - _info_token, - _param_token, - _close_token, - _restart_token, - _exit_token, - _erase_token, - _update_token, - _sep_token, - _custom_token +const uint8_t _nummenutokens = 11; +const char * const _menutokens[_nummenutokens] PROGMEM = { + "wifi", + "wifinoscan", + "info", + "param", + "close", + "restart", + "exit", + "erase", + "update", + "sep", + "custom" }; -const uint8_t _nummenutokens = (sizeof(_menutokens) / sizeof(PGM_P)); - const char R_root[] PROGMEM = "/"; const char R_wifi[] PROGMEM = "/wifi"; From 5a663db42ed3e95bfa7cfb631030a54e99fa92aa Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Mon, 9 Oct 2023 22:22:02 -0500 Subject: [PATCH 19/31] Fix debug_max --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index d0b180834..d0f3be20a 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2711,7 +2711,7 @@ void WiFiManager::setSaveConnect(bool connect) { void WiFiManager::setDebugOutput(boolean debug) { _debug = debug; if(_debug && _debugLevel == WM_DEBUG_DEV) debugPlatformInfo(); - if(_debug && _debugLevel >= WM_DEBUG_NOTIFY) DEBUG_WM((String)WM_VERSION_STR + " L:"+(String)_debugLevel); + if(_debug && _debugLevel >= WM_DEBUG_NOTIFY) DEBUG_WM((String)WM_VERSION_STR + " D:"+(String)_debugLevel); } void WiFiManager::setDebugOutput(boolean debug, String prefix) { @@ -3326,7 +3326,7 @@ template void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { if(!_debug || _debugLevel < level) return; - if(_debugLevel > WM_DEBUG_MAX){ + if(_debugLevel >= WM_DEBUG_MAX){ #ifdef ESP8266 // uint32_t free; // uint16_t max; From 99f770c4938516b8eaed7ab607984119bdf9a1d3 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Mon, 9 Oct 2023 22:22:36 -0500 Subject: [PATCH 20/31] adds button func tests --- .../OnDemandConfigPortal.ino | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino index aab2c6a0c..f9ad38ee2 100644 --- a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -31,6 +31,8 @@ bool ALLOWONDEMAND = true; // enable on demand int ONDDEMANDPIN = 0; // gpio for button bool WMISBLOCKING = true; // use blocking or non blocking mode, non global params wont work in non blocking +uint8_t BUTTONFUNC = 1; // 0 resetsettings, 1 configportal, 2 autoconnect + // char ssid[] = "*************"; // your network SSID (name) // char pass[] = "********"; // your network password @@ -102,9 +104,9 @@ void setup() { // put your setup code here, to run once: Serial.begin(115200); delay(3000); - Serial.setDebugOutput(true); + // Serial.setDebugOutput(true); - WiFi.setTxPower(WIFI_POWER_8_5dBm); + // WiFi.setTxPower(WIFI_POWER_8_5dBm); Serial.println("\n Starting"); // WiFi.setSleepMode(WIFI_NONE_SLEEP); // disable sleep, can improve ap stability @@ -329,7 +331,7 @@ void wifiInfo(){ Serial.println("[WIFI] SAVED: " + (String)(wm.getWiFiIsSaved() ? "YES" : "NO")); Serial.println("[WIFI] SSID: " + (String)wm.getWiFiSSID()); Serial.println("[WIFI] PASS: " + (String)wm.getWiFiPass()); - Serial.println("[WIFI] HOSTNAME: " + (String)WiFi.getHostname()); + // Serial.println("[WIFI] HOSTNAME: " + (String)WiFi.getHostname()); } void loop() { @@ -348,21 +350,28 @@ void loop() { Serial.println("BUTTON PRESSED"); // button reset/reboot - // wm.resetSettings(); - // wm.reboot(); - // delay(200); - // return; + if(BUTTONFUNC == 0){ + wm.resetSettings(); + wm.reboot(); + delay(200); + return; + } - wm.setConfigPortalTimeout(140); - wm.setParamsPage(false); // move params to seperate page, not wifi, do not combine with setmenu! + // start configportal + if(BUTTONFUNC == 1) + if (!wm.startConfigPortal("OnDemandAP","12345678")) { + Serial.println("failed to connect and hit timeout"); + delay(3000); + } + } - // disable captive portal redirection - // wm.setCaptivePortalEnable(false); - - if (!wm.startConfigPortal("OnDemandAP","12345678")) { - Serial.println("failed to connect and hit timeout"); - delay(3000); + //test autoconnect as reconnect etc. + if(BUTTONFUNC == 2){ + wm.setConfigPortalTimeout(20); + wm.autoConnect(); + return; } + } else { //if you get here you have connected to the WiFi From 439af6e6b12a749cd9c4b5d395aa35ac8849c46c Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Mon, 9 Oct 2023 22:24:01 -0500 Subject: [PATCH 21/31] oops --- examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino index f9ad38ee2..af2276dea 100644 --- a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -358,7 +358,7 @@ void loop() { } // start configportal - if(BUTTONFUNC == 1) + if(BUTTONFUNC == 1){ if (!wm.startConfigPortal("OnDemandAP","12345678")) { Serial.println("failed to connect and hit timeout"); delay(3000); From 1cc7df59c2933533f89abc05830647cb7e6552d9 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Tue, 10 Oct 2023 07:09:39 -0500 Subject: [PATCH 22/31] add delays to some loops These are fast and should not be needed but better safe I suppose --- WiFiManager.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index d0f3be20a..04263bad4 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1444,6 +1444,7 @@ String WiFiManager::getMenuOut(){ continue; } page += HTTP_PORTAL_MENU[menuId]; + delay(0); } return page; @@ -3149,7 +3150,9 @@ void WiFiManager::setMenu(const char * menu[], uint8_t size){ if((String)menu[i] == "param") _paramsInWifi = false; // param auto flag _menuIds.push_back(j); } + delay(0); } + delay(0); } #ifdef WM_DEBUG_LEVEL // DEBUG_WM(getMenuOut()); From 72956f563f5e9ae941ecc9312f7cb6687df87af6 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Tue, 10 Oct 2023 21:56:28 -0500 Subject: [PATCH 23/31] Revert "Revert "#1587"" This reverts commit ba3f1986f2cff8a577d5a9d03043d1102edf93f3. --- wm_consts_en.h | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/wm_consts_en.h b/wm_consts_en.h index fc21b42ff..b1c615f46 100644 --- a/wm_consts_en.h +++ b/wm_consts_en.h @@ -19,20 +19,32 @@ const char WM_VERSION_STR[] PROGMEM = "v2.0.15-rc.1"; -const uint8_t _nummenutokens = 11; -const char * const _menutokens[_nummenutokens] PROGMEM = { - "wifi", - "wifinoscan", - "info", - "param", - "close", - "restart", - "exit", - "erase", - "update", - "sep", - "custom" +static const char _wifi_token[] PROGMEM = "wifi"; +static const char _wifinoscan_token[] PROGMEM = "wifinoscan"; +static const char _info_token[] PROGMEM = "info"; +static const char _param_token[] PROGMEM = "param"; +static const char _close_token[] PROGMEM = "close"; +static const char _restart_token[] PROGMEM = "restart"; +static const char _exit_token[] PROGMEM = "exit"; +static const char _erase_token[] PROGMEM = "erase"; +static const char _update_token[] PROGMEM = "update"; +static const char _sep_token[] PROGMEM = "sep"; +static const char _custom_token[] PROGMEM = "custom"; +static PGM_P _menutokens[] PROGMEM = { + _wifi_token, + _wifinoscan_token, + _info_token, + _param_token, + _close_token, + _restart_token, + _exit_token, + _erase_token, + _update_token, + _sep_token, + _custom_token }; +const uint8_t _nummenutokens = (sizeof(_menutokens) / sizeof(PGM_P)); + const char R_root[] PROGMEM = "/"; const char R_wifi[] PROGMEM = "/wifi"; From f328cd05cd5aa758b414d8e6961e21a1f6370cab Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Tue, 10 Oct 2023 22:52:41 -0500 Subject: [PATCH 24/31] possible fixes for these Not entirely sure why esp8266 is not auto casting these --- WiFiManager.cpp | 6 +++--- .../Super/OnDemandConfigPortal/OnDemandConfigPortal.ino | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 04263bad4..f4674d8fd 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2712,7 +2712,7 @@ void WiFiManager::setSaveConnect(bool connect) { void WiFiManager::setDebugOutput(boolean debug) { _debug = debug; if(_debug && _debugLevel == WM_DEBUG_DEV) debugPlatformInfo(); - if(_debug && _debugLevel >= WM_DEBUG_NOTIFY) DEBUG_WM((String)WM_VERSION_STR + " D:"+(String)_debugLevel); + if(_debug && _debugLevel >= WM_DEBUG_NOTIFY)DEBUG_WM((__FlashStringHelper *)WM_VERSION_STR," D:"+String(_debugLevel)); } void WiFiManager::setDebugOutput(boolean debug, String prefix) { @@ -3146,7 +3146,7 @@ void WiFiManager::setMenu(const char * menu[], uint8_t size){ _menuIds.clear(); for(size_t i = 0; i < size; i++){ for(size_t j = 0; j < _nummenutokens; j++){ - if((String)menu[i] == String(_menutokens[j])){ + if((String)menu[i] == (__FlashStringHelper *)(_menutokens[j])){ if((String)menu[i] == "param") _paramsInWifi = false; // param auto flag _menuIds.push_back(j); } @@ -3175,7 +3175,7 @@ void WiFiManager::setMenu(std::vector& menu){ _menuIds.clear(); for(auto menuitem : menu ){ for(size_t j = 0; j < _nummenutokens; j++){ - if((String)menuitem == String(_menutokens[j])){ + if((String)menuitem == (__FlashStringHelper *)(_menutokens[j])){ if((String)menuitem == "param") _paramsInWifi = false; // param auto flag _menuIds.push_back(j); } diff --git a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino index af2276dea..13391794c 100644 --- a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -122,7 +122,7 @@ void setup() { // WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL); // wifi_sort_method_t sortMethod - WIFI_CONNECT_AP_BY_SIGNAL,WIFI_CONNECT_AP_BY_SECURITY // WiFi.setMinSecurity(WIFI_AUTH_WPA2_PSK); - wm.setDebugOutput(true, DEBUG_DEV); + wm.setDebugOutput(true, WM_DEBUG_DEV); wm.debugPlatformInfo(); //reset settings - for testing From 7d957277610fa585735a2295e2d63fe68b332d26 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Fri, 3 Nov 2023 22:17:20 -0500 Subject: [PATCH 25/31] add button funcs tests to super --- .../OnDemandConfigPortal/OnDemandConfigPortal.ino | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino index 13391794c..b9b767153 100644 --- a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -218,7 +218,7 @@ void setup() { */ std::vector menu = {"wifi","wifinoscan","info","param","custom","close","sep","erase","update","restart","exit"}; - wm.setMenu(menu); // custom menu, pass vector + // wm.setMenu(menu); // custom menu, pass vector // wm.setParamsPage(true); // move params to seperate page, not wifi, do not combine with setmenu! @@ -239,7 +239,7 @@ void setup() { // set Hostname - wm.setHostname(("WM_"+wm.getDefaultAPName()).c_str()); + // wm.setHostname(("WM_"+wm.getDefaultAPName()).c_str()); // wm.setHostname("WM_RANDO_1234"); // set custom channel @@ -260,7 +260,7 @@ void setup() { //sets timeout until configuration portal gets turned off //useful to make it all retry or go to sleep in seconds - wm.setConfigPortalTimeout(120); + wm.setConfigPortalTimeout(TESP_CP_TIMEOUT); // set min quality to show in web list, default 8% // wm.setMinimumSignalQuality(50); @@ -340,13 +340,14 @@ void loop() { wm.process(); } + #ifdef USEOTA ArduinoOTA.handle(); #endif // is configuration portal requested? if (ALLOWONDEMAND && digitalRead(ONDDEMANDPIN) == LOW ) { delay(100); - if ( digitalRead(ONDDEMANDPIN) == LOW ){ + if ( digitalRead(ONDDEMANDPIN) == LOW || BUTTONFUNC == 2){ Serial.println("BUTTON PRESSED"); // button reset/reboot @@ -363,11 +364,12 @@ void loop() { Serial.println("failed to connect and hit timeout"); delay(3000); } + return; } //test autoconnect as reconnect etc. if(BUTTONFUNC == 2){ - wm.setConfigPortalTimeout(20); + wm.setConfigPortalTimeout(TESP_CP_TIMEOUT); wm.autoConnect(); return; } From 94529cd08b5d956f3ca015bb4b6fd0226ee43143 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Fri, 3 Nov 2023 22:18:26 -0500 Subject: [PATCH 26/31] turn off preload and async scanning Until more qa can be done here , I have reports of these causing issues and first scans being empty on latest IDF and chips --- WiFiManager.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/WiFiManager.h b/WiFiManager.h index 095859fdb..f5c7ae3dc 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -621,9 +621,12 @@ class WiFiManager // // preload scanning causes AP to delay showing for users, but also caches and lets the cp load faster once its open // my scan takes 7-10 seconds - boolean _preloadwifiscan = true; // preload wifiscan if true + public: + boolean _preloadwifiscan = false; // preload wifiscan if true unsigned int _scancachetime = 30000; // ms cache time for preload scans - boolean _asyncScan = true; // perform wifi network scan async + boolean _asyncScan = false; // perform wifi network scan async + + private: boolean _autoforcerescan = false; // automatically force rescan if scan networks is 0, ignoring cache From 680968ff30930823a331ad4dd2014fef0274a9fc Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Sun, 5 Nov 2023 08:34:12 -0600 Subject: [PATCH 27/31] comments --- .../Super/OnDemandConfigPortal/OnDemandConfigPortal.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino index b9b767153..0662a23a5 100644 --- a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -79,16 +79,16 @@ void bindServerCallback(){ // you can override wm route endpoints, I have not found a way to remove handlers, but this would let you disable them or add auth etc. // wm.server->on("/info",handleNotFound); // wm.server->on("/update",handleNotFound); - wm.server->on("/erase",handleNotFound); + wm.server->on("/erase",handleNotFound); // disable erase } void handleRoute(){ - Serial.println("[HTTP] handle route"); + Serial.println("[HTTP] handle custom route"); wm.server->send(200, "text/plain", "hello from user code"); } void handleNotFound(){ - Serial.println("[HTTP] handle route"); + Serial.println("[HTTP] override handle route"); wm.handleNotFound(); } From 0e2016879b66dc3b4f200b1d91fde5ae9a501f37 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Wed, 15 Nov 2023 21:56:07 -0600 Subject: [PATCH 28/31] #1558 fix? Detect password only change --- WiFiManager.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index f4674d8fd..d82875aec 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1814,6 +1814,13 @@ void WiFiManager::handleWifiSave() { _ssid = server->arg(F("s")).c_str(); _pass = server->arg(F("p")).c_str(); + if(_ssid = "" && _pass != ""){ + _ssid = WiFi_SSID(true); // password change, placeholder ssid, @todo compare pass to old?, confirm ssid is clean + #ifdef WM_DEBUG_LEVEL + DEBUG_WM(WM_DEBUG_VERBOSE,F("Detected WiFi password change")); + #endif + } + #ifdef WM_DEBUG_LEVEL String requestinfo = "SERVER_REQUEST\n----------------\n"; requestinfo += "URI: "; From 18145e42ba686f297d4e741fb8805dffcb99a920 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Thu, 16 Nov 2023 21:32:16 -0600 Subject: [PATCH 29/31] update serverloc --- WiFiManager.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index d82875aec..d5ebd3e84 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2421,16 +2421,18 @@ void WiFiManager::handleNotFound() { * Return true in that case so the page handler do not try to handle the request again. */ boolean WiFiManager::captivePortal() { - #ifdef WM_DEBUG_LEVEL - DEBUG_WM(WM_DEBUG_MAX,"-> " + server->hostHeader()); - #endif if(!_enableCaptivePortal) return false; // skip redirections, @todo maybe allow redirection even when no cp ? might be useful String serverLoc = toStringIp(server->client().localIP()); + #ifdef WM_DEBUG_LEVEL + DEBUG_WM(WM_DEBUG_DEV,"-> " + server->hostHeader()); + DEBUG_WM(WM_DEBUG_DEV,"serverLoc " + serverLoc); + #endif + // fallback for ipv6 bug - if(serverLoc = "0.0.0.0"){ + if(serverLoc == "0.0.0.0"){ if ((WiFi.status()) != WL_CONNECTED) serverLoc = toStringIp(WiFi.softAPIP()); else @@ -2443,6 +2445,7 @@ boolean WiFiManager::captivePortal() { if (doredirect) { #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("<- Request redirected to captive portal")); + DEBUG_WM(WM_DEBUG_DEV,"serverLoc " + serverLoc); #endif server->sendHeader(F("Location"), (String)F("http://") + serverLoc, true); // @HTTPHEAD send redirect server->send ( 302, FPSTR(HTTP_HEAD_CT2), ""); // Empty content inhibits Content-length header so we have to close the socket ourselves. From 9df7acdeeb6a7f614cdcba4a3f8c117ab7c23718 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Fri, 17 Nov 2023 12:14:04 -0600 Subject: [PATCH 30/31] doh --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index d5ebd3e84..6bc967089 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1814,7 +1814,7 @@ void WiFiManager::handleWifiSave() { _ssid = server->arg(F("s")).c_str(); _pass = server->arg(F("p")).c_str(); - if(_ssid = "" && _pass != ""){ + if(_ssid == "" && _pass != ""){ _ssid = WiFi_SSID(true); // password change, placeholder ssid, @todo compare pass to old?, confirm ssid is clean #ifdef WM_DEBUG_LEVEL DEBUG_WM(WM_DEBUG_VERBOSE,F("Detected WiFi password change")); From 3efb536629b5750275a64afe92b1a1c0b4a8a7de Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Fri, 17 Nov 2023 19:37:44 -0600 Subject: [PATCH 31/31] disable captiveportal for webportal --- WiFiManager.cpp | 2 +- WiFiManager.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 6bc967089..efeb83e5c 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2422,7 +2422,7 @@ void WiFiManager::handleNotFound() { */ boolean WiFiManager::captivePortal() { - if(!_enableCaptivePortal) return false; // skip redirections, @todo maybe allow redirection even when no cp ? might be useful + if(!_enableCaptivePortal || !configPortalActive) return false; // skip redirections if cp not enabled or not in ap mode String serverLoc = toStringIp(server->client().localIP()); diff --git a/WiFiManager.h b/WiFiManager.h index f5c7ae3dc..c4c8be55d 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -767,8 +767,15 @@ class WiFiManager boolean abort = false; boolean reset = false; boolean configPortalActive = false; + + + // these are state flags for portal mode, we are either in webportal mode(STA) or configportal mode(AP) + // these are mutually exclusive as STA+AP mode is not supported due to channel restrictions and stability + // if we decide to support this, these checks will need to be replaced with something client aware to check if client origin is ap or web + // These state checks are critical and used for internal function checks boolean webPortalActive = false; boolean portalTimeoutResult = false; + boolean portalAbortResult = false; boolean storeSTAmode = true; // option store persistent STA mode in connectwifi int timer = 0; // timer for debug throttle for numclients, and portal timeout messages