From 83c271fed49bdbd7fd8846908c699ff15872fcb7 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 25 Mar 2016 08:19:47 -0500 Subject: [PATCH 001/424] initial commit, signal meter and secure icons Adds sprite based icons, added some accessibility support since this uses background images. Can use classes `left` or `right` on parent div to align on either side of SSID, parent div `invert` css filters the icons to white. base64 image string has been formatted for easy replacement --- WiFiManager.cpp | 2 ++ WiFiManager.h | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 47414ca..4f234d4 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -444,6 +444,8 @@ void WiFiManager::handleWifi(boolean scan) { rssiQ += quality; item.replace("{v}", WiFi.SSID(indices[i])); item.replace("{r}", rssiQ); + Serial.print(map(quality,0,100,1,4)); + item.replace("{q}", (String)round(map(quality,0,100,1,4))); if (WiFi.encryptionType(indices[i]) != ENC_TYPE_NONE) { item.replace("{i}", "l"); } else { diff --git a/WiFiManager.h b/WiFiManager.h index 9f5bc41..5aeba9e 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -26,11 +26,14 @@ extern "C" { const char HTTP_200[] PROGMEM = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"; const char HTTP_HEAD[] PROGMEM = "{v}"; -const char HTTP_STYLE[] PROGMEM = ""; +// const char HTTP_STYLE[] PROGMEM = ""; +const char HTTP_STYLE[] PROGMEM = ""; const char HTTP_SCRIPT[] PROGMEM = ""; -const char HTTP_HEAD_END[] PROGMEM = "
"; +const char HTTP_HEAD_END[] PROGMEM = "
"; const char HTTP_PORTAL_OPTIONS[] PROGMEM = "



"; -const char HTTP_ITEM[] PROGMEM = "
{v} {r}%
"; +const char HTTP_ITEM[] PROGMEM = "
{v}({r})
"; //const char HTTP_ITEM_PADLOCK[] PROGMEM = ""; const char HTTP_FORM_START[] PROGMEM = "


"; const char HTTP_FORM_PARAM[] PROGMEM = "
"; From 6708ddf37bc51a40fa86509486f9f4ae82a63867 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 25 Mar 2016 08:48:49 -0500 Subject: [PATCH 002/424] remove debug --- WiFiManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 4f234d4..30c1c48 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -444,7 +444,6 @@ void WiFiManager::handleWifi(boolean scan) { rssiQ += quality; item.replace("{v}", WiFi.SSID(indices[i])); item.replace("{r}", rssiQ); - Serial.print(map(quality,0,100,1,4)); item.replace("{q}", (String)round(map(quality,0,100,1,4))); if (WiFi.encryptionType(indices[i]) != ENC_TYPE_NONE) { item.replace("{i}", "l"); From fd27cef1aeb11fce552f791794dfb41dff1de3b1 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 25 Mar 2016 09:31:07 -0500 Subject: [PATCH 003/424] remove debug --- WiFiManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.h b/WiFiManager.h index 5aeba9e..6e6acfd 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -33,7 +33,7 @@ const char HTTP_STYLE[] PROGMEM = ""; -const char HTTP_STYLE[] PROGMEM = ""; +const char HTTP_STYLE[] PROGMEM = ""; const char HTTP_SCRIPT[] PROGMEM = ""; const char HTTP_HEAD_END[] PROGMEM = "
"; const char HTTP_PORTAL_OPTIONS[] PROGMEM = "


"; diff --git a/extras/png_signal_strength_master.png b/extras/png_signal_strength_master.png new file mode 100644 index 0000000000000000000000000000000000000000..f03c947f155f0552ce691a06424239ef80252812 GIT binary patch literal 59671 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 F{{Tv)bCCc5 literal 0 HcmV?d00001 diff --git a/extras/test.html b/extras/test.html new file mode 100644 index 0000000..58c913c --- /dev/null +++ b/extras/test.html @@ -0,0 +1,176 @@ + + + + + + Config ESP + + + + + + + + + + + + From abedb61ca1e11ee5a3ca50777fda6a1b943dbc38 Mon Sep 17 00:00:00 2001 From: Alex T Date: Sat, 15 Oct 2016 12:07:48 +0300 Subject: [PATCH 005/424] parameter label --- WiFiManager.cpp | 32 +++++++++++++++++++++++++------- WiFiManager.h | 9 +++++++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 93bf578..61e0e49 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -17,22 +17,23 @@ WiFiManagerParameter::WiFiManagerParameter(const char *custom) { _placeholder = NULL; _length = 0; _value = NULL; - + _labelPlacement = WFM_LABEL_BEFORE; _customHTML = custom; } WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length) { - init(id, placeholder, defaultValue, length, ""); + init(id, placeholder, defaultValue, length, "", WFM_LABEL_BEFORE); } WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) { - init(id, placeholder, defaultValue, length, custom); + init(id, placeholder, defaultValue, length, custom, WFM_LABEL_BEFORE); } -void WiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) { +void WiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) { _id = id; _placeholder = placeholder; _length = length; + _labelPlacement = labelPlacement; _value = new char[length + 1]; for (int i = 0; i < length; i++) { _value[i] = 0; @@ -56,6 +57,9 @@ const char* WiFiManagerParameter::getPlaceholder() { int WiFiManagerParameter::getValueLength() { return _length; } +int WiFiManagerParameter::getLabelPlacement() { + return _labelPlacement; +} const char* WiFiManagerParameter::getCustomHTML() { return _customHTML; } @@ -115,8 +119,7 @@ void WiFiManager::setupConfigPortal() { server->on("/wifisave", std::bind(&WiFiManager::handleWifiSave, this)); server->on("/i", std::bind(&WiFiManager::handleInfo, this)); server->on("/r", std::bind(&WiFiManager::handleReset, this)); - //server->on("/generate_204", std::bind(&WiFiManager::handle204, this)); //Android/Chrome OS captive portal check. - server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler. + //server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler. server->onNotFound (std::bind(&WiFiManager::handleNotFound, this)); server->begin(); // Web server start DEBUG_WM(F("HTTP server started")); @@ -471,7 +474,22 @@ void WiFiManager::handleWifi(boolean scan) { break; } - String pitem = FPSTR(HTTP_FORM_PARAM); + //String pitem = FPSTR(HTTP_FORM_PARAM); + String pitem; + switch (_params[i]->getLabelPlacement()) { + case WFM_LABEL_BEFORE: + pitem = FPSTR(HTTP_FORM_LABEL); + pitem += FPSTR(HTTP_FORM_PARAM); + break; + case WFM_LABEL_AFTER: + pitem = FPSTR(HTTP_FORM_PARAM); + pitem += FPSTR(HTTP_FORM_LABEL); + break; + default: + // WFM_NO_LABEL + pitem = FPSTR(HTTP_FORM_PARAM); + break; + } if (_params[i]->getID() != NULL) { pitem.replace("{i}", _params[i]->getID()); pitem.replace("{n}", _params[i]->getID()); diff --git a/WiFiManager.h b/WiFiManager.h index bd67c05..7c2c835 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -29,6 +29,7 @@ const char HTTP_HEAD_END[] PROGMEM = "
{v} {r}%
"; const char HTTP_FORM_START[] PROGMEM = "


"; +const char HTTP_FORM_LABEL[] PROGMEM = ""; const char HTTP_FORM_PARAM[] PROGMEM = "
"; const char HTTP_FORM_END[] PROGMEM = "
"; const char HTTP_SCAN_LINK[] PROGMEM = "
"; @@ -37,25 +38,33 @@ const char HTTP_END[] PROGMEM = "
"; #define WIFI_MANAGER_MAX_PARAMS 10 +#define WFM_LABEL_BEFORE 1 +#define WFM_LABEL_AFTER 2 +#define WFM_NO_LABEL 0 + class WiFiManagerParameter { public: WiFiManagerParameter(const char *custom); WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length); WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom); + WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement); const char *getID(); const char *getValue(); const char *getPlaceholder(); int getValueLength(); + int getLabelPlacement(); const char *getCustomHTML(); private: const char *_id; const char *_placeholder; char *_value; int _length; + int _labelPlacement; const char *_customHTML; void init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom); + void init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement); friend class WiFiManager; }; From 5f8f1ce5e614f81880cb3fb59376dccc09dfd868 Mon Sep 17 00:00:00 2001 From: Ayoma Wijethunga Date: Sat, 26 Nov 2016 20:17:41 +0530 Subject: [PATCH 006/424] Adding WiFiManagerParameter implementation with labelPlacement parameter --- WiFiManager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 61e0e49..be6d75c 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -29,6 +29,10 @@ WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placehold init(id, placeholder, defaultValue, length, custom, WFM_LABEL_BEFORE); } +WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) { + init(id, placeholder, defaultValue, length, custom, labelPlacement); +} + void WiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) { _id = id; _placeholder = placeholder; From 9c72bf98f778d38d6da1b4729ad5318318ba86e4 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 9 Feb 2017 16:33:10 -0600 Subject: [PATCH 007/424] cleaning up source, comments --- WiFiManager.cpp | 148 ++++++++++++++++++++++++++++++++---------------- WiFiManager.h | 3 +- 2 files changed, 100 insertions(+), 51 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index c9fa5aa..1f9abe8 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -12,6 +12,8 @@ #include "WiFiManager.h" +// PARAMETERS + WiFiManagerParameter::WiFiManagerParameter(const char *custom) { _id = NULL; _placeholder = NULL; @@ -64,9 +66,6 @@ const char* WiFiManagerParameter::getCustomHTML() { return _customHTML; } -WiFiManager::WiFiManager() { -} - void WiFiManager::addParameter(WiFiManagerParameter *p) { if(_paramsCount + 1 > WIFI_MANAGER_MAX_PARAMS) { @@ -82,7 +81,11 @@ void WiFiManager::addParameter(WiFiManagerParameter *p) { DEBUG_WM(p->getID()); } +WiFiManager::WiFiManager() { +} + void WiFiManager::setupConfigPortal() { + // setup dns and web servers dnsServer.reset(new DNSServer()); server.reset(new ESP8266WebServer(80)); @@ -91,28 +94,21 @@ void WiFiManager::setupConfigPortal() { DEBUG_WM(F("Configuring access point... ")); DEBUG_WM(_apName); - if (_apPassword != NULL) { - if (strlen(_apPassword) < 8 || strlen(_apPassword) > 63) { - // fail passphrase to short or long! - DEBUG_WM(F("Invalid AccessPoint password. Ignoring")); - _apPassword = NULL; - } - DEBUG_WM(_apPassword); - } - //optional soft ip config + // setup optional soft AP static ip config if (_ap_static_ip) { DEBUG_WM(F("Custom AP IP/GW/Subnet")); WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn); } + // start soft AP with pass or anonymous if (_apPassword != NULL) { WiFi.softAP(_apName, _apPassword);//password option } else { WiFi.softAP(_apName); } - delay(500); // Without delay I've seen the IP address blank + delay(500); // slight delay to make sure we have a password DEBUG_WM(F("AP IP address: ")); DEBUG_WM(WiFi.softAPIP()); @@ -120,7 +116,7 @@ void WiFiManager::setupConfigPortal() { dnsServer->setErrorReplyCode(DNSReplyCode::NoError); dnsServer->start(DNS_PORT, "*", WiFi.softAPIP()); - /* Setup web pages: root, wifi config pages, SO captive portal detectors and not found. */ + /* Setup httpd callbacks, web pages: root, wifi config pages, SO captive portal detectors and not found. */ server->on("/", std::bind(&WiFiManager::handleRoot, this)); server->on("/wifi", std::bind(&WiFiManager::handleWifi, this, true)); server->on("/0wifi", std::bind(&WiFiManager::handleWifi, this, false)); @@ -129,9 +125,9 @@ void WiFiManager::setupConfigPortal() { server->on("/r", std::bind(&WiFiManager::handleReset, this)); //server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler. server->onNotFound (std::bind(&WiFiManager::handleNotFound, this)); + server->begin(); // Web server start DEBUG_WM(F("HTTP server started")); - } boolean WiFiManager::autoConnect() { @@ -143,17 +139,17 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { DEBUG_WM(F("")); DEBUG_WM(F("AutoConnect")); - // read eeprom for ssid and pass + // read eeprom for ssid and pass, deprecated //String ssid = getSSID(); //String pass = getPassword(); - // attempt to connect; should it fail, fall back to AP + // attempt to connect using saved settings, on fail fallback to AP config portal WiFi.mode(WIFI_STA); if (connectWifi("", "") == WL_CONNECTED) { + //connected DEBUG_WM(F("IP Address:")); DEBUG_WM(WiFi.localIP()); - //connected return true; } @@ -178,34 +174,38 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo WiFi.mode(WIFI_AP_STA); DEBUG_WM("SET AP STA"); - _apName = apName; + _apName = apName; _apPassword = apPassword; + if(!validApPassword) return; - //notify we entered AP mode + // do AP callback if set if ( _apcallback != NULL) { _apcallback(this); } connect = false; + + // init configportal setupConfigPortal(); + // blocking loop waiting for config while(1){ - // check if timeout + // check if timed out if(configPortalHasTimeout()) break; - //DNS + //DNS handler dnsServer->processNextRequest(); - //HTTP + //HTTP handler server->handleClient(); - + // Waiting for save... if (connect) { connect = false; delay(2000); DEBUG_WM(F("Connecting to new AP")); - // using user-provided _ssid, _pass in place of system-stored ssid and pass + // attempt sta connection to submitted _ssid, _pass if (connectWifi(_ssid, _pass) != WL_CONNECTED) { DEBUG_WM(F("Failed to connect.")); } else { @@ -238,28 +238,32 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo return WiFi.status() == WL_CONNECTED; } - int WiFiManager::connectWifi(String ssid, String pass) { DEBUG_WM(F("Connecting as wifi client...")); - // check if we've got static_ip settings, if we do, use those. + // Setup static IP config if provided if (_sta_static_ip) { DEBUG_WM(F("Custom STA IP/GW/Subnet")); WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn); DEBUG_WM(WiFi.localIP()); } - //fix for auto connect racing issue + + // fix for auto connect racing issue + // @todo why is this here, what issue?, should be making sure its actually ssid == ssid should it not? if (WiFi.status() == WL_CONNECTED) { - DEBUG_WM("Already connected. Bailing out."); + DEBUG_WM("Already connected. Exiting"); return WL_CONNECTED; } - //check if we have ssid and pass and force those, if not, try with last saved values + + // if ssid argument provided connect to that if (ssid != "") { + DEBUG_WM("Connecting to new AP"); WiFi.begin(ssid.c_str(), pass.c_str()); } else { + // connect using saved ssid if there is one if (WiFi.SSID()) { - DEBUG_WM("Using last saved values, should be faster"); - //trying to fix connection in progress hanging + DEBUG_WM("Connecting to saved AP"); + // trying to fix connection in progress hanging, explain why ?? ETS_UART_INTR_DISABLE(); wifi_station_disconnect(); ETS_UART_INTR_ENABLE(); @@ -273,12 +277,15 @@ int WiFiManager::connectWifi(String ssid, String pass) { int connRes = waitForConnectResult(); DEBUG_WM ("Connection result: "); DEBUG_WM ( connRes ); - //not connected, WPS enabled, no pass - first attempt + + // do WPS, if WPS options enabled and not connected and no password was supplied + // @todo this seems like wrong place for this, is it a fallback or option? if (_tryWPS && connRes != WL_CONNECTED && pass == "") { startWPS(); - //should be connected at the end of WPS + // should be connected at the end of WPS connRes = waitForConnectResult(); } + return connRes; } @@ -331,16 +338,20 @@ void WiFiManager::startWPS() { return _pass; } */ + +// GETTERS String WiFiManager::getConfigPortalSSID() { return _apName; } +// SETTERS void WiFiManager::resetSettings() { - DEBUG_WM(F("settings invalidated")); - DEBUG_WM(F("THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA.")); + DEBUG_WM(F("SETTINGS ERASED")); + DEBUG_WM(F("THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA.")); // @todo WHUT? WiFi.disconnect(true); //delay(200); } + void WiFiManager::setTimeout(unsigned long seconds) { setConfigPortalTimeout(seconds); } @@ -377,10 +388,14 @@ void WiFiManager::setBreakAfterConfig(boolean shouldBreak) { _shouldBreakAfterConfig = shouldBreak; } -/** Handle root or redirect to captive portal */ + + +/** + * HTTPD CALLBACK root or redirect to captive portal + */ void WiFiManager::handleRoot() { DEBUG_WM(F("Handle root")); - if (captivePortal()) { // If caprive portal redirect instead of displaying the page. + if (captivePortal()) { // If captive portal redirect instead of displaying the page. return; } @@ -401,7 +416,9 @@ void WiFiManager::handleRoot() { } -/** Wifi config page handler */ +/** + * HTTPD CALLBACK Wifi config page handler + */ void WiFiManager::handleWifi(boolean scan) { String page = FPSTR(HTTP_HEAD); @@ -571,7 +588,9 @@ void WiFiManager::handleWifi(boolean scan) { DEBUG_WM(F("Sent config page")); } -/** Handle the WLAN save form and redirect to WLAN config page again */ +/** + * HTTPD CALLBACK save form and redirect to WLAN config page again + */ void WiFiManager::handleWifiSave() { DEBUG_WM(F("WiFi save")); @@ -629,7 +648,9 @@ void WiFiManager::handleWifiSave() { connect = true; //signal ready to connect/reset } -/** Handle the info page */ +/** + * HTTPD CALLBACK info page + */ void WiFiManager::handleInfo() { DEBUG_WM(F("Info")); @@ -669,7 +690,9 @@ void WiFiManager::handleInfo() { DEBUG_WM(F("Sent info page")); } -/** Handle the reset page */ +/** + * HTTPD CALLBACK reset page + */ void WiFiManager::handleReset() { DEBUG_WM(F("Reset")); @@ -689,17 +712,23 @@ void WiFiManager::handleReset() { delay(2000); } - - -//removed as mentioned here https://github.com/tzapu/WiFiManager/issues/114 -/*void WiFiManager::handle204() { +/** + * HTTPD CALLBACK 204 + * @note removed as mentioned here https://github.com/tzapu/WiFiManager/issues/114 + */ +/* +void WiFiManager::handle204() { DEBUG_WM(F("204 No Response")); server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); server->sendHeader("Pragma", "no-cache"); server->sendHeader("Expires", "-1"); server->send ( 204, "text/plain", ""); -}*/ +} +*/ +/** + * HTTPD CALLBACK 404 + */ void WiFiManager::handleNotFound() { if (captivePortal()) { // If captive portal redirect instead of displaying the error page. return; @@ -722,8 +751,11 @@ void WiFiManager::handleNotFound() { server->send ( 404, "text/plain", message ); } - -/** Redirect to captive portal if we got a request for another domain. Return true in that case so the page handler do not try to handle the request again. */ +/** + * HTTPD redirector + * Redirect to captive portal if we got a request for another domain. + * Return true in that case so the page handler do not try to handle the request again. + */ boolean WiFiManager::captivePortal() { if (!isIp(server->hostHeader()) ) { DEBUG_WM(F("Request redirected to captive portal")); @@ -735,6 +767,8 @@ boolean WiFiManager::captivePortal() { return false; } +// MORE SETTERS + //start up config portal callback void WiFiManager::setAPCallback( void (*func)(WiFiManager* myWiFiManager) ) { _apcallback = func; @@ -755,7 +789,7 @@ void WiFiManager::setRemoveDuplicateAPs(boolean removeDuplicates) { _removeDuplicateAPs = removeDuplicates; } - +// HELPERS template void WiFiManager::DEBUG_WM(Generic text) { @@ -798,3 +832,17 @@ String WiFiManager::toStringIp(IPAddress ip) { res += String(((ip >> 8 * 3)) & 0xFF); return res; } + +bool WiFiManager::validApPassword(){ + // check that ap password is valid, return false + if (_apPassword != NULL) { + if (strlen(_apPassword) < 8 || strlen(_apPassword) > 63) { + DEBUG_WM(F("AccessPoint password is INVALID")); + _apPassword = NULL; + return false; // @todo FATAL or fallback to NULL ? + } + DEBUG_WM(F("AccessPoint Password is VALID")); + DEBUG_WM(_apPassword); + } + return true; +} diff --git a/WiFiManager.h b/WiFiManager.h index 13dc620..86a215d 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -170,7 +170,8 @@ class WiFiManager void handle204(); boolean captivePortal(); boolean configPortalHasTimeout(); - + boolean validApPassword(); + // DNS server const byte DNS_PORT = 53; From 45a325bd3440cfb55f620a985098ab695d3ecb46 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 9 Feb 2017 16:57:34 -0600 Subject: [PATCH 008/424] fix validippassword abstracted ap password validation passing a invalid password should be fatal , not fallback to null, but could be an optional define --- WiFiManager.cpp | 4 ++-- WiFiManager.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 1f9abe8..35f9b43 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -176,7 +176,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo _apName = apName; _apPassword = apPassword; - if(!validApPassword) return; + if(!validApPassword()) return false; // do AP callback if set if ( _apcallback != NULL) { @@ -833,7 +833,7 @@ String WiFiManager::toStringIp(IPAddress ip) { return res; } -bool WiFiManager::validApPassword(){ +boolean WiFiManager::validApPassword(){ // check that ap password is valid, return false if (_apPassword != NULL) { if (strlen(_apPassword) < 8 || strlen(_apPassword) > 63) { diff --git a/WiFiManager.h b/WiFiManager.h index 86a215d..0fccf97 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -170,7 +170,6 @@ class WiFiManager void handle204(); boolean captivePortal(); boolean configPortalHasTimeout(); - boolean validApPassword(); // DNS server const byte DNS_PORT = 53; @@ -179,6 +178,7 @@ class WiFiManager int getRSSIasQuality(int RSSI); boolean isIp(String str); String toStringIp(IPAddress ip); + boolean validApPassword(); boolean connect; boolean _debug = true; From 2edd37eeb83dbce93be9d7aecb5308db190e17df Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 9 Feb 2017 17:02:33 -0600 Subject: [PATCH 009/424] oops typo --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 35f9b43..23af06a 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -108,7 +108,7 @@ void WiFiManager::setupConfigPortal() { WiFi.softAP(_apName); } - delay(500); // slight delay to make sure we have a password + delay(500); // slight delay to make sure we have an AP IP DEBUG_WM(F("AP IP address: ")); DEBUG_WM(WiFi.softAPIP()); From c819d469022a42f0ac26f368eaa9faf131e26c72 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 9 Feb 2017 17:10:15 -0600 Subject: [PATCH 010/424] allow for empty password --- WiFiManager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 23af06a..dd9b964 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -835,6 +835,7 @@ String WiFiManager::toStringIp(IPAddress ip) { boolean WiFiManager::validApPassword(){ // check that ap password is valid, return false + if (_apPassword == "") _apPassword = NULL; if (_apPassword != NULL) { if (strlen(_apPassword) < 8 || strlen(_apPassword) > 63) { DEBUG_WM(F("AccessPoint password is INVALID")); From bd9c3b31fb60a1860cd29d7c3bd18cb8c39eb679 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 10 Feb 2017 14:07:52 -0600 Subject: [PATCH 011/424] refactoring some larger functions * broke large functions into smaller , to allow new features to be hooked in easier * added persistent test to constructor destructor * testing turn off sta during portal , causes issues --- WiFiManager.cpp | 153 +++++++++++++++++++++++++++++------------------- WiFiManager.h | 7 ++- 2 files changed, 98 insertions(+), 62 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index dd9b964..44897b8 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -81,18 +81,18 @@ void WiFiManager::addParameter(WiFiManagerParameter *p) { DEBUG_WM(p->getID()); } -WiFiManager::WiFiManager() { +// constructor +WiFiManager::WiFiManager() { + WiFi.persistent(false); } -void WiFiManager::setupConfigPortal() { - // setup dns and web servers - dnsServer.reset(new DNSServer()); - server.reset(new ESP8266WebServer(80)); +// destructor +WiFiManager::~WiFiManager() { + WiFi.persistent(true); // @todo restore original +} - DEBUG_WM(F("")); - _configPortalStart = millis(); - - DEBUG_WM(F("Configuring access point... ")); +bool WiFiManager::startAP(){ + DEBUG_WM(F("Configuring access point with with SSID ... ")); DEBUG_WM(_apName); // setup optional soft AP static ip config @@ -101,16 +101,31 @@ void WiFiManager::setupConfigPortal() { WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn); } + bool ret = true; + // start soft AP with pass or anonymous if (_apPassword != NULL) { - WiFi.softAP(_apName, _apPassword);//password option + ret = WiFi.softAP(_apName, _apPassword);//password option } else { - WiFi.softAP(_apName); + DEBUG_WM(F("AP has anonymous access")); + ret = WiFi.softAP(_apName); } delay(500); // slight delay to make sure we have an AP IP DEBUG_WM(F("AP IP address: ")); DEBUG_WM(WiFi.softAPIP()); + return ret; +} + +void WiFiManager::setupConfigPortal() { + // setup dns and web servers + dnsServer.reset(new DNSServer()); + server.reset(new ESP8266WebServer(80)); + + DEBUG_WM(F("setupConfigPortal")); + _configPortalStart = millis(); + + if(!startAP()) DEBUG_WM("There was an error stating the AP"); /* Setup the DNS server redirecting all the domains to the apIP */ dnsServer->setErrorReplyCode(DNSReplyCode::NoError); @@ -144,9 +159,9 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { //String pass = getPassword(); // attempt to connect using saved settings, on fail fallback to AP config portal - WiFi.mode(WIFI_STA); + // WiFi.mode(WIFI_STA); // why, should not be needed - if (connectWifi("", "") == WL_CONNECTED) { + if (WiFi.status() == WL_CONNECTED || connectWifi("", "") == WL_CONNECTED) { //connected DEBUG_WM(F("IP Address:")); DEBUG_WM(WiFi.localIP()); @@ -171,7 +186,9 @@ boolean WiFiManager::startConfigPortal() { boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) { //setup AP - WiFi.mode(WIFI_AP_STA); + // @todo AP_STA will constantly try to connect to old aps in background, if not allowing background configportal , maybe turn off STA + WiFi.mode(WIFI_AP); + // WiFi.mode(WIFI_AP_STA); DEBUG_WM("SET AP STA"); _apName = apName; @@ -183,17 +200,25 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo _apcallback(this); } - connect = false; + connect = false; // global // init configportal setupConfigPortal(); + uint8_t ret; // blocking loop waiting for config while(1){ - // check if timed out - if(configPortalHasTimeout()) break; + if(configPortalHasTimeout()) return stopConfigPortal(); + ret = handleConfigPortal(); + if(ret == WL_CONNECTED) return true; + yield(); + } + return false; +} +//@todo need enums for return, using 3 esp enums for now +uint8_t WiFiManager::handleConfigPortal(){ //DNS handler dnsServer->processNextRequest(); //HTTP handler @@ -206,38 +231,44 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo DEBUG_WM(F("Connecting to new AP")); // attempt sta connection to submitted _ssid, _pass - if (connectWifi(_ssid, _pass) != WL_CONNECTED) { - DEBUG_WM(F("Failed to connect.")); - } else { - //connected - WiFi.mode(WIFI_STA); - //notify that configuration has changed and any optional parameters should be saved - if ( _savecallback != NULL) { - //todo: check if any custom parameters actually exist, and check if they really changed maybe - _savecallback(); - } - break; + if (connectWifi(_ssid, _pass) == WL_CONNECTED) { + DEBUG_WM(F("Connect to new AP SUCCESS")); + stopConfigPortal(); + return WL_CONNECTED; // success } + DEBUG_WM(F("Failed to connect.")); + if (_shouldBreakAfterConfig) { - //flag set to exit after config after trying to connect - //notify that configuration has changed and any optional parameters should be saved - if ( _savecallback != NULL) { - //todo: check if any custom parameters actually exist, and check if they really changed maybe - _savecallback(); - } - break; + // this is more of an exiting callback than a save + stopConfigPortal(); // fail + return WL_CONNECT_FAILED; } } - yield(); + + return WL_IDLE_STATUS; +} + +boolean WiFiManager::stopConfigPortal(){ + // do save callback + if ( _savecallback != NULL) { + //todo: confirm or verify data was saved + _savecallback(); } + // @todo does this unload them enough ? server.reset(); dnsServer.reset(); - return WiFi.status() == WL_CONNECTED; + // turn off AP + DEBUG_WM(F("disconnect configportal")); + WiFi.softAPdisconnect(); + return false; } +// @todo refactor this up into seperate functions +// one for connecting to flash , one for new client +// clean up, flow is convoluted, and causes bugs int WiFiManager::connectWifi(String ssid, String pass) { DEBUG_WM(F("Connecting as wifi client...")); @@ -249,16 +280,18 @@ int WiFiManager::connectWifi(String ssid, String pass) { } // fix for auto connect racing issue - // @todo why is this here, what issue?, should be making sure its actually ssid == ssid should it not? - if (WiFi.status() == WL_CONNECTED) { + // @todo this had to be fixed, it will not let you set a new wifi, if still connected to another, as it just returns + if (WiFi.status() == WL_CONNECTED && (ssid=="" || WiFi.SSID() == ssid)) { DEBUG_WM("Already connected. Exiting"); return WL_CONNECTED; } // if ssid argument provided connect to that if (ssid != "") { - DEBUG_WM("Connecting to new AP"); + DEBUG_WM("Connecting to new AP"); + WiFi.persistent(true); WiFi.begin(ssid.c_str(), pass.c_str()); + WiFi.persistent(false); } else { // connect using saved ssid if there is one if (WiFi.SSID()) { @@ -273,7 +306,6 @@ int WiFiManager::connectWifi(String ssid, String pass) { DEBUG_WM("No saved credentials"); } } - int connRes = waitForConnectResult(); DEBUG_WM ("Connection result: "); DEBUG_WM ( connRes ); @@ -289,27 +321,28 @@ int WiFiManager::connectWifi(String ssid, String pass) { return connRes; } +// @todo uses _connectTimeout for wifi save also, add timeout argument to bypass? + +uint8_t WiFiManager::waitForConnectResult(uint16_t timeout) { + return waitForConnectResult(timeout * 1000); +} + uint8_t WiFiManager::waitForConnectResult() { - if (_connectTimeout == 0) { - return WiFi.waitForConnectResult(); - } else { - DEBUG_WM (F("Waiting for connection result with time out")); - unsigned long start = millis(); - boolean keepConnecting = true; - uint8_t status; - while (keepConnecting) { - status = WiFi.status(); - if (millis() > start + _connectTimeout) { - keepConnecting = false; - DEBUG_WM (F("Connection timed out")); - } - if (status == WL_CONNECTED || status == WL_CONNECT_FAILED) { - keepConnecting = false; - } - delay(100); + if (_connectTimeout == 0) return WiFi.waitForConnectResult(); + + DEBUG_WM (F("connectTimeout set, waiting for connect....")); + uint8_t status; + int timeout = millis() + _connectTimeout; + + while(millis() < timeout) { + status = WiFi.status(); + if (status == WL_CONNECTED || status == WL_CONNECT_FAILED) { + return status; } - return status; + DEBUG_WM ("."); + delay(100); } + return status; } void WiFiManager::startWPS() { @@ -388,8 +421,6 @@ void WiFiManager::setBreakAfterConfig(boolean shouldBreak) { _shouldBreakAfterConfig = shouldBreak; } - - /** * HTTPD CALLBACK root or redirect to captive portal */ diff --git a/WiFiManager.h b/WiFiManager.h index 0fccf97..40efb9b 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -74,6 +74,7 @@ class WiFiManager { public: WiFiManager(); + ~WiFiManager(); boolean autoConnect(); boolean autoConnect(char const *apName, char const *apPassword = NULL); @@ -130,6 +131,7 @@ class WiFiManager void setupConfigPortal(); void startWPS(); + bool startAP(); const char* _apName = "no-net"; const char* _apPassword = NULL; @@ -160,6 +162,7 @@ class WiFiManager int status = WL_IDLE_STATUS; int connectWifi(String ssid, String pass); uint8_t waitForConnectResult(); + uint8_t waitForConnectResult(uint16_t timeout); void handleRoot(); void handleWifi(boolean scan); @@ -170,7 +173,9 @@ class WiFiManager void handle204(); boolean captivePortal(); boolean configPortalHasTimeout(); - + boolean stopConfigPortal(); + uint8_t handleConfigPortal(); + // DNS server const byte DNS_PORT = 53; From e9b36f90845e6f09999310dde5b1e93fd01a5f12 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 10 Feb 2017 15:05:45 -0600 Subject: [PATCH 012/424] fix breakafterconfig --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 44897b8..7089b4a 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -211,7 +211,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // check if timed out if(configPortalHasTimeout()) return stopConfigPortal(); ret = handleConfigPortal(); - if(ret == WL_CONNECTED) return true; + if(ret == WL_CONNECTED || ret == WL_CONNECT_FAILED) return ret; yield(); } return false; From 65349cb54629c6431366ecc9066cd58cab614e93 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 10 Feb 2017 15:13:48 -0600 Subject: [PATCH 013/424] fix WL_IDLE_STATUS return values for compatibility This might need better handling in future, since we only get back a bool of wether or not we are connected, not if configportal was saved etc. might be a problem. --- WiFiManager.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 7089b4a..ec2c806 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -209,9 +209,12 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // blocking loop waiting for config while(1){ // check if timed out - if(configPortalHasTimeout()) return stopConfigPortal(); + if(configPortalHasTimeout()){ + stopConfigPortal(); + return WiFi.status() == WL_CONNECTED; //returns connected bool, ok I guess + } ret = handleConfigPortal(); - if(ret == WL_CONNECTED || ret == WL_CONNECT_FAILED) return ret; + if(ret != WL_IDLE_STATUS) return ret == WL_CONNECTED; yield(); } return false; From 1a44dd53e63b94b94f0b6be9e9a94639d0969754 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 10 Feb 2017 15:21:48 -0600 Subject: [PATCH 014/424] move apcallback to proper location This was actually being called before the ap was setup! --- WiFiManager.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index ec2c806..cf6d397 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -114,6 +114,12 @@ bool WiFiManager::startAP(){ delay(500); // slight delay to make sure we have an AP IP DEBUG_WM(F("AP IP address: ")); DEBUG_WM(WiFi.softAPIP()); + + // do AP callback if set + if ( _apcallback != NULL) { + _apcallback(this); + } + return ret; } @@ -195,11 +201,6 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo _apPassword = apPassword; if(!validApPassword()) return false; - // do AP callback if set - if ( _apcallback != NULL) { - _apcallback(this); - } - connect = false; // global // init configportal From 0b0eb6159c0b604bd9a2e41f75722249617398a4 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 10 Feb 2017 15:29:32 -0600 Subject: [PATCH 015/424] moving blocks --- WiFiManager.cpp | 62 ++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index cf6d397..83b5cfc 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -91,6 +91,34 @@ WiFiManager::~WiFiManager() { WiFi.persistent(true); // @todo restore original } +// AUTOCONNECT +boolean WiFiManager::autoConnect() { + String ssid = "ESP" + String(ESP.getChipId()); + return autoConnect(ssid.c_str(), NULL); +} + +boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { + DEBUG_WM(F("")); + DEBUG_WM(F("AutoConnect")); + + // read eeprom for ssid and pass, deprecated + //String ssid = getSSID(); + //String pass = getPassword(); + + // attempt to connect using saved settings, on fail fallback to AP config portal + // WiFi.mode(WIFI_STA); // why, should not be needed + + if (WiFi.status() == WL_CONNECTED || connectWifi("", "") == WL_CONNECTED) { + //connected + DEBUG_WM(F("IP Address:")); + DEBUG_WM(WiFi.localIP()); + return true; + } + + return startConfigPortal(apName, apPassword); +} + +// CONFIG PORTAL bool WiFiManager::startAP(){ DEBUG_WM(F("Configuring access point with with SSID ... ")); DEBUG_WM(_apName); @@ -151,40 +179,6 @@ void WiFiManager::setupConfigPortal() { DEBUG_WM(F("HTTP server started")); } -boolean WiFiManager::autoConnect() { - String ssid = "ESP" + String(ESP.getChipId()); - return autoConnect(ssid.c_str(), NULL); -} - -boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { - DEBUG_WM(F("")); - DEBUG_WM(F("AutoConnect")); - - // read eeprom for ssid and pass, deprecated - //String ssid = getSSID(); - //String pass = getPassword(); - - // attempt to connect using saved settings, on fail fallback to AP config portal - // WiFi.mode(WIFI_STA); // why, should not be needed - - if (WiFi.status() == WL_CONNECTED || connectWifi("", "") == WL_CONNECTED) { - //connected - DEBUG_WM(F("IP Address:")); - DEBUG_WM(WiFi.localIP()); - return true; - } - - return startConfigPortal(apName, apPassword); -} - -boolean WiFiManager::configPortalHasTimeout(){ - if(_configPortalTimeout == 0 || wifi_softap_get_station_num() > 0){ - _configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts - return false; - } - return (millis() > _configPortalStart + _configPortalTimeout); -} - boolean WiFiManager::startConfigPortal() { String ssid = "ESP" + String(ESP.getChipId()); return startConfigPortal(ssid.c_str(), NULL); From 612e18be35788369ecd44547c33862347f7a4eeb Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 10 Feb 2017 15:40:31 -0600 Subject: [PATCH 016/424] oops deleted a function --- WiFiManager.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 83b5cfc..49f5c16 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -151,6 +151,14 @@ bool WiFiManager::startAP(){ return ret; } +boolean WiFiManager::configPortalHasTimeout(){ + if(_configPortalTimeout == 0 || wifi_softap_get_station_num() > 0){ + _configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts + return false; + } + return (millis() > _configPortalStart + _configPortalTimeout); +} + void WiFiManager::setupConfigPortal() { // setup dns and web servers dnsServer.reset(new DNSServer()); From 004f222f40e1d7f73d336389ebf5e42196ca8ae2 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 10 Feb 2017 17:05:07 -0600 Subject: [PATCH 017/424] do not wait for conx is no ssid --- WiFiManager.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 49f5c16..4327cd8 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -267,8 +267,9 @@ boolean WiFiManager::stopConfigPortal(){ dnsServer.reset(); // turn off AP - DEBUG_WM(F("disconnect configportal")); - WiFi.softAPdisconnect(); + DEBUG_WM(F("disconnect configportal")); + // WiFi.mode(WIFI_STA); + WiFi.softAPdisconnect(false); return false; } @@ -277,6 +278,8 @@ boolean WiFiManager::stopConfigPortal(){ // clean up, flow is convoluted, and causes bugs int WiFiManager::connectWifi(String ssid, String pass) { DEBUG_WM(F("Connecting as wifi client...")); + + bool waitforconx = true; // Setup static IP config if provided if (_sta_static_ip) { @@ -300,7 +303,7 @@ int WiFiManager::connectWifi(String ssid, String pass) { WiFi.persistent(false); } else { // connect using saved ssid if there is one - if (WiFi.SSID()) { + if (WiFi.SSID() != "") { DEBUG_WM("Connecting to saved AP"); // trying to fix connection in progress hanging, explain why ?? ETS_UART_INTR_DISABLE(); @@ -310,9 +313,11 @@ int WiFiManager::connectWifi(String ssid, String pass) { WiFi.begin(); } else { DEBUG_WM("No saved credentials"); + waitforconx = false; } } - int connRes = waitForConnectResult(); + + int connRes = waitforconx ? waitForConnectResult() : WL_NO_SSID_AVAIL; DEBUG_WM ("Connection result: "); DEBUG_WM ( connRes ); From 486ea7db2c769df83527619dc1356740fbb84b30 Mon Sep 17 00:00:00 2001 From: Alex Goris Date: Thu, 4 May 2017 21:59:17 +0200 Subject: [PATCH 018/424] Allow showing static IP config without predefined value Previously a valid predefined static IP had to be passed before the config page would show the IP, gateway and subnet fields. This did not allow the config page to show 'optional' static IP fields. Now a boolean can be passed to the autoConnect() function which will specify whether the static IP fields should be shown or not. When this boolean is true but no predefined values are passed and fields are left blank in config page, wifiManager will revert to DHCP. This allows user to choose between static IP or DHCP without changing code --- WiFiManager.cpp | 16 +++++++++------- WiFiManager.h | 7 ++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 06e7481..8ac235c 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -131,15 +131,17 @@ void WiFiManager::setupConfigPortal() { } -boolean WiFiManager::autoConnect() { +boolean WiFiManager::autoConnect(boolean showStaticIPFields) { String ssid = "ESP" + String(ESP.getChipId()); - return autoConnect(ssid.c_str(), NULL); + return autoConnect(ssid.c_str(), NULL, showStaticIPFields); } -boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { +boolean WiFiManager::autoConnect(char const *apName, char const *apPassword, boolean showStaticIPFields) { DEBUG_WM(F("")); DEBUG_WM(F("AutoConnect")); + _sta_show_static_fields = showStaticIPFields; + // read eeprom for ssid and pass //String ssid = getSSID(); //String pass = getPassword(); @@ -498,14 +500,14 @@ void WiFiManager::handleWifi(boolean scan) { page += "
"; } - if (_sta_static_ip) { + if (_sta_show_static_fields) { String item = FPSTR(HTTP_FORM_PARAM); item.replace("{i}", "ip"); item.replace("{n}", "ip"); item.replace("{p}", "Static IP"); item.replace("{l}", "15"); - item.replace("{v}", _sta_static_ip.toString()); + item.replace("{v}", (_sta_static_ip ? _sta_static_ip.toString() : "")); page += item; @@ -514,7 +516,7 @@ void WiFiManager::handleWifi(boolean scan) { item.replace("{n}", "gw"); item.replace("{p}", "Static Gateway"); item.replace("{l}", "15"); - item.replace("{v}", _sta_static_gw.toString()); + item.replace("{v}", (_sta_static_gw ? _sta_static_gw.toString() : "")); page += item; @@ -523,7 +525,7 @@ void WiFiManager::handleWifi(boolean scan) { item.replace("{n}", "sn"); item.replace("{p}", "Subnet"); item.replace("{l}", "15"); - item.replace("{v}", _sta_static_sn.toString()); + item.replace("{v}", (_sta_static_sn ? _sta_static_sn.toString() : "")); page += item; diff --git a/WiFiManager.h b/WiFiManager.h index bd67c05..3edff0a 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -35,7 +35,7 @@ const char HTTP_SCAN_LINK[] PROGMEM = "
Date: Thu, 4 May 2017 22:04:05 +0200 Subject: [PATCH 019/424] Also show static IP fields when static IP is passed Regardless of the boolean, we should always show static IP fields if actual static IP value is passed. This ensures backwards compatibility --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 8ac235c..343be0f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -500,7 +500,7 @@ void WiFiManager::handleWifi(boolean scan) { page += "
"; } - if (_sta_show_static_fields) { + if (_sta_show_static_fields || _sta_static_ip) { String item = FPSTR(HTTP_FORM_PARAM); item.replace("{i}", "ip"); From 179c0309a5c1a894bdc8707d901ffb6677888bbf Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sat, 26 Aug 2017 23:13:37 -0500 Subject: [PATCH 020/424] comments, autoconnect fix fix sta+ap mode preservaton in autoconnect --- WiFiManager.cpp | 84 ++++++++++++------- WiFiManager.h | 2 + .../AutoConnectWithTimeout/platformio.ini | 18 ++++ 3 files changed, 75 insertions(+), 29 deletions(-) create mode 100644 examples/AutoConnectWithTimeout/platformio.ini diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 4327cd8..c56fcb5 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -106,15 +106,16 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { //String pass = getPassword(); // attempt to connect using saved settings, on fail fallback to AP config portal - // WiFi.mode(WIFI_STA); // why, should not be needed + if((WiFi.getMode() & WIFI_STA) == 0) wifimode(WIFI_STA); // if STA not on, turn it on + // if already connected, or try stored connect if (WiFi.status() == WL_CONNECTED || connectWifi("", "") == WL_CONNECTED) { //connected DEBUG_WM(F("IP Address:")); DEBUG_WM(WiFi.localIP()); return true; } - + // not connected start configportal return startConfigPortal(apName, apPassword); } @@ -131,7 +132,7 @@ bool WiFiManager::startAP(){ bool ret = true; - // start soft AP with pass or anonymous + // start soft AP with password or anonymous if (_apPassword != NULL) { ret = WiFi.softAP(_apName, _apPassword);//password option } else { @@ -139,7 +140,7 @@ bool WiFiManager::startAP(){ ret = WiFi.softAP(_apName); } - delay(500); // slight delay to make sure we have an AP IP + delay(500); // slight delay to make sure we get an AP IP DEBUG_WM(F("AP IP address: ")); DEBUG_WM(WiFi.softAPIP()); @@ -167,7 +168,7 @@ void WiFiManager::setupConfigPortal() { DEBUG_WM(F("setupConfigPortal")); _configPortalStart = millis(); - if(!startAP()) DEBUG_WM("There was an error stating the AP"); + if(!startAP()) DEBUG_WM("There was an error stating the AP"); // @bug startAP returns unreliable success status /* Setup the DNS server redirecting all the domains to the apIP */ dnsServer->setErrorReplyCode(DNSReplyCode::NoError); @@ -194,10 +195,15 @@ boolean WiFiManager::startConfigPortal() { boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) { //setup AP - // @todo AP_STA will constantly try to connect to old aps in background, if not allowing background configportal , maybe turn off STA - WiFi.mode(WIFI_AP); - // WiFi.mode(WIFI_AP_STA); - DEBUG_WM("SET AP STA"); + if(!WiFi.isConnected()){ + // this fixes most ap problems, simply doing mode(WIFI_AP) does not work if sta connection is hanging + wifioff(); + wifimode(WIFI_AP); + DEBUG_WM("Disabling STA"); + } + else wifimode(WIFI_AP_STA); + + DEBUG_WM("Enabling AP"); _apName = apName; _apPassword = apPassword; @@ -223,7 +229,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo return false; } -//@todo need enums for return, using 3 esp enums for now +//using esp enums returns for now, should be fine uint8_t WiFiManager::handleConfigPortal(){ //DNS handler dnsServer->processNextRequest(); @@ -262,15 +268,21 @@ boolean WiFiManager::stopConfigPortal(){ _savecallback(); } - // @todo does this unload them enough ? + //DNS handler + dnsServer->processNextRequest(); + //HTTP handler + server->handleClient(); + + // @todo does this free memory? server.reset(); dnsServer.reset(); // turn off AP DEBUG_WM(F("disconnect configportal")); - // WiFi.mode(WIFI_STA); - WiFi.softAPdisconnect(false); - return false; + bool ret = WiFi.softAPdisconnect(false); + if(!ret)DEBUG_WM(F("disconnect configportal error")); + wifimode(WIFI_STA); // set back to sta, @todo use preservation variable + return ret; } // @todo refactor this up into seperate functions @@ -288,12 +300,8 @@ int WiFiManager::connectWifi(String ssid, String pass) { DEBUG_WM(WiFi.localIP()); } - // fix for auto connect racing issue - // @todo this had to be fixed, it will not let you set a new wifi, if still connected to another, as it just returns - if (WiFi.status() == WL_CONNECTED && (ssid=="" || WiFi.SSID() == ssid)) { - DEBUG_WM("Already connected. Exiting"); - return WL_CONNECTED; - } + wifimode(WIFI_AP_STA); // turn sta back on so begin does not call enablesta->mode + wifioff(); // disconnect before begin, in case anything is hung // if ssid argument provided connect to that if (ssid != "") { @@ -305,11 +313,6 @@ int WiFiManager::connectWifi(String ssid, String pass) { // connect using saved ssid if there is one if (WiFi.SSID() != "") { DEBUG_WM("Connecting to saved AP"); - // trying to fix connection in progress hanging, explain why ?? - ETS_UART_INTR_DISABLE(); - wifi_station_disconnect(); - ETS_UART_INTR_ENABLE(); - WiFi.begin(); } else { DEBUG_WM("No saved credentials"); @@ -339,8 +342,11 @@ uint8_t WiFiManager::waitForConnectResult(uint16_t timeout) { } uint8_t WiFiManager::waitForConnectResult() { - if (_connectTimeout == 0) return WiFi.waitForConnectResult(); - + if (_connectTimeout == 0){ + DEBUG_WM (F("connectTimeout not set, ESP waitForConnectResult...")); + return WiFi.waitForConnectResult(); + } + DEBUG_WM (F("connectTimeout set, waiting for connect....")); uint8_t status; int timeout = millis() + _connectTimeout; @@ -880,12 +886,32 @@ boolean WiFiManager::validApPassword(){ if (_apPassword == "") _apPassword = NULL; if (_apPassword != NULL) { if (strlen(_apPassword) < 8 || strlen(_apPassword) > 63) { - DEBUG_WM(F("AccessPoint password is INVALID")); + DEBUG_WM(F("AccessPoint set password is INVALID")); _apPassword = NULL; return false; // @todo FATAL or fallback to NULL ? } - DEBUG_WM(F("AccessPoint Password is VALID")); + DEBUG_WM(F("AccessPoint set password is VALID")); DEBUG_WM(_apPassword); } return true; } + +// set mode without persistent +bool WiFiManager::wifimode(WiFiMode_t m) { + if(wifi_get_opmode() == (uint8) m) { + return true; + } + bool ret; + ETS_UART_INTR_DISABLE(); + ret = wifi_set_opmode_current(m); + ETS_UART_INTR_ENABLE(); + return ret; +} + +// sta disconnect without persistent +bool WiFiManager::wifioff() { + DEBUG_WM(F("wifi disconncting")); + if((WiFi.getMode() & WIFI_STA) != 0) { + return wifi_station_disconnect(); + } +} \ No newline at end of file diff --git a/WiFiManager.h b/WiFiManager.h index 40efb9b..c2bf7da 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -175,6 +175,8 @@ class WiFiManager boolean configPortalHasTimeout(); boolean stopConfigPortal(); uint8_t handleConfigPortal(); + bool wifimode(WiFiMode_t m); + bool wifioff(); // DNS server const byte DNS_PORT = 53; diff --git a/examples/AutoConnectWithTimeout/platformio.ini b/examples/AutoConnectWithTimeout/platformio.ini new file mode 100644 index 0000000..7e80288 --- /dev/null +++ b/examples/AutoConnectWithTimeout/platformio.ini @@ -0,0 +1,18 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[env:nodemcuv2] +platform=espressif8266 +board=nodemcuv2 +framework=arduino + +[platformio] +src_dir=AutoConnectWithTimeout +lib_dir=/Users/shawn/projects/microcontrollers/dev/libraries From 0aecffc8226d38ae165615ff10690243fcc2a9a4 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sat, 26 Aug 2017 23:26:48 -0500 Subject: [PATCH 021/424] fix configportal loop flow removed returns for better flow --- WiFiManager.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index c56fcb5..ef9a5f2 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -202,7 +202,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo DEBUG_WM("Disabling STA"); } else wifimode(WIFI_AP_STA); - + DEBUG_WM("Enabling AP"); _apName = apName; @@ -213,20 +213,28 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // init configportal setupConfigPortal(); - uint8_t ret; + uint8_t state; + bool result = false; // blocking loop waiting for config while(1){ + // check if timed out if(configPortalHasTimeout()){ stopConfigPortal(); - return WiFi.status() == WL_CONNECTED; //returns connected bool, ok I guess + result = WiFi.status() == WL_CONNECTED; //returns connected bool, ok I guess + break; + } + + state = handleConfigPortal(); + + if(state != WL_IDLE_STATUS){ + result == WL_CONNECTED; + break; } - ret = handleConfigPortal(); - if(ret != WL_IDLE_STATUS) return ret == WL_CONNECTED; yield(); } - return false; + return result; } //using esp enums returns for now, should be fine From 47d9082e18dc9a9f7670f1970b5a7ba4aec2c8cd Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sun, 27 Aug 2017 00:11:04 -0500 Subject: [PATCH 022/424] testing non blocking portal calling process in loop not fast enough results in corrupt webpages, not sure why. --- WiFiManager.cpp | 12 ++++++++++++ WiFiManager.h | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index ef9a5f2..57c4dc5 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -209,6 +209,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo _apPassword = apPassword; if(!validApPassword()) return false; + configPortalActive = true; connect = false; // global // init configportal @@ -216,6 +217,8 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo uint8_t state; bool result = false; + if(!_configPortalIsBlocking) return result; + // blocking loop waiting for config while(1){ @@ -237,6 +240,14 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo return result; } +boolean WiFiManager::process(){ + if(configPortalActive){ + uint8_t state = handleConfigPortal(); + return state == WL_CONNECTED; + } + return false; +} + //using esp enums returns for now, should be fine uint8_t WiFiManager::handleConfigPortal(){ //DNS handler @@ -290,6 +301,7 @@ boolean WiFiManager::stopConfigPortal(){ bool ret = WiFi.softAPdisconnect(false); if(!ret)DEBUG_WM(F("disconnect configportal error")); wifimode(WIFI_STA); // set back to sta, @todo use preservation variable + configPortalActive = false; return ret; } diff --git a/WiFiManager.h b/WiFiManager.h index c2bf7da..c466c9c 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -82,6 +82,7 @@ class WiFiManager //if you want to always start the config portal, without trying to connect first boolean startConfigPortal(); boolean startConfigPortal(char const *apName, char const *apPassword = NULL); + boolean process(); // get the AP name of the config portal, so it can be used in the callback String getConfigPortalSSID(); @@ -148,11 +149,13 @@ class WiFiManager IPAddress _sta_static_gw; IPAddress _sta_static_sn; + // option parameters int _paramsCount = 0; int _minimumQuality = -1; boolean _removeDuplicateAPs = true; boolean _shouldBreakAfterConfig = false; boolean _tryWPS = false; + boolean _configPortalIsBlocking = false; const char* _customHeadElement = ""; @@ -188,6 +191,7 @@ class WiFiManager boolean validApPassword(); boolean connect; + boolean configPortalActive = false; boolean _debug = true; void (*_apcallback)(WiFiManager*) = NULL; From c4563802f3110b315ca5f8482c191462a4941cbf Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sun, 27 Aug 2017 09:32:31 -0500 Subject: [PATCH 023/424] renable blocking --- WiFiManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.h b/WiFiManager.h index 52b74fe..eb56a04 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -155,7 +155,7 @@ class WiFiManager boolean _removeDuplicateAPs = true; boolean _shouldBreakAfterConfig = false; boolean _tryWPS = false; - boolean _configPortalIsBlocking = false; + boolean _configPortalIsBlocking = true; const char* _customHeadElement = ""; From f2580463e43bc1bc8f1e929916c52e36edcb6c7f Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sun, 27 Aug 2017 10:55:26 -0500 Subject: [PATCH 024/424] fix const char corruptions #400 fixing non blocking, non blocking does not handle timeouts for the user --- WiFiManager.cpp | 27 ++++++++++++++++----------- WiFiManager.h | 6 +++--- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index a0428e8..b43feae 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -133,11 +133,11 @@ bool WiFiManager::startAP(){ bool ret = true; // start soft AP with password or anonymous - if (_apPassword != NULL) { - ret = WiFi.softAP(_apName, _apPassword);//password option + if (_apPassword != "") { + ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str());//password option } else { DEBUG_WM(F("AP has anonymous access")); - ret = WiFi.softAP(_apName); + ret = WiFi.softAP(_apName.c_str()); } delay(500); // slight delay to make sure we get an AP IP @@ -205,7 +205,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo DEBUG_WM("Enabling AP"); - _apName = apName; + _apName = apName; // @todo check valid apname ? _apPassword = apPassword; if(!validApPassword()) return false; @@ -217,8 +217,12 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo uint8_t state; bool result = false; - if(!_configPortalIsBlocking) return result; + if(!_configPortalIsBlocking){ + DEBUG_WM(F("Config Portal Running, non blocking/processing")); + return result; + } + DEBUG_WM(F("Config Portal Running, blocking")); // blocking loop waiting for config while(1){ @@ -815,7 +819,8 @@ void WiFiManager::handleNotFound() { * Return true in that case so the page handler do not try to handle the request again. */ boolean WiFiManager::captivePortal() { - if (!isIp(server->hostHeader()) ) { +DEBUG_WM(server->hostHeader()); + if (!isIp(server->hostHeader()) && false) { DEBUG_WM(F("Request redirected to captive portal")); server->sendHeader("Location", String("http://") + toStringIp(server->client().localIP()), true); server->send ( 302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves. @@ -893,12 +898,12 @@ String WiFiManager::toStringIp(IPAddress ip) { boolean WiFiManager::validApPassword(){ // check that ap password is valid, return false - if (_apPassword == "") _apPassword = NULL; - if (_apPassword != NULL) { - if (strlen(_apPassword) < 8 || strlen(_apPassword) > 63) { + if (_apPassword == NULL) _apPassword = ""; + if (_apPassword != "") { + if (_apPassword.length() < 8 || _apPassword.length() > 63) { DEBUG_WM(F("AccessPoint set password is INVALID")); - _apPassword = NULL; - return false; // @todo FATAL or fallback to NULL ? + _apPassword = ""; + return false; // @todo FATAL or fallback to empty ? } DEBUG_WM(F("AccessPoint set password is VALID")); DEBUG_WM(_apPassword); diff --git a/WiFiManager.h b/WiFiManager.h index eb56a04..d156ecf 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -134,8 +134,8 @@ class WiFiManager void startWPS(); bool startAP(); - const char* _apName = "no-net"; - const char* _apPassword = NULL; + String _apName = "no-net"; + String _apPassword = ""; String _ssid = ""; String _pass = ""; unsigned long _configPortalTimeout = 0; @@ -155,7 +155,7 @@ class WiFiManager boolean _removeDuplicateAPs = true; boolean _shouldBreakAfterConfig = false; boolean _tryWPS = false; - boolean _configPortalIsBlocking = true; + boolean _configPortalIsBlocking = false; const char* _customHeadElement = ""; From 8592647cbfd990af8fec8528ad0e5d47e6d8e50d Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sun, 27 Aug 2017 10:57:43 -0500 Subject: [PATCH 025/424] fraking tabs --- WiFiManager.cpp | 30 +++++++++++++++--------------- WiFiManager.h | 4 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index b43feae..05a8f9b 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -70,10 +70,10 @@ void WiFiManager::addParameter(WiFiManagerParameter *p) { if(_paramsCount + 1 > WIFI_MANAGER_MAX_PARAMS) { //Max parameters exceeded! - DEBUG_WM("WIFI_MANAGER_MAX_PARAMS exceeded, increase number (in WiFiManager.h) before adding more parameters!"); - DEBUG_WM("Skipping parameter with ID:"); - DEBUG_WM(p->getID()); - return; + DEBUG_WM("WIFI_MANAGER_MAX_PARAMS exceeded, increase number (in WiFiManager.h) before adding more parameters!"); + DEBUG_WM("Skipping parameter with ID:"); + DEBUG_WM(p->getID()); + return; } _params[_paramsCount] = p; _paramsCount++; @@ -115,7 +115,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { DEBUG_WM(WiFi.localIP()); return true; } - // not connected start configportal + // not connected start configportal return startConfigPortal(apName, apPassword); } @@ -209,7 +209,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo _apPassword = apPassword; if(!validApPassword()) return false; - configPortalActive = true; + configPortalActive = true; connect = false; // global // init configportal @@ -218,8 +218,8 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo bool result = false; if(!_configPortalIsBlocking){ - DEBUG_WM(F("Config Portal Running, non blocking/processing")); - return result; + DEBUG_WM(F("Config Portal Running, non blocking/processing")); + return result; } DEBUG_WM(F("Config Portal Running, blocking")); @@ -236,8 +236,8 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo state = handleConfigPortal(); if(state != WL_IDLE_STATUS){ - result == WL_CONNECTED; - break; + result == WL_CONNECTED; + break; } yield(); } @@ -245,11 +245,11 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo } boolean WiFiManager::process(){ - if(configPortalActive){ - uint8_t state = handleConfigPortal(); - return state == WL_CONNECTED; - } - return false; + if(configPortalActive){ + uint8_t state = handleConfigPortal(); + return state == WL_CONNECTED; + } + return false; } //using esp enums returns for now, should be fine diff --git a/WiFiManager.h b/WiFiManager.h index d156ecf..e76b1ab 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -134,8 +134,8 @@ class WiFiManager void startWPS(); bool startAP(); - String _apName = "no-net"; - String _apPassword = ""; + String _apName = "no-net"; + String _apPassword = ""; String _ssid = ""; String _pass = ""; unsigned long _configPortalTimeout = 0; From 8185eaa00226f31b5b65456a6fc5cec3ea5ae395 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sun, 27 Aug 2017 11:04:05 -0500 Subject: [PATCH 026/424] add blocking setter @todo add example --- WiFiManager.cpp | 5 +++++ WiFiManager.h | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 05a8f9b..450e162 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -852,6 +852,11 @@ void WiFiManager::setRemoveDuplicateAPs(boolean removeDuplicates) { _removeDuplicateAPs = removeDuplicates; } +//if this is true, remove duplicated Access Points - defaut true +void WiFiManager::setConfigPortalBlocking(boolean shoudlBlock) { + _configPortalIsBlocking = shoudlBlock; +} + // HELPERS template diff --git a/WiFiManager.h b/WiFiManager.h index e76b1ab..e69c6eb 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -114,7 +114,9 @@ class WiFiManager void addParameter(WiFiManagerParameter *p); //if this is set, it will exit after config, even if connection is unsuccessful. void setBreakAfterConfig(boolean shouldBreak); - //if this is set, try WPS setup when starting (this will delay config portal for up to 2 mins) + //if this is set, portal will be blocking and wait until save or exit, is false user must manually process to handle config portal + void setConfigPortalBlocking(boolean shouldBlock); + //TODO //if this is set, customise style void setCustomHeadElement(const char* element); @@ -155,7 +157,7 @@ class WiFiManager boolean _removeDuplicateAPs = true; boolean _shouldBreakAfterConfig = false; boolean _tryWPS = false; - boolean _configPortalIsBlocking = false; + boolean _configPortalIsBlocking = true; const char* _customHeadElement = ""; From d1ab6ec6db8289d944c9f94ec8b389470c6b8389 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 28 Aug 2017 21:00:15 -0500 Subject: [PATCH 027/424] left in debug --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 320af11..a7d63a8 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -820,8 +820,8 @@ void WiFiManager::handleNotFound() { * Return true in that case so the page handler do not try to handle the request again. */ boolean WiFiManager::captivePortal() { -DEBUG_WM(server->hostHeader()); - if (!isIp(server->hostHeader()) && false) { + DEBUG_WM(server->hostHeader()); + if (!isIp(server->hostHeader())) { DEBUG_WM(F("Request redirected to captive portal")); server->sendHeader("Location", String("http://") + toStringIp(server->client().localIP()), true); server->send ( 302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves. From 04a9dda74b98cb14aa8ee892604f11fed5d4dd4c Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 29 Aug 2017 16:31:59 -0500 Subject: [PATCH 028/424] testing mode and persistent presrvation You should be able to have sta+softap mode with your own softap, and starting config portal will not overwrite your default softap, but i cannot find a way to reconnect other than rebooting the device --- WiFiManager.cpp | 22 +++++++++++++++++----- WiFiManager.h | 11 ++++++++++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index a7d63a8..a068068 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -82,13 +82,17 @@ void WiFiManager::addParameter(WiFiManagerParameter *p) { } // constructor -WiFiManager::WiFiManager() { - WiFi.persistent(false); +WiFiManager::WiFiManager() { + _usermode = WiFi.getMode(); + WiFi.persistent(false); // disable persistent so scannetworks and mode switching is not saved } // destructor WiFiManager::~WiFiManager() { - WiFi.persistent(true); // @todo restore original + if(_userpersistent) WiFi.persistent(true); // reenable persistent + WiFi.mode(_usermode); + DEBUG_WM(_usermode); + DEBUG_WM(F("unloading")); } // AUTOCONNECT @@ -121,7 +125,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { // CONFIG PORTAL bool WiFiManager::startAP(){ - DEBUG_WM(F("Configuring access point with with SSID ... ")); + DEBUG_WM(F("Configuring access point with with SSID of ... ")); DEBUG_WM(_apName); // setup optional soft AP static ip config @@ -303,7 +307,7 @@ boolean WiFiManager::stopConfigPortal(){ // turn off AP DEBUG_WM(F("disconnect configportal")); bool ret = WiFi.softAPdisconnect(false); - if(!ret)DEBUG_WM(F("disconnect configportal error")); + if(!ret)DEBUG_WM(F("disconnect configportal - softAPdisconnect failed")); wifimode(WIFI_STA); // set back to sta, @todo use preservation variable configPortalActive = false; return ret; @@ -422,7 +426,9 @@ String WiFiManager::getConfigPortalSSID() { void WiFiManager::resetSettings() { DEBUG_WM(F("SETTINGS ERASED")); DEBUG_WM(F("THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA.")); // @todo WHUT? + WiFi.persistent(true); WiFi.disconnect(true); + WiFi.persistent(false); //delay(200); } @@ -858,6 +864,12 @@ void WiFiManager::setConfigPortalBlocking(boolean shoudlBlock) { _configPortalIsBlocking = shoudlBlock; } +//wrapper for ESP wifi.persistent so we can remember it as WIFi._persistent is protected +void WiFiManager::setRestorePersistent(boolean persistent) { + _userpersistent = persistent; + if(!persistent) DEBUG_WM(F("persistent is off")); +} + // HELPERS template diff --git a/WiFiManager.h b/WiFiManager.h index 72956b0..843ddb1 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -125,11 +125,13 @@ class WiFiManager //if this is set, portal will be blocking and wait until save or exit, is false user must manually process to handle config portal void setConfigPortalBlocking(boolean shouldBlock); - //TODO + //if this is set, customise style void setCustomHeadElement(const char* element); //if this is true, remove duplicated Access Points - defaut true void setRemoveDuplicateAPs(boolean removeDuplicates); + //wrapper for esp wifi persistent, set esp wifi persistent through wifimanager so we can save status and restore as needed + void setRestorePersistent(boolean persistent); private: std::unique_ptr dnsServer; @@ -144,6 +146,11 @@ class WiFiManager void startWPS(); bool startAP(); + // typedef enum WiFiMode + // { + // WIFI_OFF = 0, WIFI_STA = 1, WIFI_AP = 2, WIFI_AP_STA = 3 + // } WiFiMode_t; + String _apName = "no-net"; String _apPassword = ""; String _ssid = ""; @@ -151,6 +158,8 @@ class WiFiManager unsigned long _configPortalTimeout = 0; unsigned long _connectTimeout = 0; unsigned long _configPortalStart = 0; + boolean _userpersistent = true; + WiFiMode_t _usermode = WIFI_OFF; IPAddress _ap_static_ip; IPAddress _ap_static_gw; From 9160b5bd3b8b1974dc6a39af2ab629b09a1779e4 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 30 Aug 2017 09:15:36 -0500 Subject: [PATCH 029/424] maxlength null string fix pr#244 --- WiFiManager.cpp | 9 ++++----- WiFiManager.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index a068068..b94e0fc 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -41,7 +41,7 @@ void WiFiManagerParameter::init(const char *id, const char *placeholder, const c _value[i] = 0; } if (defaultValue != NULL) { - strncpy(_value, defaultValue, length); + strncpy(_value, defaultValue, length+1); // length+1 due to null terminated string } _customHTML = custom; @@ -84,7 +84,7 @@ void WiFiManager::addParameter(WiFiManagerParameter *p) { // constructor WiFiManager::WiFiManager() { _usermode = WiFi.getMode(); - WiFi.persistent(false); // disable persistent so scannetworks and mode switching is not saved + WiFi.persistent(false); // disable persistent so scannetworks and mode switching do not cause overwrites } // destructor @@ -309,6 +309,7 @@ boolean WiFiManager::stopConfigPortal(){ bool ret = WiFi.softAPdisconnect(false); if(!ret)DEBUG_WM(F("disconnect configportal - softAPdisconnect failed")); wifimode(WIFI_STA); // set back to sta, @todo use preservation variable + WiFi.mode(_usermode); configPortalActive = false; return ret; } @@ -575,7 +576,7 @@ void WiFiManager::handleWifi(boolean scan) { page += item; delay(0); } else { - DEBUG_WM(F("Skipping due to quality")); + DEBUG_WM(F("Skipping , does not meet _minimumQuality")); } } @@ -659,13 +660,11 @@ void WiFiManager::handleWifi(boolean scan) { page += FPSTR(HTTP_FORM_END); page += FPSTR(HTTP_SCAN_LINK); - page += FPSTR(HTTP_END); server->sendHeader("Content-Length", String(page.length())); server->send(200, "text/html", page); - DEBUG_WM(F("Sent config page")); } diff --git a/WiFiManager.h b/WiFiManager.h index 843ddb1..433ddd9 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -36,7 +36,7 @@ const char HTTP_HEAD_END[] PROGMEM = "



"; const char HTTP_ITEM[] PROGMEM = "
"; //const char HTTP_ITEM_PADLOCK[] PROGMEM = ""; -const char HTTP_FORM_START[] PROGMEM = "


"; +const char HTTP_FORM_START[] PROGMEM = "

"; const char HTTP_FORM_LABEL[] PROGMEM = ""; const char HTTP_FORM_PARAM[] PROGMEM = "
"; const char HTTP_FORM_END[] PROGMEM = "
"; From 63dd714805c5e818b975fa773a3b549f5e7a884d Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 30 Aug 2017 09:22:40 -0500 Subject: [PATCH 030/424] oops missed one pr#244 --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index b94e0fc..3d97c04 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -686,7 +686,7 @@ void WiFiManager::handleWifiSave() { //read parameter String value = server->arg(_params[i]->getID()).c_str(); //store it in array - value.toCharArray(_params[i]->_value, _params[i]->_length); + value.toCharArray(_params[i]->_value, _params[i]->_length+1); // length+1 null terminated DEBUG_WM(F("Parameter")); DEBUG_WM(_params[i]->getID()); DEBUG_WM(value); From 606a1c312884eadc9e17bb0b69a6af24e8de3562 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 30 Aug 2017 10:00:29 -0500 Subject: [PATCH 031/424] removed escaped quotes --- WiFiManager.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/WiFiManager.h b/WiFiManager.h index 433ddd9..4bfaaa9 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -22,8 +22,8 @@ extern "C" { #include "user_interface.h" } -const char HTTP_HEAD[] PROGMEM = "{v}"; -// const char HTTP_STYLE[] PROGMEM = ""; +const char HTTP_HEAD[] PROGMEM = "{v}"; +// const char HTTP_STYLE[] PROGMEM = ""; const char HTTP_STYLE[] PROGMEM = ""; const char HTTP_SCRIPT[] PROGMEM = ""; const char HTTP_HEAD_END[] PROGMEM = "
"; -const char HTTP_PORTAL_OPTIONS[] PROGMEM = "



"; +const char HTTP_PORTAL_OPTIONS[] PROGMEM = "



"; const char HTTP_ITEM[] PROGMEM = ""; //const char HTTP_ITEM_PADLOCK[] PROGMEM = ""; const char HTTP_FORM_START[] PROGMEM = "


"; -const char HTTP_FORM_LABEL[] PROGMEM = ""; +const char HTTP_FORM_LABEL[] PROGMEM = ""; const char HTTP_FORM_PARAM[] PROGMEM = "
"; const char HTTP_FORM_END[] PROGMEM = "
"; -const char HTTP_SCAN_LINK[] PROGMEM = "
"; +const char HTTP_SCAN_LINK[] PROGMEM = "
"; const char HTTP_SAVED[] PROGMEM = "
Credentials Saved
Trying to connect ESP to network.
If it fails reconnect to AP to try again
"; const char HTTP_END[] PROGMEM = "
"; From 66c653ff94bb83f08b317b94b022dafb64ecfc5d Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 30 Aug 2017 10:00:48 -0500 Subject: [PATCH 032/424] convert to post --- WiFiManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.h b/WiFiManager.h index 4bfaaa9..9500450 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -33,7 +33,7 @@ const char HTTP_STYLE[] PROGMEM = ""; const char HTTP_SCRIPT[] PROGMEM = ""; const char HTTP_HEAD_END[] PROGMEM = "
"; -const char HTTP_PORTAL_OPTIONS[] PROGMEM = "



"; +const char HTTP_PORTAL_OPTIONS[] PROGMEM = "



"; const char HTTP_ITEM[] PROGMEM = ""; //const char HTTP_ITEM_PADLOCK[] PROGMEM = ""; const char HTTP_FORM_START[] PROGMEM = "


"; From 6e43c1eb41c87aca254e85418118c51c0d94268b Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 30 Aug 2017 10:24:04 -0500 Subject: [PATCH 033/424] change all forms to POST #409 --- WiFiManager.cpp | 3 ++- WiFiManager.h | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 3d97c04..33500f7 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -382,6 +382,7 @@ uint8_t WiFiManager::waitForConnectResult() { while(millis() < timeout) { status = WiFi.status(); + // @todo detect additional states, connect happens, then dhcp then get ip, there is some delay here, make sure not to timeout if waiting on IP if (status == WL_CONNECTED || status == WL_CONNECT_FAILED) { return status; } @@ -673,7 +674,7 @@ void WiFiManager::handleWifi(boolean scan) { */ void WiFiManager::handleWifiSave() { DEBUG_WM(F("WiFi save")); - + //SAVE/connect here _ssid = server->arg("s").c_str(); _pass = server->arg("p").c_str(); diff --git a/WiFiManager.h b/WiFiManager.h index 9500450..2949d2b 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -33,10 +33,10 @@ const char HTTP_STYLE[] PROGMEM = ""; const char HTTP_SCRIPT[] PROGMEM = ""; const char HTTP_HEAD_END[] PROGMEM = "
"; -const char HTTP_PORTAL_OPTIONS[] PROGMEM = "


"; +const char HTTP_PORTAL_OPTIONS[] PROGMEM = "



"; const char HTTP_ITEM[] PROGMEM = ""; //const char HTTP_ITEM_PADLOCK[] PROGMEM = ""; -const char HTTP_FORM_START[] PROGMEM = "


"; +const char HTTP_FORM_START[] PROGMEM = "

"; const char HTTP_FORM_LABEL[] PROGMEM = ""; const char HTTP_FORM_PARAM[] PROGMEM = "
"; const char HTTP_FORM_END[] PROGMEM = "
"; From 5f288438435b471007fca38d66d5c461cfbd7303 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 30 Aug 2017 14:01:37 -0500 Subject: [PATCH 034/424] Cleaned some html csss --- WiFiManager.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WiFiManager.h b/WiFiManager.h index 2949d2b..7005227 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -24,7 +24,7 @@ extern "C" { const char HTTP_HEAD[] PROGMEM = "{v}"; // const char HTTP_STYLE[] PROGMEM = ""; -const char HTTP_STYLE[] PROGMEM = ""; const char HTTP_SCRIPT[] PROGMEM = ""; const char HTTP_HEAD_END[] PROGMEM = "
"; -const char HTTP_PORTAL_OPTIONS[] PROGMEM = "



"; +const char HTTP_PORTAL_OPTIONS[] PROGMEM = "



"; const char HTTP_ITEM[] PROGMEM = ""; //const char HTTP_ITEM_PADLOCK[] PROGMEM = ""; const char HTTP_FORM_START[] PROGMEM = "


"; const char HTTP_FORM_LABEL[] PROGMEM = ""; const char HTTP_FORM_PARAM[] PROGMEM = "
"; -const char HTTP_FORM_END[] PROGMEM = "
"; +const char HTTP_FORM_END[] PROGMEM = "
"; const char HTTP_SCAN_LINK[] PROGMEM = "
"; const char HTTP_SAVED[] PROGMEM = "
Credentials Saved
Trying to connect ESP to network.
If it fails reconnect to AP to try again
"; const char HTTP_END[] PROGMEM = "
"; From 2c357d7e8683444e27195a9cef037c1c67fd4ffe Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 31 Aug 2017 10:21:21 -0500 Subject: [PATCH 035/424] changing non form back to GET for now #409 --- WiFiManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.h b/WiFiManager.h index 7005227..4d25252 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -33,7 +33,7 @@ const char HTTP_STYLE[] PROGMEM = ""; const char HTTP_SCRIPT[] PROGMEM = ""; const char HTTP_HEAD_END[] PROGMEM = "
"; -const char HTTP_PORTAL_OPTIONS[] PROGMEM = "



"; +const char HTTP_PORTAL_OPTIONS[] PROGMEM = "



"; const char HTTP_ITEM[] PROGMEM = ""; //const char HTTP_ITEM_PADLOCK[] PROGMEM = ""; const char HTTP_FORM_START[] PROGMEM = "


"; From 6525a0bd3d1960df68cebd9d3b6411e16ee14e17 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 31 Aug 2017 13:57:11 -0500 Subject: [PATCH 036/424] fixed comment wording --- WiFiManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.h b/WiFiManager.h index 4d25252..f021a23 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -130,7 +130,7 @@ class WiFiManager void setCustomHeadElement(const char* element); //if this is true, remove duplicated Access Points - defaut true void setRemoveDuplicateAPs(boolean removeDuplicates); - //wrapper for esp wifi persistent, set esp wifi persistent through wifimanager so we can save status and restore as needed + //setter for ESP wifi.persistent so we can remember it and restore user preference, as WIFi._persistent is protected void setRestorePersistent(boolean persistent); private: From a93b601cd7e349db43c98a439896e34569d67fc7 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 31 Aug 2017 13:57:23 -0500 Subject: [PATCH 037/424] again --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 33500f7..d84e753 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -674,7 +674,7 @@ void WiFiManager::handleWifi(boolean scan) { */ void WiFiManager::handleWifiSave() { DEBUG_WM(F("WiFi save")); - + //SAVE/connect here _ssid = server->arg("s").c_str(); _pass = server->arg("p").c_str(); @@ -864,7 +864,7 @@ void WiFiManager::setConfigPortalBlocking(boolean shoudlBlock) { _configPortalIsBlocking = shoudlBlock; } -//wrapper for ESP wifi.persistent so we can remember it as WIFi._persistent is protected +//setter for ESP wifi.persistent so we can remember it and restore user preference, as WIFi._persistent is protected void WiFiManager::setRestorePersistent(boolean persistent) { _userpersistent = persistent; if(!persistent) DEBUG_WM(F("persistent is off")); From 81b37dfffce6cff343257549ab08fa000f8e0963 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 8 Sep 2017 16:08:35 -0500 Subject: [PATCH 038/424] adds some style, clean up css, adds new tokens #415 --- WiFiManager.cpp | 30 ++++- WiFiManager.h | 20 +++- extras/WiFiManager.template.html | 196 +++++++++++++++++++++++++------ extras/test.html | 8 +- 4 files changed, 201 insertions(+), 53 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index d84e753..e758692 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -560,15 +560,18 @@ void WiFiManager::handleWifi(boolean scan) { DEBUG_WM(WiFi.SSID(indices[i])); DEBUG_WM(WiFi.RSSI(indices[i])); int quality = getRSSIasQuality(WiFi.RSSI(indices[i])); + uint8_t enc_type = WiFi.encryptionType(indices[i]); if (_minimumQuality == -1 || _minimumQuality < quality) { String item = FPSTR(HTTP_ITEM); String rssiQ; rssiQ += quality; - item.replace("{v}", WiFi.SSID(indices[i])); - item.replace("{r}", rssiQ); - item.replace("{q}", (String)round(map(quality,0,100,1,4))); - if (WiFi.encryptionType(indices[i]) != ENC_TYPE_NONE) { + item.replace("{v}", WiFi.SSID(indices[i])); // ssid no encoding + item.replace("{R}", (String)WiFi.RSSI(indices[i])); // rssi + item.replace("{e}", encryptionTypeStr(enc_type)); + item.replace("{r}", rssiQ); // qualitypercent + item.replace("{q}", (String)round(map(quality,0,100,1,4))); //quality icon 1-4 + if (enc_type != ENC_TYPE_NONE) { item.replace("{i}", "l"); } else { item.replace("{i}", ""); @@ -616,7 +619,7 @@ void WiFiManager::handleWifi(boolean scan) { snprintf(parLength, 5, "%d", _params[i]->getValueLength()); pitem.replace("{l}", parLength); pitem.replace("{v}", _params[i]->getValue()); - pitem.replace("{c}", _params[i]->getCustomHTML()); + pitem.replace("{c}", _params[i]->getCustomHTML()); // additional attributes not html } else { pitem = _params[i]->getCustomHTML(); } @@ -929,6 +932,23 @@ boolean WiFiManager::validApPassword(){ return true; } +String WiFiManager::encryptionTypeStr(uint8_t authmode) { + switch(authmode) { + case ENC_TYPE_NONE: + return "None"; + case ENC_TYPE_WEP: + return "WEP"; + case ENC_TYPE_TKIP: + return "WPA_PSK"; + case ENC_TYPE_CCMP: + return "WPA2_PSK"; + case ENC_TYPE_AUTO: + return "WPA_WPA2_PSK"; + default: + return "Unknown"; + } +} + // set mode without persistent bool WiFiManager::wifimode(WiFiMode_t m) { if(wifi_get_opmode() == (uint8) m) { diff --git a/WiFiManager.h b/WiFiManager.h index f021a23..f6ad1ec 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -24,15 +24,24 @@ extern "C" { const char HTTP_HEAD[] PROGMEM = "{v}"; // const char HTTP_STYLE[] PROGMEM = ""; -const char HTTP_STYLE[] PROGMEM = ""; + const char HTTP_SCRIPT[] PROGMEM = ""; -const char HTTP_HEAD_END[] PROGMEM = "
"; +const char HTTP_HEAD_END[] PROGMEM = "
"; const char HTTP_PORTAL_OPTIONS[] PROGMEM = "


"; const char HTTP_ITEM[] PROGMEM = ""; //const char HTTP_ITEM_PADLOCK[] PROGMEM = ""; @@ -40,8 +49,8 @@ const char HTTP_FORM_START[] PROGMEM = "
{p}"; const char HTTP_FORM_PARAM[] PROGMEM = "
"; const char HTTP_FORM_END[] PROGMEM = "
"; -const char HTTP_SCAN_LINK[] PROGMEM = "
"; -const char HTTP_SAVED[] PROGMEM = "
Credentials Saved
Trying to connect ESP to network.
If it fails reconnect to AP to try again
"; +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_END[] PROGMEM = "
"; #define WIFI_MANAGER_MAX_PARAMS 10 @@ -208,6 +217,7 @@ class WiFiManager boolean isIp(String str); String toStringIp(IPAddress ip); boolean validApPassword(); + String encryptionTypeStr(uint8_t authmode); boolean connect; boolean configPortalActive = false; diff --git a/extras/WiFiManager.template.html b/extras/WiFiManager.template.html index e15593b..2a49be3 100644 --- a/extras/WiFiManager.template.html +++ b/extras/WiFiManager.template.html @@ -6,15 +6,125 @@ {v} - + "; diff --git a/extras/WiFiManager.template.html b/extras/WiFiManager.template.html index 2a49be3..09ae94b 100644 --- a/extras/WiFiManager.template.html +++ b/extras/WiFiManager.template.html @@ -124,6 +124,13 @@ a:hover { color: #d9534f; } +dt { + font-weight: bold; +} +dd { + margin: 0; + padding: 0 0 0.5em 0; +} @@ -189,8 +196,18 @@ a:hover {

Information

Connected to AP: homeAP

Connect Failed

An error occured
- - + +

/info


+
+
Chip ID
123456
+
Flash Chip ID
1234556
+
IDE Flash Size
4194304 bytes
+
Real Flash Size
4194304 bytes
+
Soft AP IP
192.168.4.1
+
Soft AP MAC
00:00:00:00:00:00
+
Station MAC
00:00:00:00:00:00
+
+
From 64798ebbf1519f54a787a30a9cd0bb7d4a44e2b8 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sun, 10 Sep 2017 21:17:07 -0500 Subject: [PATCH 040/424] pimped out info pagee We can simply this later, or make an option string to display specific things --- WiFiManager.cpp | 113 ++++++++++++++++++++++++++++++++++++++++++++++-- WiFiManager.h | 1 + 2 files changed, 110 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index cc6edb0..0fe2c24 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -749,29 +749,114 @@ void WiFiManager::handleInfo() { page += FPSTR(HTTP_STYLE); page += _customHeadElement; page += FPSTR(HTTP_HEAD_END); - page += F("
"); + + page += "
"; + reportStatus(page); + page +="
"; + // @todo add versioning here + + page += F("

esp8266


"); page += F("
Chip ID
"); page += ESP.getChipId(); page += F("
"); + page += F("
Flash Chip ID
"); page += ESP.getFlashChipId(); page += F("
"); + page += F("
IDE Flash Size
"); page += ESP.getFlashChipSize(); page += F(" bytes
"); - page += F("
Real Flash Size
"); + + page += F("
Actual Flash Size
"); page += ESP.getFlashChipRealSize(); page += F(" bytes
"); - page += F("
Soft AP IP
"); + + page += F("
SDK Version
"); + page += system_get_sdk_version(); + page += F("
"); + + page += F("
Core Version
"); + page += ESP.getCoreVersion(); + page += F("
"); + + page += F("
Boot Version
"); + page += system_get_boot_version(); + page += F("
"); + + page += F("
CPU Frequency
"); + page += ESP.getCpuFreqMHz(); + page += F("MHz
"); + + // heap is dynamic, would have to have a known starting for graph + // uint32_t heapstart = 47000; + // page += F("
Memory Heap
"); + // page += F("Used/Total bytes
"); + // page += (heapstart)-ESP.getFreeHeap(); + // page += "/"; + // page += (heapstart); + // page += "
"; + // page += F("
"); + + page += F("
Memory - Free Heap
"); + page += ESP.getFreeHeap(); + page += F(" bytes available
"); + + page += F("
Memory - Sketch Size
"); + page += F("Used/Total bytes
"); + page += (ESP.getSketchSize()+ESP.getFreeSketchSpace())-ESP.getFreeSketchSpace(); + page += "/"; + page += (ESP.getSketchSize()+ESP.getFreeSketchSpace()); + page += F("
"); + + page += F("
Last reset reason
"); + page += ESP.getResetReason(); + page += F("
"); + + page += F("

WiFi


Access Point IP
"); page += WiFi.softAPIP().toString(); page += F("
"); - page += F("
Soft AP MAC
"); + + page += F("
Access Point MAC
"); page += WiFi.softAPmacAddress(); page += F("
"); + + page += F("
SSID
"); + page += WiFi.SSID(); + page += F("
"); + + page += F("
Station IP
"); + page += WiFi.localIP().toString(); + page += F("
"); + page += F("
Station MAC
"); page += WiFi.macAddress(); page += F("
"); + page += F("
"); + + page += F("

Available Pages


"); + page += F(""); + page += F(""); + page += F(""); + page += F(""); + page += F(""); + page += F(""); + page += F(""); + page += F(""); + page += F(""); + page += F(""); + page += F(""); + page += F(""); + page += F(""); + page += F(""); + // @todo add callback here + page += F("
PageFunction
/Menu page.
/wifiShow WiFi scan results and enter WiFi configuration.
/wifisaveSave WiFi configuration information and configure device. Needs variables supplied.
/closeClose the configuration server and configuration WiFi network.
/iInformation page
/rDelete WiFi configuration and reboot. ESP device will not reconnect to a network until new WiFi configuration data is entered.
"); + page += F("

More information about WiFiManager at https://github.com/tzapu/WiFiManager."); page += FPSTR(HTTP_END); server->sendHeader("Content-Length", String(page.length())); @@ -780,6 +865,26 @@ void WiFiManager::handleInfo() { DEBUG_WM(F("Sent info page")); } +void WiFiManager::reportStatus(String &page){ + if (WiFi.SSID() != ""){ + page += F("Configured to connect to access point "); + page += WiFi.SSID(); + if (WiFi.status()==WL_CONNECTED){ + page += F(" and currently connected on IP "); + page += WiFi.localIP().toString(); + page += F(""); + } + else { + page += F(" but not currently connected to network."); + } + } + else { + page += F("No network currently configured."); + } +} + /** * HTTPD CALLBACK reset page */ diff --git a/WiFiManager.h b/WiFiManager.h index 40e5c0e..c5cde8e 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -221,6 +221,7 @@ class WiFiManager String toStringIp(IPAddress ip); boolean validApPassword(); String encryptionTypeStr(uint8_t authmode); + void reportStatus(String &page); boolean connect; boolean configPortalActive = false; From c6f7ac001253f3421b8606d2d92a86e3efcdb8e1 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 14 Sep 2017 10:26:51 -0500 Subject: [PATCH 041/424] added uptime to info still subject to rollover --- WiFiManager.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 0fe2c24..78ec234 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -756,6 +756,11 @@ void WiFiManager::handleInfo() { // @todo add versioning here page += F("

esp8266


"); + + page += F("
Uptime
"); + page += (String)(system_get_time() / 1000000 / 60) + " mins "; + page += (String)((system_get_time() / 1000000)%60) + " secs"; + page += F("
Chip ID
"); page += ESP.getChipId(); page += F("
"); From e43a7d0b75db446744bb0d46c3d6cd08fb544359 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 14 Sep 2017 15:38:12 -0500 Subject: [PATCH 042/424] modify templates, remove placeholders adds labels to all inputs, deprecates {p} placeholders, adds {t} to ttitles --- WiFiManager.cpp | 117 +++++++++++++++++++++++++++++------------------- WiFiManager.h | 8 ++-- 2 files changed, 76 insertions(+), 49 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 78ec234..d545b36 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -592,78 +592,103 @@ void WiFiManager::handleWifi(boolean scan) { } } - page += FPSTR(HTTP_FORM_START); - char parLength[5]; - // add the extra parameters to the form - for (int i = 0; i < _paramsCount; i++) { - if (_params[i] == NULL) { - break; - } + String pitem = FPSTR(HTTP_FORM_START); + pitem.replace("{v}", WiFi.SSID()); + page += pitem; - //String pitem = FPSTR(HTTP_FORM_PARAM); - String pitem; - switch (_params[i]->getLabelPlacement()) { - case WFM_LABEL_BEFORE: - pitem = FPSTR(HTTP_FORM_LABEL); - pitem += FPSTR(HTTP_FORM_PARAM); - break; - case WFM_LABEL_AFTER: - pitem = FPSTR(HTTP_FORM_PARAM); - pitem += FPSTR(HTTP_FORM_LABEL); - break; - default: - // WFM_NO_LABEL - pitem = FPSTR(HTTP_FORM_PARAM); - break; - } - if (_params[i]->getID() != NULL) { - pitem.replace("{i}", _params[i]->getID()); - pitem.replace("{n}", _params[i]->getID()); - pitem.replace("{p}", _params[i]->getPlaceholder()); - snprintf(parLength, 5, "%d", _params[i]->getValueLength()); - pitem.replace("{l}", parLength); - pitem.replace("{v}", _params[i]->getValue()); - pitem.replace("{c}", _params[i]->getCustomHTML()); // additional attributes not html - } else { - pitem = _params[i]->getCustomHTML(); - } - page += pitem; - } - if (_params[0] != NULL) { - page += "
"; + if(_paramsCount > 0){ + + page += FPSTR(HTTP_FORM_PARAM_START); + + char parLength[5]; + // add the extra parameters to the form + for (int i = 0; i < _paramsCount; i++) { + if (_params[i] == NULL) { + break; + } + + String pitem; + switch (_params[i]->getLabelPlacement()) { + case WFM_LABEL_BEFORE: + pitem = FPSTR(HTTP_FORM_LABEL); + pitem += FPSTR(HTTP_FORM_PARAM); + break; + case WFM_LABEL_AFTER: + pitem = FPSTR(HTTP_FORM_PARAM); + pitem += FPSTR(HTTP_FORM_LABEL); + break; + default: + // WFM_NO_LABEL + pitem = FPSTR(HTTP_FORM_PARAM); + break; + } + if (_params[i]->getID() != NULL) { + pitem.replace("{i}", _params[i]->getID()); + pitem.replace("{n}", _params[i]->getID()); + pitem.replace("{p}", "{t}"); + pitem.replace("{t}", _params[i]->getPlaceholder()); + snprintf(parLength, 5, "%d", _params[i]->getValueLength()); + pitem.replace("{l}", parLength); + pitem.replace("{v}", _params[i]->getValue()); + pitem.replace("{c}", _params[i]->getCustomHTML()); // additional attributes not html + } else { + pitem = _params[i]->getCustomHTML(); + } + + page += pitem; + } + if (_params[0] != NULL) { + page += FPSTR(HTTP_FORM_PARAM_END); + } } if (_sta_show_static_fields || _sta_static_ip) { - String item = FPSTR(HTTP_FORM_PARAM); + // @todo how do we get these settings from memory , wifi_get_ip_info does not seem to reveal if struct ip_info is static or not + // @todo move titles to params for i18n + + String item = FPSTR(HTTP_FORM_LABEL); + item += FPSTR(HTTP_FORM_PARAM); item.replace("{i}", "ip"); item.replace("{n}", "ip"); - item.replace("{p}", "Static IP"); + item.replace("{p}", "{t}"); + item.replace("{t}", "Static IP"); item.replace("{l}", "15"); item.replace("{v}", (_sta_static_ip ? _sta_static_ip.toString() : "")); + // IPAddress sta_ip = WiFi.localIP(); + // item.replace("{p}", sta_ip.toString()); + page += item; - item = FPSTR(HTTP_FORM_PARAM); + item = FPSTR(HTTP_FORM_LABEL); + item += FPSTR(HTTP_FORM_PARAM); item.replace("{i}", "gw"); item.replace("{n}", "gw"); - item.replace("{p}", "Static Gateway"); + item.replace("{p}", "{t}"); + item.replace("{t}", "Static Gateway"); item.replace("{l}", "15"); item.replace("{v}", (_sta_static_gw ? _sta_static_gw.toString() : "")); + // IPAddress sta_gateway = WiFi.gatewayIP(); + // item.replace("{p}", sta_gateway.toString()); + page += item; - item = FPSTR(HTTP_FORM_PARAM); + item = FPSTR(HTTP_FORM_LABEL); + item += FPSTR(HTTP_FORM_PARAM); item.replace("{i}", "sn"); item.replace("{n}", "sn"); - item.replace("{p}", "Subnet"); + item.replace("{p}", "{t}"); + item.replace("{t}", "Subnet"); item.replace("{l}", "15"); item.replace("{v}", (_sta_static_sn ? _sta_static_sn.toString() : "")); + // IPAddress sta_subnet = WiFi.subnetMask(); + // item.replace("{p}", sta_subnet.toString()); page += item; - - page += "
"; + page += "
"; // @todo remove these, use css } page += FPSTR(HTTP_FORM_END); diff --git a/WiFiManager.h b/WiFiManager.h index c5cde8e..01ac0f6 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -47,10 +47,12 @@ const char HTTP_HEAD_END[] PROGMEM = "
"; const char HTTP_PORTAL_OPTIONS[] PROGMEM = "



"; const char HTTP_ITEM[] PROGMEM = ""; //const char HTTP_ITEM_PADLOCK[] PROGMEM = ""; -const char HTTP_FORM_START[] PROGMEM = "


"; -const char HTTP_FORM_LABEL[] PROGMEM = ""; -const char HTTP_FORM_PARAM[] PROGMEM = "
"; +const char HTTP_FORM_START[] PROGMEM = "

"; const char HTTP_FORM_END[] PROGMEM = "
"; +const char HTTP_FORM_LABEL[] PROGMEM = ""; +const char HTTP_FORM_PARAM_START[] PROGMEM = "
"; +const char HTTP_FORM_PARAM[] PROGMEM = "
"; +const char HTTP_FORM_PARAM_END[] PROGMEM = "
"; 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_END[] PROGMEM = "
"; From 37dbd667f4f7cdd7da25d00b2cdd32e1a4679627 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 14 Sep 2017 15:38:42 -0500 Subject: [PATCH 043/424] add staticfield setter --- WiFiManager.cpp | 5 +++++ WiFiManager.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index d545b36..d896650 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1012,6 +1012,11 @@ void WiFiManager::setRestorePersistent(boolean persistent) { if(!persistent) DEBUG_WM(F("persistent is off")); } +void WiFiManager::setShowStaticFields(boolean alwaysShow){ + _sta_show_static_fields = alwaysShow; +} + + // HELPERS template diff --git a/WiFiManager.h b/WiFiManager.h index 01ac0f6..788a004 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -145,6 +145,8 @@ class WiFiManager void setRemoveDuplicateAPs(boolean removeDuplicates); //setter for ESP wifi.persistent so we can remember it and restore user preference, as WIFi._persistent is protected void setRestorePersistent(boolean persistent); + //if true, always show static net inputs, IP, subnet, gateway, if false, only show when already set. + void setShowStaticFields(boolean alwaysShow); private: std::unique_ptr dnsServer; From 4d18bfb113c1eb565f197f1b3f8c246760e477bc Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 14 Sep 2017 16:34:16 -0500 Subject: [PATCH 044/424] abstracted outputters --- WiFiManager.cpp | 134 +++++++++++++++++++++++++++--------------------- WiFiManager.h | 4 ++ 2 files changed, 80 insertions(+), 58 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index d896650..5e6fdc5 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -514,6 +514,29 @@ void WiFiManager::handleWifi(boolean scan) { page += FPSTR(HTTP_HEAD_END); if (scan) { + page += getScanItemOut(); + } + + String pitem = FPSTR(HTTP_FORM_START); + pitem.replace("{v}", WiFi.SSID()); + page += pitem; + + page += getStaticOut(); + page += getParamOut(); + + page += FPSTR(HTTP_FORM_END); + page += FPSTR(HTTP_SCAN_LINK); + page += FPSTR(HTTP_END); + + server->sendHeader("Content-Length", String(page.length())); + server->send(200, "text/html", page); + + DEBUG_WM(F("Sent config page")); +} + +String WiFiManager::getScanItemOut(){ + String page; + int n = WiFi.scanNetworks(); DEBUG_WM(F("Scan done")); if (n == 0) { @@ -590,59 +613,11 @@ void WiFiManager::handleWifi(boolean scan) { } page += "
"; } - } - - String pitem = FPSTR(HTTP_FORM_START); - pitem.replace("{v}", WiFi.SSID()); - page += pitem; - - - if(_paramsCount > 0){ - - page += FPSTR(HTTP_FORM_PARAM_START); - - char parLength[5]; - // add the extra parameters to the form - for (int i = 0; i < _paramsCount; i++) { - if (_params[i] == NULL) { - break; - } - - String pitem; - switch (_params[i]->getLabelPlacement()) { - case WFM_LABEL_BEFORE: - pitem = FPSTR(HTTP_FORM_LABEL); - pitem += FPSTR(HTTP_FORM_PARAM); - break; - case WFM_LABEL_AFTER: - pitem = FPSTR(HTTP_FORM_PARAM); - pitem += FPSTR(HTTP_FORM_LABEL); - break; - default: - // WFM_NO_LABEL - pitem = FPSTR(HTTP_FORM_PARAM); - break; - } - if (_params[i]->getID() != NULL) { - pitem.replace("{i}", _params[i]->getID()); - pitem.replace("{n}", _params[i]->getID()); - pitem.replace("{p}", "{t}"); - pitem.replace("{t}", _params[i]->getPlaceholder()); - snprintf(parLength, 5, "%d", _params[i]->getValueLength()); - pitem.replace("{l}", parLength); - pitem.replace("{v}", _params[i]->getValue()); - pitem.replace("{c}", _params[i]->getCustomHTML()); // additional attributes not html - } else { - pitem = _params[i]->getCustomHTML(); - } - - page += pitem; - } - if (_params[0] != NULL) { - page += FPSTR(HTTP_FORM_PARAM_END); - } - } + return page; +} +String WiFiManager::getStaticOut(){ + String page; if (_sta_show_static_fields || _sta_static_ip) { // @todo how do we get these settings from memory , wifi_get_ip_info does not seem to reveal if struct ip_info is static or not @@ -690,15 +665,58 @@ void WiFiManager::handleWifi(boolean scan) { page += item; page += "
"; // @todo remove these, use css } + return page; +} - page += FPSTR(HTTP_FORM_END); - page += FPSTR(HTTP_SCAN_LINK); - page += FPSTR(HTTP_END); +String WiFiManager::getParamOut(){ + String page; - server->sendHeader("Content-Length", String(page.length())); - server->send(200, "text/html", page); + if(_paramsCount > 0){ - DEBUG_WM(F("Sent config page")); + page += FPSTR(HTTP_FORM_PARAM_START); + + char parLength[5]; + // add the extra parameters to the form + for (int i = 0; i < _paramsCount; i++) { + if (_params[i] == NULL) { + break; + } + + String pitem; + switch (_params[i]->getLabelPlacement()) { + case WFM_LABEL_BEFORE: + pitem = FPSTR(HTTP_FORM_LABEL); + pitem += FPSTR(HTTP_FORM_PARAM); + break; + case WFM_LABEL_AFTER: + pitem = FPSTR(HTTP_FORM_PARAM); + pitem += FPSTR(HTTP_FORM_LABEL); + break; + default: + // WFM_NO_LABEL + pitem = FPSTR(HTTP_FORM_PARAM); + break; + } + if (_params[i]->getID() != NULL) { + pitem.replace("{i}", _params[i]->getID()); + pitem.replace("{n}", _params[i]->getID()); + pitem.replace("{p}", "{t}"); + pitem.replace("{t}", _params[i]->getPlaceholder()); + snprintf(parLength, 5, "%d", _params[i]->getValueLength()); + pitem.replace("{l}", parLength); + pitem.replace("{v}", _params[i]->getValue()); + pitem.replace("{c}", _params[i]->getCustomHTML()); // additional attributes not html + } else { + pitem = _params[i]->getCustomHTML(); + } + + page += pitem; + } + if (_params[0] != NULL) { + page += FPSTR(HTTP_FORM_PARAM_END); + } + } + return page; } /** diff --git a/WiFiManager.h b/WiFiManager.h index 788a004..7535feb 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -216,6 +216,10 @@ class WiFiManager bool wifimode(WiFiMode_t m); bool wifioff(); + String getParamOut(); + String getScanItemOut(); + String getStaticOut(); + // DNS server const byte DNS_PORT = 53; From 31ab2b67d0120267ffc4c79bef118cb97bfb061d Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 14 Sep 2017 17:09:17 -0500 Subject: [PATCH 045/424] ability to disable captiveportal Sometimes the redirect to captive portal is unwanted or a nuisance, eg wehn using as a webserver etc. --- WiFiManager.cpp | 8 +++++++- WiFiManager.h | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 5e6fdc5..7b9ddb4 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -536,7 +536,7 @@ void WiFiManager::handleWifi(boolean scan) { String WiFiManager::getScanItemOut(){ String page; - + int n = WiFi.scanNetworks(); DEBUG_WM(F("Scan done")); if (n == 0) { @@ -987,6 +987,9 @@ void WiFiManager::handleNotFound() { */ boolean WiFiManager::captivePortal() { DEBUG_WM(server->hostHeader()); + + if(!_enableCaptivePortal) return true; // skip redirections + if (!isIp(server->hostHeader())) { DEBUG_WM(F("Request redirected to captive portal")); server->sendHeader("Location", String("http://") + toStringIp(server->client().localIP()), true); @@ -1034,6 +1037,9 @@ void WiFiManager::setShowStaticFields(boolean alwaysShow){ _sta_show_static_fields = alwaysShow; } +void WiFiManager::setCaptivePortalEnable(boolean enabled){ + _enableCaptivePortal = enabled; +} // HELPERS diff --git a/WiFiManager.h b/WiFiManager.h index 7535feb..0be462f 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -148,6 +148,8 @@ class WiFiManager //if true, always show static net inputs, IP, subnet, gateway, if false, only show when already set. void setShowStaticFields(boolean alwaysShow); + void setCaptivePortalEnable(boolean enabled); + private: std::unique_ptr dnsServer; std::unique_ptr server; @@ -175,6 +177,7 @@ class WiFiManager unsigned long _configPortalStart = 0; boolean _userpersistent = true; WiFiMode_t _usermode = WIFI_OFF; + boolean _enableCaptivePortal = true; IPAddress _ap_static_ip; IPAddress _ap_static_gw; From 80470fb553011d72e1d27b3455b5099907193aa1 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sat, 16 Sep 2017 10:39:51 -0500 Subject: [PATCH 046/424] addd token precheck flags This helps skip token replacements that are not even used, replace is slow, this is an optimization mostly for large sets of params or aps. --- WiFiManager.cpp | 63 ++++++++++++++++++++++++++++++++----------------- WiFiManager.h | 5 ++-- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 7b9ddb4..c4286bc 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -581,27 +581,36 @@ String WiFiManager::getScanItemOut(){ } } + // token precheck, to speed up replacements on large ap lists + String HTTP_ITEM_STR = FPSTR(HTTP_ITEM); + bool tok_r = HTTP_ITEM_STR.indexOf("{r}") > 0; + bool tok_R = HTTP_ITEM_STR.indexOf("{R}") > 0; + bool tok_e = HTTP_ITEM_STR.indexOf("{e}") > 0; + bool tok_q = HTTP_ITEM_STR.indexOf("{q}") > 0; + bool tok_i = HTTP_ITEM_STR.indexOf("{i}") > 0; + //display networks in page for (int i = 0; i < n; i++) { if (indices[i] == -1) continue; // skip dups - DEBUG_WM(WiFi.SSID(indices[i])); - DEBUG_WM(WiFi.RSSI(indices[i])); - int quality = getRSSIasQuality(WiFi.RSSI(indices[i])); + + DEBUG_WM("AP: " + (String)WiFi.RSSI(indices[i]) + " " + (String)WiFi.SSID(indices[i])); + + int rssiperc = getRSSIasQuality(WiFi.RSSI(indices[i])); uint8_t enc_type = WiFi.encryptionType(indices[i]); - if (_minimumQuality == -1 || _minimumQuality < quality) { + if (_minimumQuality == -1 || _minimumQuality < rssiperc) { String item = FPSTR(HTTP_ITEM); - String rssiQ; - rssiQ += quality; item.replace("{v}", WiFi.SSID(indices[i])); // ssid no encoding - item.replace("{R}", (String)WiFi.RSSI(indices[i])); // rssi - item.replace("{e}", encryptionTypeStr(enc_type)); - item.replace("{r}", rssiQ); // qualitypercent - item.replace("{q}", (String)round(map(quality,0,100,1,4))); //quality icon 1-4 - if (enc_type != ENC_TYPE_NONE) { - item.replace("{i}", "l"); - } else { - item.replace("{i}", ""); + if(tok_e) item.replace("{e}", encryptionTypeStr(enc_type)); + if(tok_r) item.replace("{r}", (String)rssiperc); // rssi percentage 0-100 + if(tok_R) item.replace("{R}", (String)WiFi.RSSI(indices[i])); // rssi db + if(tok_q) item.replace("{q}", (String)round(map(rssiperc,0,100,1,4))); //quality icon 1-4 + if(tok_i){ + if (enc_type != ENC_TYPE_NONE) { + item.replace("{i}", "l"); + } else { + item.replace("{i}", ""); + } } //DEBUG_WM(item); page += item; @@ -613,6 +622,7 @@ String WiFiManager::getScanItemOut(){ } page += "
"; } + return page; } @@ -673,6 +683,16 @@ String WiFiManager::getParamOut(){ if(_paramsCount > 0){ + String HTTP_PARAM_temp = FPSTR(HTTP_FORM_LABEL); + HTTP_PARAM_temp += FPSTR(HTTP_FORM_PARAM); + bool tok_i = HTTP_PARAM_temp.indexOf("{i}") > 0; + bool tok_n = HTTP_PARAM_temp.indexOf("{n}") > 0; + bool tok_p = HTTP_PARAM_temp.indexOf("{p}") > 0; + bool tok_t = HTTP_PARAM_temp.indexOf("{t}") > 0; + bool tok_l = HTTP_PARAM_temp.indexOf("{l}") > 0; + bool tok_v = HTTP_PARAM_temp.indexOf("{v}") > 0; + bool tok_c = HTTP_PARAM_temp.indexOf("{c}") > 0; + page += FPSTR(HTTP_FORM_PARAM_START); char parLength[5]; @@ -698,14 +718,14 @@ String WiFiManager::getParamOut(){ break; } if (_params[i]->getID() != NULL) { - pitem.replace("{i}", _params[i]->getID()); - pitem.replace("{n}", _params[i]->getID()); - pitem.replace("{p}", "{t}"); - pitem.replace("{t}", _params[i]->getPlaceholder()); + if(tok_i)pitem.replace("{i}", _params[i]->getID()); + if(tok_n)pitem.replace("{n}", _params[i]->getID()); + if(tok_p)pitem.replace("{p}", "{t}"); + if(tok_t)pitem.replace("{t}", _params[i]->getPlaceholder()); snprintf(parLength, 5, "%d", _params[i]->getValueLength()); - pitem.replace("{l}", parLength); - pitem.replace("{v}", _params[i]->getValue()); - pitem.replace("{c}", _params[i]->getCustomHTML()); // additional attributes not html + if(tok_l)pitem.replace("{l}", parLength); + if(tok_v)pitem.replace("{v}", _params[i]->getValue()); + if(tok_c)pitem.replace("{c}", _params[i]->getCustomHTML()); // meant for additional attributes, not html } else { pitem = _params[i]->getCustomHTML(); } @@ -716,6 +736,7 @@ String WiFiManager::getParamOut(){ page += FPSTR(HTTP_FORM_PARAM_END); } } + return page; } diff --git a/WiFiManager.h b/WiFiManager.h index 0be462f..95ce014 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -45,11 +45,12 @@ const char HTTP_STYLE[] PROGMEM = ""; const char HTTP_STYLE[] PROGMEM = ""; const char HTTP_STYLE[] PROGMEM = ""; @@ -113,6 +121,7 @@ class WiFiManager String getConfigPortalSSID(); void resetSettings(); + void reboot(); //sets timeout before AP,webserver loop ends and exits even if there has been no setup. //useful for devices that failed to connect at some point and got stuck in a webserver loop @@ -227,7 +236,7 @@ class WiFiManager bool WiFi_Disconnect(); bool WiFi_enableSTA(bool enable); bool WiFi_enableSTA(bool enable,bool persistent); - bool ESP_eraseConfig(); + bool WiFi_eraseConfig(); void debugSoftAPConfig(); String getParamOut(); From 90024b8603172c8d51f1e382d0db69ab53ed49e8 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 23 Jan 2018 13:28:49 -0600 Subject: [PATCH 079/424] adding def blocks, nonworking adding conditionals for all module types, there has been requests for other module support in addition to esp32, so I ma just gonna go ahead and avoid else fallbacks for now. Not working yet. --- WiFiManager.cpp | 155 ++++++++++++++++++++++++++++++------------------ WiFiManager.h | 17 ++++-- 2 files changed, 111 insertions(+), 61 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 7aeafe5..c195611 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -465,7 +465,11 @@ uint8_t WiFiManager::waitForConnectResult() { void WiFiManager::startWPS() { DEBUG_WM("START WPS"); - WiFi.beginWPSConfig(); + #ifdef ESP8266 + WiFi.beginWPSConfig(); + #else + // @todo + #endif DEBUG_WM("END WPS"); } @@ -1339,34 +1343,57 @@ String WiFiManager::getWLStatusString(uint8_t status){ } String WiFiManager::encryptionTypeStr(uint8_t authmode) { - switch(authmode) { - case ENC_TYPE_NONE: - return "None"; - case ENC_TYPE_WEP: - return "WEP"; - case ENC_TYPE_TKIP: - return "WPA_PSK"; - case ENC_TYPE_CCMP: - return "WPA2_PSK"; - case ENC_TYPE_AUTO: - return "WPA_WPA2_PSK"; - default: - return "Unknown"; - } + #ifdef ESP8266 + switch(authmode) { + case ENC_TYPE_NONE: + return "None"; + case ENC_TYPE_WEP: + return "WEP"; + case ENC_TYPE_TKIP: + return "WPA_PSK"; + case ENC_TYPE_CCMP: + return "WPA2_PSK"; + case ENC_TYPE_AUTO: + return "WPA_WPA2_PSK"; + default: + return "Unknown"; + } + #elif defined(ESP31B) || defined(ESP32) + switch(authmode) { + case WIFI_AUTH_OPEN: + return "None"; + case WIFI_AUTH_WEP: + return "WEP"; + case WIFI_AUTH_WPA_PSK: + return "WPA_PSK"; + case WIFI_AUTH_WPA_WPA2_PSK: + return "WPA2_PSK"; + case WIFI_AUTH_WPA2_ENTERPRISE: + return "WPA_WPA2_ENTERPRISE"; + case WIFI_AUTH_MAX: + return "MAX"; + default: + return "Unknown"; + } + #endif } // set mode ignores WiFi.persistent bool WiFiManager::WiFi_Mode(WiFiMode_t m,bool persistent) { - if((wifi_get_opmode() == (uint8) m ) && !persistent) { - return true; - } - bool ret; - ETS_UART_INTR_DISABLE(); - if(persistent) ret = wifi_set_opmode(m); - else ret = wifi_set_opmode_current(m); - ETS_UART_INTR_ENABLE(); + #ifdef ESP8266 + if((wifi_get_opmode() == (uint8) m ) && !persistent) { + return true; + } + bool ret; + ETS_UART_INTR_DISABLE(); + if(persistent) ret = wifi_set_opmode(m); + else ret = wifi_set_opmode_current(m); + ETS_UART_INTR_ENABLE(); - return ret; + return ret; + #elif defined(ESP31B) || defined(ESP32) + return WiFi.mode(m); // @todo persistent not implemented? + #endif } bool WiFiManager::WiFi_Mode(WiFiMode_t m) { return WiFi_Mode(m,false); @@ -1374,51 +1401,65 @@ bool WiFiManager::WiFi_Mode(WiFiMode_t m) { // sta disconnect without persistent bool WiFiManager::WiFi_Disconnect() { - if((WiFi.getMode() & WIFI_STA) != 0) { - bool ret; - DEBUG_WM(F("wifi station disconnect")); - ETS_UART_INTR_DISABLE(); - ret = wifi_station_disconnect(); - ETS_UART_INTR_ENABLE(); - return ret; - } + #ifdef ESP8266 + if((WiFi.getMode() & WIFI_STA) != 0) { + bool ret; + DEBUG_WM(F("wifi station disconnect")); + ETS_UART_INTR_DISABLE(); + ret = wifi_station_disconnect(); + ETS_UART_INTR_ENABLE(); + return ret; + } + #elif defined(ESP31B) || defined(ESP32) + DEBUG_WM(F("wifi station disconnect")); + // @todo why does disconnect call these, might be needed + // WiFi.getMode(); // wifiLowLevelInit() + // esp_wifi_start(); + return esp_wifi_disconnect() == ESP_OK; + #endif } // toggle STA without persistent bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) { + #ifdef ESP8266 + WiFiMode_t currentMode = WiFi.getMode(); + bool isEnabled = ((currentMode & WIFI_STA) != 0); - WiFiMode_t currentMode = WiFi.getMode(); - bool isEnabled = ((currentMode & WIFI_STA) != 0); - - if((isEnabled != enable) || persistent) { - if(enable) { - if(persistent) DEBUG_WM(F("enableSTA PERSISTENT ON")); - return WiFi_Mode((WiFiMode_t)(currentMode | WIFI_STA),persistent); - } else { - return WiFi_Mode((WiFiMode_t)(currentMode & (~WIFI_STA)),persistent); - } - } else { - return true; - } + if((isEnabled != enable) || persistent) { + if(enable) { + if(persistent) DEBUG_WM(F("enableSTA PERSISTENT ON")); + return WiFi_Mode((WiFiMode_t)(currentMode | WIFI_STA),persistent); + } else { + return WiFi_Mode((WiFiMode_t)(currentMode & (~WIFI_STA)),persistent); + } + } else { + return true; + } + #elif defined(ESP31B) || defined(ESP32) + return WiFi.mode(m); // @todo persistent not implemented? + #endif } bool WiFiManager::WiFi_enableSTA(bool enable) { return WiFi_enableSTA(enable,false); } -// erase config BUG polyfill -// https://github.com/esp8266/Arduino/pull/3635 bool WiFiManager::WiFi_eraseConfig(void) { - // return ESP.eraseConfig(); + #ifdef ESP8266 + return ESP.eraseConfig(); + // https://github.com/esp8266/Arduino/pull/3635 + // erase config BUG polyfill + // const size_t cfgSize = 0x4000; + // size_t cfgAddr = ESP.getFlashChipSize() - cfgSize; - const size_t cfgSize = 0x4000; - size_t cfgAddr = ESP.getFlashChipSize() - cfgSize; - - for (size_t offset = 0; offset < cfgSize; offset += SPI_FLASH_SEC_SIZE) { - if (!ESP.flashEraseSector((cfgAddr + offset) / SPI_FLASH_SEC_SIZE)) { - return false; - } - } - return true; + // for (size_t offset = 0; offset < cfgSize; offset += SPI_FLASH_SEC_SIZE) { + // if (!ESP.flashEraseSector((cfgAddr + offset) / SPI_FLASH_SEC_SIZE)) { + // return false; + // } + // } + // return true; + #else + // @todo + #endif } void WiFiManager::reboot(){ diff --git a/WiFiManager.h b/WiFiManager.h index 1b02b56..1c7e99e 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -13,22 +13,31 @@ #ifndef WiFiManager_h #define WiFiManager_h -#if defined(ESP8266) +#ifdef ESP8266 #include #include +#elif defined(ESP31B) || defined(ESP32) + #include +#else #endif #include #include -#if defined(ESP8266) +#ifdef ESP8266 extern "C" { #include "user_interface.h" } #endif -#define WIFI_getChipId() ESP.getChipId() -#define WIFI_AUTH_OPEN ENC_TYPE_NONE +#ifdef ESP8266 + #define WIFI_getChipId() ESP.getChipId() + #define WIFI_AUTH_OPEN ENC_TYPE_NONE +#elif defined(ESP31B) || defined(ESP32) + #define WIFI_getChipId() (uint32_t)ESP.getEfuseMac() + #define WIFI_AUTH_OPEN WIFI_AUTH_OPEN +#else +#endif const char HTTP_HEAD[] PROGMEM = "{v}"; // const char HTTP_STYLE[] PROGMEM = ""; From f3be7c7c0b6f020986a48e51ee3d9954387618f6 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 23 Jan 2018 14:07:33 -0600 Subject: [PATCH 080/424] it compiles --- WiFiManager.cpp | 19 ++++++++++++++----- WiFiManager.h | 7 ++++++- .../OnDemandConfigPortal.ino | 9 +++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index c195611..033d7a7 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -178,10 +178,10 @@ void WiFiManager::stopWebPortal() { } boolean WiFiManager::configPortalHasTimeout(){ - if(_configPortalTimeout == 0 || wifi_softap_get_station_num() > 0){ + if(_configPortalTimeout == 0 ){ //|| wifi_softap_get_station_num() > 0){ if(millis() - timer > 30000){ timer = millis(); - DEBUG_WM("NUM CLIENTS: " + (String)wifi_softap_get_station_num()); + // DEBUG_WM("NUM CLIENTS: " + (String)wifi_softap_get_station_num()); } _configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts return false; @@ -206,7 +206,11 @@ void WiFiManager::setupConfigPortal() { // setup dns and web servers dnsServer.reset(new DNSServer()); - server.reset(new ESP8266WebServer(80)); + #ifdef ESP8266 + server.reset(new ESP8266WebServer(80)); + #elif defined(ESP31B) || defined(ESP32) + server.reset(new WebServer(80)); + #endif /* Setup the DNS server redirecting all the domains to the apIP */ dnsServer->setErrorReplyCode(DNSReplyCode::NoError); @@ -884,6 +888,7 @@ void WiFiManager::handleInfo() { // @todo add versioning here + #ifdef ESP8266 page += F("

esp8266


"); // subject to rollover! @@ -1001,6 +1006,7 @@ void WiFiManager::handleInfo() { page += F(""); page += F("
"); + #endif page += "
"; page += F("

Available Pages


"); @@ -1260,6 +1266,7 @@ void WiFiManager::DEBUG_WM(Generic text,Genericb textb) { */ void WiFiManager::debugSoftAPConfig(){ + #ifdef ESP8266 softap_config config; wifi_softap_get_config(&config); @@ -1274,6 +1281,7 @@ void WiFiManager::debugSoftAPConfig(){ DEBUG_WM(F("max_connection: "),config.max_connection); DEBUG_WM(F("beacon_interval: "),(String)config.beacon_interval + "(ms)"); DEBUG_WM(F("--------------------")); + #endif } @@ -1415,7 +1423,8 @@ bool WiFiManager::WiFi_Disconnect() { // @todo why does disconnect call these, might be needed // WiFi.getMode(); // wifiLowLevelInit() // esp_wifi_start(); - return esp_wifi_disconnect() == ESP_OK; + // return esp_wifi_disconnect() == ESP_OK; // @todo BUG not declared in scope + return WiFi.disconnect(); #endif } @@ -1436,7 +1445,7 @@ bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) { return true; } #elif defined(ESP31B) || defined(ESP32) - return WiFi.mode(m); // @todo persistent not implemented? + return WiFi.mode(WIFI_STA); // @todo persistent not implemented? #endif } bool WiFiManager::WiFi_enableSTA(bool enable) { diff --git a/WiFiManager.h b/WiFiManager.h index 1c7e99e..29e8cda 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -18,6 +18,7 @@ #include #elif defined(ESP31B) || defined(ESP32) #include + #include #else #endif @@ -173,7 +174,11 @@ class WiFiManager private: std::unique_ptr dnsServer; - std::unique_ptr server; + #ifdef ESP8266 + std::unique_ptr server; + #elif defined(ESP31B) || defined(ESP32) + std::unique_ptr server; + #endif //const int WM_DONE = 0; //const int WM_WAIT = 10; diff --git a/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino index 1292c35..1cb8205 100644 --- a/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -1,7 +1,12 @@ +#ifdef ESP8266 #include //https://github.com/esp8266/Arduino - //needed for library #include +#else +#include +#include +#endif + #include #include //https://github.com/tzapu/WiFiManager @@ -49,7 +54,7 @@ void loop() { Serial.println("failed to connect and hit timeout"); delay(3000); //reset and try again, or maybe put it to deep sleep - ESP.reset(); + ESP.restart(); delay(5000); } From 2af1c62bd11c4aa6c6443f7d808ca81bb2da0b0d Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 24 Jan 2018 08:27:56 -0600 Subject: [PATCH 081/424] redo esp32 disconnect --- WiFiManager.cpp | 8 ++++---- WiFiManager.h | 1 + examples/OnDemandConfigPortal/OnDemandConfigPortal.ino | 5 +++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 033d7a7..584c131 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1421,10 +1421,10 @@ bool WiFiManager::WiFi_Disconnect() { #elif defined(ESP31B) || defined(ESP32) DEBUG_WM(F("wifi station disconnect")); // @todo why does disconnect call these, might be needed - // WiFi.getMode(); // wifiLowLevelInit() - // esp_wifi_start(); - // return esp_wifi_disconnect() == ESP_OK; // @todo BUG not declared in scope - return WiFi.disconnect(); + // WiFi.getMode(); // @todo wifiLowLevelInit(), probably not needed, for save config only + // esp_wifi_start(); // @todo can only disconnect if enabled perhaps, prevent failure, or correct for previous call ? + return esp_wifi_disconnect() == ESP_OK; + // return WiFi.disconnect(); #endif } diff --git a/WiFiManager.h b/WiFiManager.h index 29e8cda..45a0e37 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -19,6 +19,7 @@ #elif defined(ESP31B) || defined(ESP32) #include #include + #include #else #endif diff --git a/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino index 1cb8205..617b0f0 100644 --- a/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -14,6 +14,7 @@ // ESP-01 users please note: the only pins available (0 and 2), are shared // with the bootloader, so always set them HIGH at power-up #define TRIGGER_PIN 0 +const char* modes[] = { "NULL", "STA", "AP", "STA+AP" }; void setup() { @@ -21,6 +22,10 @@ void setup() { Serial.begin(115200); Serial.println("\n Starting"); + Serial.setDebugOutput(true); + Serial.println(modes[WiFi.getMode()]); + WiFi.printDiag(Serial); + pinMode(TRIGGER_PIN, INPUT); } From 2a50d797a06210cc531578b26e926eec44c59d2f Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 24 Jan 2018 08:50:24 -0600 Subject: [PATCH 082/424] fix esp32 softap numclients --- WiFiManager.cpp | 12 ++++++++++-- WiFiManager.h | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 584c131..bec013a 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -178,10 +178,10 @@ void WiFiManager::stopWebPortal() { } boolean WiFiManager::configPortalHasTimeout(){ - if(_configPortalTimeout == 0 ){ //|| wifi_softap_get_station_num() > 0){ + if(_configPortalTimeout == 0 || WiFi_softap_num_stations() > 0){ if(millis() - timer > 30000){ timer = millis(); - // DEBUG_WM("NUM CLIENTS: " + (String)wifi_softap_get_station_num()); + DEBUG_WM("NUM CLIENTS: " + (String)WiFi_softap_num_stations()); } _configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts return false; @@ -1473,4 +1473,12 @@ bool WiFiManager::WiFi_eraseConfig(void) { void WiFiManager::reboot(){ ESP.restart(); +} + +uint8_t WiFiManager::WiFi_softap_num_stations(){ + #ifdef ESP8266 + return wifi_softap_get_station_num(); + #elif defined(ESP31B) || defined(ESP32) + return WiFi.softAPgetStationNum(); + #endif } \ No newline at end of file diff --git a/WiFiManager.h b/WiFiManager.h index 45a0e37..ee7d805 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -253,7 +253,8 @@ class WiFiManager bool WiFi_enableSTA(bool enable,bool persistent); bool WiFi_eraseConfig(); void debugSoftAPConfig(); - + uint8_t WiFi_softap_num_stations(); + String getParamOut(); String getScanItemOut(); String getStaticOut(); From e5879b2101f13c20f2cd84cde73da2bd17b01670 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 24 Jan 2018 11:05:28 -0600 Subject: [PATCH 083/424] fix esp32 autoconnect --- WiFiManager.cpp | 29 ++++++++++++++++++++++------- WiFiManager.h | 4 +++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index bec013a..60305fe 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -98,7 +98,7 @@ WiFiManager::WiFiManager():_debugPort(Serial) { // destructor WiFiManager::~WiFiManager() { if(_userpersistent) WiFi.persistent(true); // reenable persistent, there is no getter we rely on _userpersistent - WiFi.mode(_usermode); + if(_usermode != WIFI_OFF) WiFi.mode(_usermode); DEBUG_WM(F("unloading")); } @@ -114,6 +114,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { // attempt to connect using saved settings, on fail fallback to AP config portal WiFi_enableSTA(true); + _usermode = WIFI_STA; // if already connected, or try stored connect if (WiFi.status() == WL_CONNECTED || connectWifi("", "") == WL_CONNECTED) { @@ -325,17 +326,19 @@ uint8_t WiFiManager::handleConfigPortal(){ // Waiting for save... if (connect) { connect = false; - delay(2000); - DEBUG_WM(F("Connecting save WiFi")); + DEBUG_WM(F("Connecting to a new AP")); // attempt sta connection to submitted _ssid, _pass if (connectWifi(_ssid, _pass) == WL_CONNECTED) { - DEBUG_WM(F("Connect to new AP SUCCESS")); + DEBUG_WM(F("Connect to new AP [SUCCESS]")); + delay(500); + DEBUG_WM(F("Got IP Address:")); + DEBUG_WM(WiFi.localIP()); stopConfigPortal(); return WL_CONNECTED; // success } - DEBUG_WM(F("Failed to connect.")); + DEBUG_WM(F("Connect to new AP [FAILED]")); if (_shouldBreakAfterConfig) { // this is more of an exiting callback than a save @@ -414,7 +417,7 @@ int WiFiManager::connectWifi(String ssid, String pass) { //@todo catch failures in set_config } else { // connect using saved ssid if there is one - if (WiFi.SSID() != "") { + if (WiFi_hasAutoConnect()) { DEBUG_WM("Connecting to saved AP"); WiFi_enableSTA(true,storeSTAmode); WiFi.begin(); @@ -1430,10 +1433,10 @@ bool WiFiManager::WiFi_Disconnect() { // toggle STA without persistent bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) { + #ifdef ESP8266 WiFiMode_t currentMode = WiFi.getMode(); bool isEnabled = ((currentMode & WIFI_STA) != 0); - if((isEnabled != enable) || persistent) { if(enable) { if(persistent) DEBUG_WM(F("enableSTA PERSISTENT ON")); @@ -1481,4 +1484,16 @@ uint8_t WiFiManager::WiFi_softap_num_stations(){ #elif defined(ESP31B) || defined(ESP32) return WiFi.softAPgetStationNum(); #endif +} + +bool WiFiManager::WiFi_hasAutoConnect(){ + #ifdef ESP8266 + return WiFi.SSID() != ""; + #elif defined(ESP31B) || defined(ESP32) + wifi_config_t conf; + esp_wifi_get_config(WIFI_IF_STA, &conf); + const char* ssid = reinterpret_cast(conf.sta.ssid); + DEBUG_WM(ssid); + return ssid != ""; + #endif } \ No newline at end of file diff --git a/WiFiManager.h b/WiFiManager.h index ee7d805..97f7410 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -252,8 +252,10 @@ class WiFiManager bool WiFi_enableSTA(bool enable); bool WiFi_enableSTA(bool enable,bool persistent); bool WiFi_eraseConfig(); - void debugSoftAPConfig(); uint8_t WiFi_softap_num_stations(); + bool WiFi_hasAutoConnect(); + + void debugSoftAPConfig(); String getParamOut(); String getScanItemOut(); From ceaf53f604bf4473e981dba355455f0ca59a5c2c Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 24 Jan 2018 13:13:25 -0600 Subject: [PATCH 084/424] adds esp32 autoreconnector Using static event cb for now, feel free to improve, this functionality should be fixed in core soon --- WiFiManager.cpp | 26 ++++++++++++++++++++++++++ WiFiManager.h | 9 +++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 60305fe..eceade8 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -116,6 +116,8 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { WiFi_enableSTA(true); _usermode = WIFI_STA; + WiFi_autoReconnect(); + // if already connected, or try stored connect if (WiFi.status() == WL_CONNECTED || connectWifi("", "") == WL_CONNECTED) { //connected @@ -1224,6 +1226,10 @@ void WiFiManager::setCaptivePortalEnable(boolean enabled){ _enableCaptivePortal = enabled; } +void WiFiManager::setWiFiAutoReconnect(boolean enabled){ + _wifiAutoReconnect = enabled; +} + // HELPERS template @@ -1496,4 +1502,24 @@ bool WiFiManager::WiFi_hasAutoConnect(){ DEBUG_WM(ssid); return ssid != ""; #endif +} + +void WiFiManager::WiFiEvent(WiFiEvent_t event, system_event_info_t info){ + WiFiManager _WiFiManager; + if(event == SYSTEM_EVENT_STA_DISCONNECTED){ + // Serial.println("Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); + _WiFiManager.DEBUG_WM("ESP32 Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); // @todo remove debugging from prod, or change static method + WiFi.reconnect(); + } +} + +void WiFiManager::WiFi_autoReconnect(){ + #ifdef ESP8266 + WiFi.setAutoReconnect(_wifiAutoReconnect); + #elif defined(ESP31B) || defined(ESP32) + if(_wifiAutoReconnect){ + DEBUG_WM("ESP32 autoreconnect handler enabled"); + WiFi.onEvent(WiFiEvent); + } + #endif } \ No newline at end of file diff --git a/WiFiManager.h b/WiFiManager.h index 97f7410..a70ca86 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -172,6 +172,8 @@ class WiFiManager void setShowStaticFields(boolean alwaysShow); //if true disable captive portal redirection void setCaptivePortalEnable(boolean enabled); + // if true enable autoreconnecting + void setWiFiAutoReconnect(boolean enabled); private: std::unique_ptr dnsServer; @@ -221,7 +223,8 @@ class WiFiManager boolean _shouldBreakAfterConfig = false; boolean _tryWPS = false; boolean _configPortalIsBlocking = true; - + boolean _wifiAutoReconnect = false; + const char* _customHeadElement = ""; //String getEEPROMString(int start, int len); @@ -254,7 +257,9 @@ class WiFiManager bool WiFi_eraseConfig(); uint8_t WiFi_softap_num_stations(); bool WiFi_hasAutoConnect(); - + void WiFi_autoReconnect(); + static void WiFiEvent(WiFiEvent_t event, system_event_info_t info); + void debugSoftAPConfig(); String getParamOut(); From ead2b7353cfb5ddc53c4533ef5069f90aeb8e869 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 24 Jan 2018 13:16:06 -0600 Subject: [PATCH 085/424] enable autoreconnect --- WiFiManager.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.h b/WiFiManager.h index a70ca86..324d564 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -223,8 +223,8 @@ class WiFiManager boolean _shouldBreakAfterConfig = false; boolean _tryWPS = false; boolean _configPortalIsBlocking = true; - boolean _wifiAutoReconnect = false; - + boolean _wifiAutoReconnect = true; + const char* _customHeadElement = ""; //String getEEPROMString(int start, int len); From 8dbe045655608768f1fb57919034f4f393b8727b Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 24 Jan 2018 13:36:34 -0600 Subject: [PATCH 086/424] remove system_event_info_t arg --- WiFiManager.cpp | 2 +- WiFiManager.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index eceade8..e9194dc 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1504,7 +1504,7 @@ bool WiFiManager::WiFi_hasAutoConnect(){ #endif } -void WiFiManager::WiFiEvent(WiFiEvent_t event, system_event_info_t info){ +void WiFiManager::WiFiEvent(WiFiEvent_t event){ WiFiManager _WiFiManager; if(event == SYSTEM_EVENT_STA_DISCONNECTED){ // Serial.println("Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); diff --git a/WiFiManager.h b/WiFiManager.h index 324d564..b07011e 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -258,7 +258,7 @@ class WiFiManager uint8_t WiFi_softap_num_stations(); bool WiFi_hasAutoConnect(); void WiFi_autoReconnect(); - static void WiFiEvent(WiFiEvent_t event, system_event_info_t info); + static void WiFiEvent(WiFiEvent_t event); void debugSoftAPConfig(); From 7189e36c59cf67994c884b499596315e1ee3c3b7 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 24 Jan 2018 13:54:58 -0600 Subject: [PATCH 087/424] clean up defines, remove esp31b --- WiFiManager.cpp | 16 ++++++++-------- WiFiManager.h | 51 +++++++++++++++++++++++++------------------------ 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index e9194dc..66e3824 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -211,7 +211,7 @@ void WiFiManager::setupConfigPortal() { dnsServer.reset(new DNSServer()); #ifdef ESP8266 server.reset(new ESP8266WebServer(80)); - #elif defined(ESP31B) || defined(ESP32) + #elif defined(ESP32) server.reset(new WebServer(80)); #endif @@ -1375,7 +1375,7 @@ String WiFiManager::encryptionTypeStr(uint8_t authmode) { default: return "Unknown"; } - #elif defined(ESP31B) || defined(ESP32) + #elif defined(ESP32) switch(authmode) { case WIFI_AUTH_OPEN: return "None"; @@ -1408,7 +1408,7 @@ bool WiFiManager::WiFi_Mode(WiFiMode_t m,bool persistent) { ETS_UART_INTR_ENABLE(); return ret; - #elif defined(ESP31B) || defined(ESP32) + #elif defined(ESP32) return WiFi.mode(m); // @todo persistent not implemented? #endif } @@ -1427,7 +1427,7 @@ bool WiFiManager::WiFi_Disconnect() { ETS_UART_INTR_ENABLE(); return ret; } - #elif defined(ESP31B) || defined(ESP32) + #elif defined(ESP32) DEBUG_WM(F("wifi station disconnect")); // @todo why does disconnect call these, might be needed // WiFi.getMode(); // @todo wifiLowLevelInit(), probably not needed, for save config only @@ -1453,7 +1453,7 @@ bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) { } else { return true; } - #elif defined(ESP31B) || defined(ESP32) + #elif defined(ESP32) return WiFi.mode(WIFI_STA); // @todo persistent not implemented? #endif } @@ -1487,7 +1487,7 @@ void WiFiManager::reboot(){ uint8_t WiFiManager::WiFi_softap_num_stations(){ #ifdef ESP8266 return wifi_softap_get_station_num(); - #elif defined(ESP31B) || defined(ESP32) + #elif defined(ESP32) return WiFi.softAPgetStationNum(); #endif } @@ -1495,7 +1495,7 @@ uint8_t WiFiManager::WiFi_softap_num_stations(){ bool WiFiManager::WiFi_hasAutoConnect(){ #ifdef ESP8266 return WiFi.SSID() != ""; - #elif defined(ESP31B) || defined(ESP32) + #elif defined(ESP32) wifi_config_t conf; esp_wifi_get_config(WIFI_IF_STA, &conf); const char* ssid = reinterpret_cast(conf.sta.ssid); @@ -1516,7 +1516,7 @@ void WiFiManager::WiFiEvent(WiFiEvent_t event){ void WiFiManager::WiFi_autoReconnect(){ #ifdef ESP8266 WiFi.setAutoReconnect(_wifiAutoReconnect); - #elif defined(ESP31B) || defined(ESP32) + #elif defined(ESP31B) if(_wifiAutoReconnect){ DEBUG_WM("ESP32 autoreconnect handler enabled"); WiFi.onEvent(WiFiEvent); diff --git a/WiFiManager.h b/WiFiManager.h index b07011e..cbb219c 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -13,34 +13,34 @@ #ifndef WiFiManager_h #define WiFiManager_h +#define WEBSERVERSHIM // use webserver shim lib + #ifdef ESP8266 - #include - #include -#elif defined(ESP31B) || defined(ESP32) - #include - #include - #include + + extern "C" { + #include "user_interface.h" + } + #include + #include + + #define WIFI_getChipId() ESP.getChipId() + #define WIFI_AUTH_OPEN ENC_TYPE_NONE + +#elif defined(ESP32) + + #include + #include + #include + + #define WIFI_getChipId() (uint32_t)ESP.getEfuseMac() + #define WIFI_AUTH_OPEN WIFI_AUTH_OPEN + #else #endif #include #include -#ifdef ESP8266 - extern "C" { - #include "user_interface.h" - } -#endif - -#ifdef ESP8266 - #define WIFI_getChipId() ESP.getChipId() - #define WIFI_AUTH_OPEN ENC_TYPE_NONE -#elif defined(ESP31B) || defined(ESP32) - #define WIFI_getChipId() (uint32_t)ESP.getEfuseMac() - #define WIFI_AUTH_OPEN WIFI_AUTH_OPEN -#else -#endif - const char HTTP_HEAD[] PROGMEM = "{v}"; // const char HTTP_STYLE[] PROGMEM = ""; const char HTTP_STYLE[] PROGMEM = ""; -const char HTTP_STYLE[] PROGMEM = ""; - -const char HTTP_SCRIPT[] PROGMEM = ""; -const char HTTP_HEAD_END[] PROGMEM = "
"; -const char HTTP_PORTAL_OPTIONS[] PROGMEM = "




"; -const char HTTP_ITEM[] PROGMEM = ""; -// const char HTTP_ITEM[] PROGMEM = "
{v} {R} {r}% {q} {e}
"; // test all tokens -//const char HTTP_ITEM_PADLOCK[] PROGMEM = ""; -const char HTTP_FORM_START[] PROGMEM = "


"; -const char HTTP_FORM_END[] PROGMEM = "
"; -const char HTTP_FORM_LABEL[] PROGMEM = ""; -const char HTTP_FORM_PARAM_START[] PROGMEM = "
"; -const char HTTP_FORM_PARAM[] PROGMEM = "
"; -const char HTTP_FORM_PARAM_END[] PROGMEM = "
"; -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_END[] PROGMEM = "
"; - -#define WIFI_MANAGER_MAX_PARAMS 5 +#define WIFI_MANAGER_MAX_PARAMS 5 // params will autoincrement and realloc by this amount when max is reached #define WFM_LABEL_BEFORE 1 #define WFM_LABEL_AFTER 2 diff --git a/strings_en.h b/strings_en.h new file mode 100644 index 0000000..abda51c --- /dev/null +++ b/strings_en.h @@ -0,0 +1,56 @@ +const char HTTP_HEAD[] PROGMEM = "{v}"; +const char HTTP_SCRIPT[] PROGMEM = ""; +const char HTTP_HEAD_END[] PROGMEM = "
"; +const char HTTP_PORTAL_OPTIONS[] PROGMEM = "




"; +const char HTTP_ITEM[] PROGMEM = ""; +// const char HTTP_ITEM[] PROGMEM = "
{v} {R} {r}% {q} {e}
"; // test all tokens +const char HTTP_FORM_START[] PROGMEM = "


"; +const char HTTP_FORM_END[] PROGMEM = "
"; +const char HTTP_FORM_LABEL[] PROGMEM = ""; +const char HTTP_FORM_PARAM_START[] PROGMEM = "
"; +const char HTTP_FORM_PARAM[] PROGMEM = "
"; +const char HTTP_FORM_PARAM_END[] PROGMEM = "
"; +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_END[] PROGMEM = "
"; + +const char HTTP_STYLE[] PROGMEM = ""; + +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.
/closeClose the configuration server and configuration WiFi network.
/iInformation page
/exitExit Config Portal, configportal will close
/rReboot the device
/eraseErase WiFi configuration and reboot Device. Device will not reconnect to a network until new WiFi configuration data is entered.
" + "

More information about WiFiManager at https://github.com/tzapu/WiFiManager."; \ No newline at end of file From 68762e1741b6c8d0b268b869e04a10bac7d6e145 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 31 Jan 2018 14:03:33 -0600 Subject: [PATCH 125/424] typo --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 4af51ea..95e3d7e 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -82,7 +82,7 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { // check param id is valid for (int i = 0; i < strlen(p->getID()); i++){ if(!isAlphaNumeric(p->getID()[i])){ - DEBUG_WM("[ERROR] parameter IDs can only contain aplha numberic chars"); + DEBUG_WM("[ERROR] parameter IDs can only contain alpha numeric chars"); return false; } } From b0c61688d660f55dadc316ea7f43cf6d3061665f Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 31 Jan 2018 14:07:38 -0600 Subject: [PATCH 126/424] cleanup --- WiFiManager.cpp | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 95e3d7e..5620da1 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -713,7 +713,7 @@ String WiFiManager::getStaticOut(){ String page; if (_sta_show_static_fields || _sta_static_ip) { - // @todo how do we get these settings from memory , wifi_get_ip_info does not seem to reveal if struct ip_info is static or not + // @todo how can we get these settings from memory , wifi_get_ip_info does not seem to reveal if struct ip_info is static or not // @todo move titles to params for i18n String item = FPSTR(HTTP_FORM_LABEL); @@ -725,7 +725,8 @@ String WiFiManager::getStaticOut(){ item.replace("{l}", "15"); item.replace("{v}", (_sta_static_ip ? _sta_static_ip.toString() : "")); item.replace("{c}", ""); - + + // actuals as placeholder // IPAddress sta_ip = WiFi.localIP(); // item.replace("{p}", sta_ip.toString()); @@ -741,6 +742,7 @@ String WiFiManager::getStaticOut(){ item.replace("{v}", (_sta_static_gw ? _sta_static_gw.toString() : "")); item.replace("{c}", ""); + // actuals as placeholder // IPAddress sta_gateway = WiFi.gatewayIP(); // item.replace("{p}", sta_gateway.toString()); @@ -756,6 +758,7 @@ String WiFiManager::getStaticOut(){ item.replace("{v}", (_sta_static_sn ? _sta_static_sn.toString() : "")); item.replace("{c}", ""); + // actuals as placeholder // IPAddress sta_subnet = WiFi.subnetMask(); // item.replace("{p}", sta_subnet.toString()); page += item; @@ -1250,28 +1253,6 @@ void WiFiManager::DEBUG_WM(Generic text,Genericb textb) { } } -/* - String WiFiManager::getSSID() { - if (_ssid == "") { - DEBUG_WM(F("Reading SSID")); - _ssid = WiFi.SSID(); - DEBUG_WM(F("SSID: ")); - DEBUG_WM(_ssid); - } - return _ssid; - } - - String WiFiManager::getPassword() { - if (_pass == "") { - DEBUG_WM(F("Reading Password")); - _pass = WiFi.psk(); - DEBUG_WM("Password: " + _pass); - //DEBUG_WM(_pass); - } - return _pass; - } -*/ - void WiFiManager::debugSoftAPConfig(){ softap_config config; wifi_softap_get_config(&config); From 6894c89441daa8686a393dbbb30056dea3a79ec2 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 31 Jan 2018 16:37:53 -0600 Subject: [PATCH 127/424] moved all html strings out of code --- WiFiManager.cpp | 119 +++++++++++++++--------------------------------- WiFiManager.h | 1 + strings_en.h | 6 +++ 3 files changed, 44 insertions(+), 82 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 5620da1..a841b8b 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -547,6 +547,17 @@ void WiFiManager::setBreakAfterConfig(boolean shouldBreak) { _shouldBreakAfterConfig = shouldBreak; } +String WiFiManager::getHTTPHead(String title){ + String page; + page += FPSTR(HTTP_HEAD); + page.replace("{v}", title); + page += FPSTR(HTTP_SCRIPT); + page += FPSTR(HTTP_STYLE); + page += _customHeadElement; + page += FPSTR(HTTP_HEAD_END); + return page; +} + /** * HTTPD CALLBACK root or redirect to captive portal */ @@ -556,26 +567,17 @@ void WiFiManager::handleRoot() { if (captivePortal()) { // If captive portal redirect instead of displaying the page. return; } - - String page = FPSTR(HTTP_HEAD); - page.replace("{v}", "Options"); - page += FPSTR(HTTP_SCRIPT); - page += FPSTR(HTTP_STYLE); - page += _customHeadElement; - page += FPSTR(HTTP_HEAD_END); - page += "

"; - page += configPortalActive ? _apName : WiFi.localIP().toString(); - page += "

"; - page += F("

WiFiManager

"); + String page = getHTTPHead("options"); // @token options + String str = FPSTR(HTTP_ROOT_MAIN); + str.replace("{v}",configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading + page += str; page += FPSTR(HTTP_PORTAL_OPTIONS); reportStatus(page); page += FPSTR(HTTP_END); - server->sendHeader("Content-Length", String(page.length())); server->send(200, "text/html", page); // server->close(); // testing reliability fix for content length mismatches during mutiple flood hits - } /** @@ -584,18 +586,10 @@ void WiFiManager::handleRoot() { void WiFiManager::handleWifi(boolean scan) { DEBUG_WM("<- HTTP Wifi"); - - String page = FPSTR(HTTP_HEAD); - page.replace("{v}", "Config ESP"); // @token titlewifi - page += FPSTR(HTTP_SCRIPT); - page += FPSTR(HTTP_STYLE); - page += _customHeadElement; - page += FPSTR(HTTP_HEAD_END); - + String page = getHTTPHead("Config ESP"); // @token titlewifi if (scan) { page += getScanItemOut(); } - String pitem = FPSTR(HTTP_FORM_START); pitem.replace("{v}", WiFi.SSID()); page += pitem; @@ -883,12 +877,7 @@ void WiFiManager::handleWifiSave() { DEBUG_WM(F("static netmask:"),sn); } - String page = FPSTR(HTTP_HEAD); - page.replace("{v}", "Credentials Saved"); // @token titlewifisaved - page += FPSTR(HTTP_SCRIPT); - page += FPSTR(HTTP_STYLE); - page += _customHeadElement; - page += FPSTR(HTTP_HEAD_END); + String page = getHTTPHead("Credentials Saved"); // @token titlewifisaved page += FPSTR(HTTP_SAVED); page += FPSTR(HTTP_END); @@ -905,14 +894,7 @@ void WiFiManager::handleWifiSave() { */ void WiFiManager::handleInfo() { DEBUG_WM(F("<- HTTP Info")); - - String page = FPSTR(HTTP_HEAD); - page.replace("{v}", "Info"); // @token titleinfo - page += FPSTR(HTTP_SCRIPT); - page += FPSTR(HTTP_STYLE); - page += _customHeadElement; - page += FPSTR(HTTP_HEAD_END); - + String page = getHTTPHead("Info"); // @token titleinfo reportStatus(page); // @todo add versioning here @@ -1033,13 +1015,8 @@ void WiFiManager::handleInfo() { page += WiFi.getAutoConnect() ? "Enabled" : "Disabled"; // @token enabled,disabled page += F(""); page += F("
"); - - page += "
"; - + page += FPSTR(HTTP_ERASEBTN); page += FPSTR(HTTP_HELP); - page += FPSTR(HTTP_END); server->sendHeader("Content-Length", String(page.length())); @@ -1054,42 +1031,30 @@ void WiFiManager::handleInfo() { */ void WiFiManager::handleExit() { DEBUG_WM(F("<- HTTP Exit")); - - String page = FPSTR(HTTP_HEAD); - page.replace("{v}", "Exit"); - page += FPSTR(HTTP_SCRIPT); - page += FPSTR(HTTP_STYLE); - page += _customHeadElement; - page += FPSTR(HTTP_HEAD_END); - - page += "Exiting"; + String page = getHTTPHead("Exit"); // @token exit + page += "Exiting"; // @token exiting server->sendHeader("Content-Length", String(page.length())); server->send(200, "text/html", page); abort = true; } void WiFiManager::reportStatus(String &page){ - + String str; if (WiFi.SSID() != ""){ if (WiFi.status()==WL_CONNECTED){ - page += "
"; - page += F("Connected to "); - page += WiFi.SSID(); - page += F("
with IP "); - page += WiFi.localIP().toString(); - page += F(""); - } else { - page += "
"; - page += "Not Connected to "; - page += WiFi.SSID(); - } - } else { - page += "
"; - page += "No AP set"; + str = FPSTR(HTTP_STATUS_ON); + str.replace("{u}",WiFi.localIP().toString()); + str.replace("{s}",WiFi.SSID()); + } + else { + str = FPSTR(HTTP_STATUS_OFF); + str.replace("{s}",WiFi.SSID()); + } } - page += "
"; + else { + str = FPSTR(HTTP_STATUS_NONE); + } + page += str; } /** @@ -1098,12 +1063,7 @@ void WiFiManager::reportStatus(String &page){ void WiFiManager::handleReset() { DEBUG_WM(F("<- HTTP Reset")); - String page = FPSTR(HTTP_HEAD); - page.replace("{v}", "Reset"); - page += FPSTR(HTTP_SCRIPT); - page += FPSTR(HTTP_STYLE); - page += _customHeadElement; - page += FPSTR(HTTP_HEAD_END); + String page = getHTTPHead("Reset"); page += F("Module will reset in a few seconds."); page += FPSTR(HTTP_END); @@ -1121,15 +1081,10 @@ void WiFiManager::handleReset() { void WiFiManager::handleErase() { DEBUG_WM(F("<- HTTP Erase")); - String page = FPSTR(HTTP_HEAD); - page.replace("{v}", "Erase"); - page += FPSTR(HTTP_SCRIPT); - page += FPSTR(HTTP_STYLE); - page += _customHeadElement; + String page = getHTTPHead("Erase"); page += FPSTR(HTTP_HEAD_END); - bool ret = WiFi_eraseConfig(); - + if(ret) page += F("Module will reset in a few seconds."); else { page += F("An Error Occured"); diff --git a/WiFiManager.h b/WiFiManager.h index 4c0065a..d0b90be 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -205,6 +205,7 @@ class WiFiManager String getParamOut(); String getScanItemOut(); String getStaticOut(); + String getHTTPHead(String title); //helpers String getWLStatusString(uint8_t status); diff --git a/strings_en.h b/strings_en.h index abda51c..bf5f112 100644 --- a/strings_en.h +++ b/strings_en.h @@ -1,6 +1,7 @@ const char HTTP_HEAD[] PROGMEM = "{v}"; const char HTTP_SCRIPT[] PROGMEM = ""; const char HTTP_HEAD_END[] PROGMEM = "
"; +const char HTTP_ROOT_MAIN[] PROGMEM = "

{v}

WiFiManager

"; const char HTTP_PORTAL_OPTIONS[] PROGMEM = "




"; const char HTTP_ITEM[] PROGMEM = ""; // const char HTTP_ITEM[] PROGMEM = "
{v} {R} {r}% {q} {e}
"; // test all tokens @@ -13,6 +14,11 @@ const char HTTP_FORM_PARAM_END[] PROGMEM = "
"; 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_END[] PROGMEM = "
"; +const char HTTP_ERASEBTN[] PROGMEM = "
"; + +const char HTTP_STATUS_ON[] PROGMEM = "
Connected to {s}
with IP {u}
"; +const char HTTP_STATUS_OFF[] PROGMEM = "
Not Connected to {s}
"; +const char HTTP_STATUS_NONE[] PROGMEM = "
No AP set
"; const char HTTP_STYLE[] PROGMEM = ""; const char HTTP_HELP[] PROGMEM = @@ -95,8 +95,8 @@ const char HTTP_JS[] PROGMEM = const char HTTP_INFO_esphead[] PROGMEM = "

esp8266


"; 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_uptime[] PROGMEM = "
Uptime
{1} Mins {2} Secs
"; +const char HTTP_INFO_chipid[] PROGMEM = "
Chip ID
{1}
"; const char HTTP_INFO_fchipid[] PROGMEM = "
Flash Chip ID
{1}
"; const char HTTP_INFO_idesize[] PROGMEM = "
IDE Flash Size
{1} bytes
"; const char HTTP_INFO_flashsize[] PROGMEM = "
Actual Flash Size
{1} bytes
"; From 46929e0ee6e7df7ab1b5d6ff81eeee9399fb77df Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 12 Feb 2018 10:59:50 -0600 Subject: [PATCH 147/424] change uptime --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 3034a9d..4ee0e90 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -971,8 +971,8 @@ String WiFiManager::getInfoData(String id){ else if(id=="uptime"){ // subject to rollover! p = FPSTR(HTTP_INFO_uptime); - p.replace("{1}",(String)(system_get_time() / 1000000 / 60)); - p.replace("{2}",(String)((system_get_time() / 1000000)%60)); + p.replace("{1}",(String)(millis() / 1000 / 60)); + p.replace("{2}",(String)((millis() / 1000)%60)); } else if(id=="chipid"){ p = FPSTR(HTTP_INFO_chipid); From 4424e66222538bf8dc0847ef847010146820aa42 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 12 Feb 2018 12:31:16 -0600 Subject: [PATCH 148/424] infohelp align html --- extras/WiFiManager.template.html | 27 +++++++++++++++++++++++++++ strings_en.h | 1 + 2 files changed, 28 insertions(+) diff --git a/extras/WiFiManager.template.html b/extras/WiFiManager.template.html index 09ae94b..1609f5f 100644 --- a/extras/WiFiManager.template.html +++ b/extras/WiFiManager.template.html @@ -131,6 +131,9 @@ dd { margin: 0; padding: 0 0 0.5em 0; } +td { + vertical-align: top; +} @@ -203,11 +206,35 @@ dd {
Flash Chip ID
1234556
IDE Flash Size
4194304 bytes
Real Flash Size
4194304 bytes
+
Empty
Soft AP IP
192.168.4.1
Soft AP MAC
00:00:00:00:00:00
Station MAC
00:00:00:00:00:00
+ +

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.
/closeClose the configuration server and configuration WiFi network.
/iInformation page
/exitExit Config Portal, configportal will close
/rReboot the device
/eraseErase WiFi configuration and reboot Device. Device will not reconnect to a network until new WiFi configuration data is entered.
+

More information about WiFiManager at https://github.com/tzapu/WiFiManager.; +

diff --git a/strings_en.h b/strings_en.h index 002323a..3767942 100644 --- a/strings_en.h +++ b/strings_en.h @@ -43,6 +43,7 @@ const char HTTP_STYLE[] PROGMEM = ""; const char HTTP_HELP[] PROGMEM = From 1f7dc79b2033dd91908db2aa3fbc1a8c5a12a7eb Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 12 Feb 2018 13:03:13 -0600 Subject: [PATCH 149/424] added webserver precompiler warning updates readme --- README.md | 13 +++++++++++-- WiFiManager.h | 17 ++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d9d7f58..125ad0f 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,18 @@ The configuration portal is of the captive variety, so on various devices it wil First attempt at a library. Lots more changes and fixes to do. Contributions are welcome. -### ESP32 must be patched with webserver library!!!!!! see https://github.com/tzapu/WiFiManager/issues/241 +**This works with the ESP8266 Arduino platform with a recent stable release(2.0.0 or newer)** -#### This works with the ESP8266 Arduino platform with a recent stable release(2.0.0 or newer) https://github.com/esp8266/Arduino +[https://github.com/esp8266/Arduino](https://github.com/esp8266/Arduino) + +**This works with the ESP32 Arduino platform with staging , with caveats below** + +[https://github.com/espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) + +### Known Issues +* ESP32 must be patched with webserver library ! see [https://github.com/tzapu/WiFiManager/issues/513](https://github.com/tzapu/WiFiManager/issues/513) +* ESP32 espressif/dnsserver contains bugs that prevent captibe portal from working ! see [https://github.com/tzapu/WiFiManager/issues/513](https://github.com/tzapu/WiFiManager/issues/513) +* Documentation needs to be updated, see [https://github.com/tzapu/WiFiManager/issues/500](https://github.com/tzapu/WiFiManager/issues/500) ## Contents - [How it works](#how-it-works) diff --git a/WiFiManager.h b/WiFiManager.h index 2f71e7f..ed6f428 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -33,13 +33,16 @@ #define WIFI_getChipId() (uint32_t)ESP.getEfuseMac() #define WIFI_AUTH_OPEN WIFI_AUTH_OPEN - - #ifdef WEBSERVERSHIM - #include - #else - #include - // Forthcoming official - // https://github.com/esp8266/ESPWebServer + + #ifndef WEBSERVER_H + #warning "WEBSERVER not implemented in espressif/esp32, see readme notes" + #ifdef WEBSERVERSHIM + #include + #else + #include + // Forthcoming official + // https://github.com/esp8266/ESPWebServer + #endif #endif #else From 17410d38c21fe4b1b73b4e832dbfd397041de076 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 12 Feb 2018 13:46:03 -0600 Subject: [PATCH 150/424] readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 125ad0f..42df97b 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are [https://github.com/espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) ### Known Issues -* ESP32 must be patched with webserver library ! see [https://github.com/tzapu/WiFiManager/issues/513](https://github.com/tzapu/WiFiManager/issues/513) -* ESP32 espressif/dnsserver contains bugs that prevent captibe portal from working ! see [https://github.com/tzapu/WiFiManager/issues/513](https://github.com/tzapu/WiFiManager/issues/513) +* :exclamation: ESP32 must be patched with webserver library, see [https://github.com/tzapu/WiFiManager/issues/513](https://github.com/tzapu/WiFiManager/issues/513) +* :exclamation: ESP32 espressif/dnsserver contains bugs that prevent captive portal from working, see [https://github.com/tzapu/WiFiManager/issues/513](https://github.com/tzapu/WiFiManager/issues/513) * Documentation needs to be updated, see [https://github.com/tzapu/WiFiManager/issues/500](https://github.com/tzapu/WiFiManager/issues/500) ## Contents From 3e10f984e1545cb98160b0122daf81e57736f35f Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 12 Feb 2018 19:23:51 -0600 Subject: [PATCH 151/424] template --- extras/WiFiManager.template.html | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/extras/WiFiManager.template.html b/extras/WiFiManager.template.html index 09ae94b..327c17f 100644 --- a/extras/WiFiManager.template.html +++ b/extras/WiFiManager.template.html @@ -44,6 +44,9 @@ a:hover { color: #1fa3ec; text-decoration: underline; } +.h { + display: none; +} .q { height: 16px; margin: 0; @@ -142,6 +145,7 @@ dd {
+

/


@@ -160,17 +164,18 @@ dd { - - - - - + + + + + + -


+

custom parameter


From bab1201dcb79b343a581f7729400ade4f4f2078e Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 13 Feb 2018 11:40:19 -0600 Subject: [PATCH 152/424] fix esp32 esp8266 bug --- WiFiManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.h b/WiFiManager.h index ed6f428..4d92e2b 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -213,7 +213,7 @@ class WiFiManager boolean _staShowStaticFields = false; boolean _enableCaptivePortal = true; boolean _userpersistent = true; - boolean _wifiAutoReconnect = false; + boolean _wifiAutoReconnect = true; // there is no getter for this, we must assume its true and make it so boolean _cpClientCheck = false; // keep cp alive if cp have station boolean _webClientCheck = true; // keep cp alive if web have client From addb045a0c3acc1d7315a994fd10fd93d87ff6c7 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 14 Feb 2018 09:36:09 -0600 Subject: [PATCH 153/424] moved strings to flash --- WiFiManager.cpp | 431 ++++++++++++++++++++++++------------------------ 1 file changed, 218 insertions(+), 213 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 4ee0e90..f4da82a 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -225,7 +225,7 @@ boolean WiFiManager::configPortalHasTimeout(){ } else { if((millis() - timer) > 1000){ timer = millis(); - DEBUG_WM("Portal Timeout In " + (String)((_configPortalStart + _configPortalTimeout-millis())/1000) + " seconds"); + DEBUG_WM(F("Portal Timeout In"),(String)((_configPortalStart + _configPortalTimeout-millis())/1000) + (String)F(" seconds")); } } @@ -234,7 +234,7 @@ boolean WiFiManager::configPortalHasTimeout(){ void WiFiManager::setupConfigPortal() { - DEBUG_WM("Starting Web Portal"); + DEBUG_WM(F("Starting Web Portal")); // setup dns and web servers dnsServer.reset(new DNSServer()); @@ -242,18 +242,18 @@ void WiFiManager::setupConfigPortal() { /* Setup the DNS server redirecting all the domains to the apIP */ dnsServer->setErrorReplyCode(DNSReplyCode::NoError); - dnsServer->start(DNS_PORT, "*", WiFi.softAPIP()); + dnsServer->start(DNS_PORT, F("*"), WiFi.softAPIP()); /* Setup httpd callbacks, web pages: root, wifi config pages, SO captive portal detectors and not found. */ - server->on("/", std::bind(&WiFiManager::handleRoot, this)); - server->on("/wifi", std::bind(&WiFiManager::handleWifi, this, true)); - server->on("/0wifi", std::bind(&WiFiManager::handleWifi, this, false)); - server->on("/wifisave", std::bind(&WiFiManager::handleWifiSave, this)); - server->on("/i", std::bind(&WiFiManager::handleInfo, this)); - server->on("/r", std::bind(&WiFiManager::handleReset, this)); - server->on("/exit", std::bind(&WiFiManager::handleExit, this)); - server->on("/erase", std::bind(&WiFiManager::handleErase, this)); - server->on("/status", std::bind(&WiFiManager::handleWiFiStatus, this)); + server->on((String)F("/"), std::bind(&WiFiManager::handleRoot, this)); + server->on((String)F("/wifi"), std::bind(&WiFiManager::handleWifi, this, true)); + server->on((String)F("/0wifi"), std::bind(&WiFiManager::handleWifi, this, false)); + server->on((String)F("/wifisave"), std::bind(&WiFiManager::handleWifiSave, this)); + server->on((String)F("/i"), std::bind(&WiFiManager::handleInfo, this)); + server->on((String)F("/r"), std::bind(&WiFiManager::handleReset, this)); + server->on((String)F("/exit"), std::bind(&WiFiManager::handleExit, this)); + server->on((String)F("/erase"), std::bind(&WiFiManager::handleErase, this)); + server->on((String)F("/status"), std::bind(&WiFiManager::handleWiFiStatus, this)); //server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler. server->onNotFound (std::bind(&WiFiManager::handleNotFound, this)); @@ -277,14 +277,14 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // this fixes most ap problems, however, simply doing mode(WIFI_AP) does not work if sta connection is hanging, must `wifi_station_disconnect` WiFi_Disconnect(); WiFi_enableSTA(false); - DEBUG_WM("Disabling STA"); + DEBUG_WM(F("Disabling STA")); } else { // @todo even if sta is connected, it is possible that softap connections will fail, IOS says "invalid password", windows says "cannot connect to this network" researching WiFi_enableSTA(true); } - DEBUG_WM("Enabling AP"); + DEBUG_WM(F("Enabling AP")); _apName = apName; // @todo check valid apname ? _apPassword = apPassword; @@ -332,7 +332,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo yield(); // watchdog } - DEBUG_WM("config portal exiting"); + DEBUG_WM(F("config portal exiting")); return result; } @@ -375,7 +375,7 @@ uint8_t WiFiManager::handleConfigPortal(){ // sta off to stabilize AP on connect failure WiFi_Disconnect(); WiFi_enableSTA(false); - DEBUG_WM("Disabling STA"); + DEBUG_WM(F("Disabling STA")); } } @@ -434,7 +434,7 @@ int WiFiManager::connectWifi(String ssid, String pass) { // if ssid argument provided connect to that if (ssid != "") { - DEBUG_WM("Connecting to new AP"); + DEBUG_WM(F("Connecting to new AP")); WiFi_enableSTA(true,storeSTAmode); // storeSTAmode will also toggle STA on in default opmode (persistent) if true (default) WiFi.persistent(true); WiFi.begin(ssid.c_str(), pass.c_str()); @@ -443,17 +443,17 @@ int WiFiManager::connectWifi(String ssid, String pass) { } else { // connect using saved ssid if there is one if (WiFi.SSID() != "") { - DEBUG_WM("Connecting to saved AP"); + DEBUG_WM(F("Connecting to saved AP")); WiFi_enableSTA(true,storeSTAmode); WiFi.begin(); } else { - DEBUG_WM("No saved credentials, skipping wifi"); + DEBUG_WM(F("No saved credentials, skipping wifi")); waitforconx = false; } } uint8_t connRes = waitforconx ? waitForConnectResult() : WL_NO_SSID_AVAIL; - DEBUG_WM ("Connection result:",getWLStatusString(connRes)); + DEBUG_WM (F("Connection result:"),getWLStatusString(connRes)); // do WPS, if WPS options enabled and not connected and no password was supplied // @todo this seems like wrong place for this, is it a fallback or option? @@ -495,9 +495,9 @@ uint8_t WiFiManager::waitForConnectResult() { } void WiFiManager::startWPS() { - DEBUG_WM("START WPS"); + DEBUG_WM(F("START WPS")); WiFi.beginWPSConfig(); - DEBUG_WM("END WPS"); + DEBUG_WM(F("END WPS")); } // GETTERS @@ -554,7 +554,7 @@ void WiFiManager::setBreakAfterConfig(boolean shouldBreak) { String WiFiManager::getHTTPHead(String title){ String page; page += FPSTR(HTTP_HEAD); - page.replace("{v}", title); + page.replace(F("{v}"), title); page += FPSTR(HTTP_SCRIPT); page += FPSTR(HTTP_STYLE); page += _customHeadElement; @@ -578,14 +578,14 @@ void WiFiManager::handleRoot() { handleRequest(); String page = getHTTPHead(FPSTR(S_options)); // @token options String str = FPSTR(HTTP_ROOT_MAIN); - str.replace("{v}",configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading + str.replace(F("{v}"),configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading page += str; page += FPSTR(HTTP_PORTAL_OPTIONS); reportStatus(page); page += FPSTR(HTTP_END); - server->sendHeader("Content-Length", String(page.length())); - server->send(200, "text/html", page); + server->sendHeader(F("Content-Length"), String(page.length())); + server->send(200, F("text/html"), page); // server->close(); // testing reliability fix for content length mismatches during mutiple flood hits } @@ -593,14 +593,14 @@ void WiFiManager::handleRoot() { * HTTPD CALLBACK Wifi config page handler */ void WiFiManager::handleWifi(boolean scan) { - DEBUG_WM("<- HTTP Wifi"); + DEBUG_WM(F("<- HTTP Wifi")); handleRequest(); String page = getHTTPHead(FPSTR(S_titlewifi)); // @token titlewifi if (scan) { page += getScanItemOut(); } String pitem = FPSTR(HTTP_FORM_START); - pitem.replace("{v}", WiFi.SSID()); + pitem.replace(F("{v}"), WiFi.SSID()); page += pitem; page += getStaticOut(); @@ -611,8 +611,8 @@ void WiFiManager::handleWifi(boolean scan) { reportStatus(page); page += FPSTR(HTTP_END); - server->sendHeader("Content-Length", String(page.length())); - server->send(200, "text/html", page); + server->sendHeader(F("Content-Length"), String(page.length())); + server->send(200, F("text/html"), page); // server->close(); // testing reliability fix for content length mismatches during mutiple flood hits // Serial.println(page); @@ -660,7 +660,7 @@ String WiFiManager::getScanItemOut(){ cssid = WiFi.SSID(indices[i]); for (int j = i + 1; j < n; j++) { if (cssid == WiFi.SSID(indices[j])) { - DEBUG_WM("DUP AP:",WiFi.SSID(indices[j])); + DEBUG_WM(F("DUP AP:"),WiFi.SSID(indices[j])); indices[j] = -1; // set dup aps to index -1 } } @@ -669,33 +669,33 @@ String WiFiManager::getScanItemOut(){ // token precheck, to speed up replacements on large ap lists String HTTP_ITEM_STR = FPSTR(HTTP_ITEM); - bool tok_r = HTTP_ITEM_STR.indexOf("{r}") > 0; - bool tok_R = HTTP_ITEM_STR.indexOf("{R}") > 0; - bool tok_e = HTTP_ITEM_STR.indexOf("{e}") > 0; - bool tok_q = HTTP_ITEM_STR.indexOf("{q}") > 0; - bool tok_i = HTTP_ITEM_STR.indexOf("{i}") > 0; + bool tok_r = HTTP_ITEM_STR.indexOf(F("{r}")) > 0; + bool tok_R = HTTP_ITEM_STR.indexOf(F("{R}")) > 0; + bool tok_e = HTTP_ITEM_STR.indexOf(F("{e}")) > 0; + bool tok_q = HTTP_ITEM_STR.indexOf(F("{q}")) > 0; + bool tok_i = HTTP_ITEM_STR.indexOf(F("{i}")) > 0; //display networks in page for (int i = 0; i < n; i++) { if (indices[i] == -1) continue; // skip dups - DEBUG_WM("AP: " + (String)WiFi.RSSI(indices[i]) + " " + (String)WiFi.SSID(indices[i])); + DEBUG_WM(F("AP: "),(String)WiFi.RSSI(indices[i]) + " " + (String)WiFi.SSID(indices[i])); int rssiperc = getRSSIasQuality(WiFi.RSSI(indices[i])); uint8_t enc_type = WiFi.encryptionType(indices[i]); if (_minimumQuality == -1 || _minimumQuality < rssiperc) { String item = FPSTR(HTTP_ITEM); - item.replace("{v}", WiFi.SSID(indices[i])); // ssid no encoding - if(tok_e) item.replace("{e}", encryptionTypeStr(enc_type)); - if(tok_r) item.replace("{r}", (String)rssiperc); // rssi percentage 0-100 - if(tok_R) item.replace("{R}", (String)WiFi.RSSI(indices[i])); // rssi db - if(tok_q) item.replace("{q}", (String)round(map(rssiperc,0,100,1,4))); //quality icon 1-4 + item.replace(F("{v}"), WiFi.SSID(indices[i])); // ssid no encoding + if(tok_e) item.replace(F("{e}"), encryptionTypeStr(enc_type)); + if(tok_r) item.replace(F("{r}"), (String)rssiperc); // rssi percentage 0-100 + if(tok_R) item.replace(F("{R}"), (String)WiFi.RSSI(indices[i])); // rssi db + if(tok_q) item.replace(F("{q}"), (String)round(map(rssiperc,0,100,1,4))); //quality icon 1-4 if(tok_i){ if (enc_type != WIFI_AUTH_OPEN) { - item.replace("{i}", "l"); + item.replace(F("{i}"), F("l")); } else { - item.replace("{i}", ""); + item.replace(F("{i}"), ""); } } //DEBUG_WM(item); @@ -721,51 +721,51 @@ String WiFiManager::getStaticOut(){ String item = FPSTR(HTTP_FORM_LABEL); item += FPSTR(HTTP_FORM_PARAM); - item.replace("{i}", "ip"); - item.replace("{n}", "ip"); - item.replace("{p}", "{t}"); - item.replace("{t}", FPSTR(S_staticip)); // @token staticip - item.replace("{l}", "15"); - item.replace("{v}", (_sta_static_ip ? _sta_static_ip.toString() : "")); - item.replace("{c}", ""); + item.replace(F("{i}"), F("ip")); + item.replace(F("{n}"), F("ip")); + item.replace(F("{p}"), F("{t}")); + item.replace(F("{t}"), FPSTR(S_staticip)); // @token staticip + item.replace(F("{l}"), F("15")); + item.replace(F("{v}"), (_sta_static_ip ? _sta_static_ip.toString() : "")); + item.replace(F("{c}"), ""); // actuals as placeholder // IPAddress sta_ip = WiFi.localIP(); - // item.replace("{p}", sta_ip.toString()); + // item.replace(F("{p}"), sta_ip.toString()); page += item; item = FPSTR(HTTP_FORM_LABEL); item += FPSTR(HTTP_FORM_PARAM); - item.replace("{i}", "gw"); - item.replace("{n}", "gw"); - item.replace("{p}", "{t}"); - item.replace("{t}", FPSTR(S_staticgw)); // @token staticgw - item.replace("{l}", "15"); - item.replace("{v}", (_sta_static_gw ? _sta_static_gw.toString() : "")); - item.replace("{c}", ""); + item.replace(F("{i}"), F("gw")); + item.replace(F("{n}"), F("gw")); + item.replace(F("{p}"), F("{t}")); + item.replace(F("{t}"), FPSTR(S_staticgw)); // @token staticgw + item.replace(F("{l}"), F("15")); + item.replace(F("{v}"), (_sta_static_gw ? _sta_static_gw.toString() : "")); + item.replace(F("{c}"), ""); // actuals as placeholder // IPAddress sta_gateway = WiFi.gatewayIP(); - // item.replace("{p}", sta_gateway.toString()); + // item.replace(F("{p}"), sta_gateway.toString()); page += item; item = FPSTR(HTTP_FORM_LABEL); item += FPSTR(HTTP_FORM_PARAM); - item.replace("{i}", "sn"); - item.replace("{n}", "sn"); - item.replace("{p}", "{t}"); - item.replace("{t}", FPSTR(S_subnet)); // @token subnet - item.replace("{l}", "15"); - item.replace("{v}", (_sta_static_sn ? _sta_static_sn.toString() : "")); - item.replace("{c}", ""); + item.replace(F("{i}"), F("sn")); + item.replace(F("{n}"), F("sn")); + item.replace(F("{p}"), F("{t}")); + item.replace(F("{t}"), FPSTR(S_subnet)); // @token subnet + item.replace(F("{l}"), F("15")); + item.replace(F("{v}"), (_sta_static_sn ? _sta_static_sn.toString() : "")); + item.replace(F("{c}"), ""); // actuals as placeholder // IPAddress sta_subnet = WiFi.subnetMask(); // item.replace("{p}", sta_subnet.toString()); page += item; - page += "
"; // @todo remove these, use css + page += F("
"); // @todo remove these, use css } return page; } @@ -777,14 +777,14 @@ String WiFiManager::getParamOut(){ String HTTP_PARAM_temp = FPSTR(HTTP_FORM_LABEL); HTTP_PARAM_temp += FPSTR(HTTP_FORM_PARAM); - bool tok_I = HTTP_PARAM_temp.indexOf("{I}") > 0; - bool tok_i = HTTP_PARAM_temp.indexOf("{i}") > 0; - bool tok_n = HTTP_PARAM_temp.indexOf("{n}") > 0; - bool tok_p = HTTP_PARAM_temp.indexOf("{p}") > 0; - bool tok_t = HTTP_PARAM_temp.indexOf("{t}") > 0; - bool tok_l = HTTP_PARAM_temp.indexOf("{l}") > 0; - bool tok_v = HTTP_PARAM_temp.indexOf("{v}") > 0; - bool tok_c = HTTP_PARAM_temp.indexOf("{c}") > 0; + bool tok_I = HTTP_PARAM_temp.indexOf(F("{I}")) > 0; + bool tok_i = HTTP_PARAM_temp.indexOf(F("{i}")) > 0; + bool tok_n = HTTP_PARAM_temp.indexOf(F("{n}")) > 0; + bool tok_p = HTTP_PARAM_temp.indexOf(F("{p}")) > 0; + bool tok_t = HTTP_PARAM_temp.indexOf(F("{t}")) > 0; + bool tok_l = HTTP_PARAM_temp.indexOf(F("{l}")) > 0; + bool tok_v = HTTP_PARAM_temp.indexOf(F("{v}")) > 0; + bool tok_c = HTTP_PARAM_temp.indexOf(F("{c}")) > 0; page += FPSTR(HTTP_FORM_PARAM_START); @@ -814,15 +814,15 @@ String WiFiManager::getParamOut(){ // if no ID use customhtml for item, else generate from param string if (_params[i]->getID() != NULL) { - if(tok_I)pitem.replace("{I}", "param_"+(String)i); - if(tok_i)pitem.replace("{i}", _params[i]->getID()); - if(tok_n)pitem.replace("{n}", _params[i]->getID()); - if(tok_p)pitem.replace("{p}", "{t}"); - if(tok_t)pitem.replace("{t}", _params[i]->getPlaceholder()); + if(tok_I)pitem.replace(F("{I}"), (String)F("param_")+(String)i); + if(tok_i)pitem.replace(F("{i}"), _params[i]->getID()); + if(tok_n)pitem.replace(F("{n}"), _params[i]->getID()); + if(tok_p)pitem.replace(F("{p}"), F("{t}")); + if(tok_t)pitem.replace(F("{t}"), _params[i]->getPlaceholder()); snprintf(parLength, 5, "%d", _params[i]->getValueLength()); - if(tok_l)pitem.replace("{l}", parLength); - if(tok_v)pitem.replace("{v}", _params[i]->getValue()); - if(tok_c)pitem.replace("{c}", _params[i]->getCustomHTML()); // meant for additional attributes, not html + if(tok_l)pitem.replace(F("{l}"), parLength); + if(tok_v)pitem.replace(F("{v}"), _params[i]->getValue()); + if(tok_c)pitem.replace(F("{c}"), _params[i]->getCustomHTML()); // meant for additional attributes, not html } else { pitem = _params[i]->getCustomHTML(); } @@ -843,8 +843,8 @@ void WiFiManager::handleWiFiStatus(){ String page; // String page = "{\"result\":true,\"count\":1}"; page = FPSTR(HTTP_JS); - server->sendHeader("Content-Length", String(page.length())); - server->send(200, "text/html", page); + server->sendHeader(F("Content-Length"), String(page.length())); + server->send(200, F("text/html"), page); } /** @@ -852,17 +852,17 @@ void WiFiManager::handleWiFiStatus(){ */ void WiFiManager::handleWifiSave() { DEBUG_WM(F("<- HTTP WiFi save ")); - DEBUG_WM(F("Method:"),server->method() == HTTP_GET ? "GET" : "POST"); + DEBUG_WM(F("Method:"),server->method() == HTTP_GET ? (String)F("GET") : (String)F("POST")); handleRequest(); //SAVE/connect here - _ssid = server->arg("s").c_str(); - _pass = server->arg("p").c_str(); + _ssid = server->arg(F("s")).c_str(); + _pass = server->arg(F("p")).c_str(); //parameters if(_paramsCount > 0){ - DEBUG_WM("Parameters"); - DEBUG_WM("-----------"); + DEBUG_WM(F("Parameters")); + DEBUG_WM(F("-----------")); for (int i = 0; i < _paramsCount; i++) { if (_params[i] == NULL) { break; @@ -876,22 +876,22 @@ void WiFiManager::handleWifiSave() { value.toCharArray(_params[i]->_value, _params[i]->_length+1); // length+1 null terminated DEBUG_WM((String)_params[i]->getID() + ":",value); } - DEBUG_WM("-----------"); + DEBUG_WM(F("-----------")); } - if (server->arg("ip") != "") { - //_sta_static_ip.fromString(server->arg("ip")); - String ip = server->arg("ip"); + if (server->arg(F("ip")) != "") { + //_sta_static_ip.fromString(server->arg(F("ip"))); + String ip = server->arg(F("ip")); optionalIPFromString(&_sta_static_ip, ip.c_str()); DEBUG_WM(F("static ip:"),ip); } - if (server->arg("gw") != "") { - String gw = server->arg("gw"); + if (server->arg(F("gw")) != "") { + String gw = server->arg(F("gw")); optionalIPFromString(&_sta_static_gw, gw.c_str()); DEBUG_WM(F("static gateway:"),gw); } - if (server->arg("sn") != "") { - String sn = server->arg("sn"); + if (server->arg(F("sn")) != "") { + String sn = server->arg(F("sn")); optionalIPFromString(&_sta_static_sn, sn.c_str()); DEBUG_WM(F("static netmask:"),sn); } @@ -900,8 +900,8 @@ void WiFiManager::handleWifiSave() { page += FPSTR(HTTP_SAVED); page += FPSTR(HTTP_END); - server->sendHeader("Content-Length", String(page.length())); - server->send(200, "text/html", page); + server->sendHeader(F("Content-Length"), String(page.length())); + server->send(200, F("text/html"), page); DEBUG_WM(F("Sent wifi save page")); @@ -918,33 +918,33 @@ void WiFiManager::handleInfo() { reportStatus(page); String infoids[] = { - "esphead", - "uptime", - "chipid", - "fchipid", - "idesize", - "flashsize", - "sdkver", - "corever", - "bootver", - "cpufreq", - "freeheap", - "memsketch", - "memsmeter", - "lastreset", - "wifihead", - "apip", - "apmac", - "apssid", - "apbssid", - "staip", - "stagw", - "stasub", - "dnss", - "host", - "stamac", - "conx", - "autoconx" + F("esphead"), + F("uptime"), + F("chipid"), + F("fchipid"), + F("idesize"), + F("flashsize"), + F("sdkver"), + F("corever"), + F("bootver"), + F("cpufreq"), + F("freeheap"), + F("memsketch"), + F("memsmeter"), + F("lastreset"), + F("wifihead"), + F("apip"), + F("apmac"), + F("apssid"), + F("apbssid"), + F("staip"), + F("stagw"), + F("stasub"), + F("dnss"), + F("host"), + F("stamac"), + F("conx"), + F("autoconx") }; for(int i=0; i<25;i++){ @@ -956,8 +956,8 @@ void WiFiManager::handleInfo() { page += FPSTR(HTTP_HELP); page += FPSTR(HTTP_END); - server->sendHeader("Content-Length", String(page.length())); - server->send(200, "text/html", page); + server->sendHeader(F("Content-Length"), String(page.length())); + server->send(200, F("text/html"), page); DEBUG_WM(F("Sent info page")); } @@ -966,111 +966,111 @@ String WiFiManager::getInfoData(String id){ String p; // @todo add versioning - if(id=="esphead")p = FPSTR(HTTP_INFO_esphead); - else if(id=="wifihead")p = FPSTR(HTTP_INFO_wifihead); - else if(id=="uptime"){ + if(id==F("esphead"))p = FPSTR(HTTP_INFO_esphead); + else if(id==F("wifihead"))p = FPSTR(HTTP_INFO_wifihead); + else if(id==F("uptime")){ // subject to rollover! p = FPSTR(HTTP_INFO_uptime); - p.replace("{1}",(String)(millis() / 1000 / 60)); - p.replace("{2}",(String)((millis() / 1000)%60)); + p.replace(F("{1}"),(String)(millis() / 1000 / 60)); + p.replace(F("{2}"),(String)((millis() / 1000)%60)); } - else if(id=="chipid"){ + else if(id==F("chipid")){ p = FPSTR(HTTP_INFO_chipid); - p.replace("{1}",(String)WIFI_getChipId()); + p.replace(F("{1}"),(String)WIFI_getChipId()); } - else if(id=="fchipid"){ + else if(id==F("fchipid")){ p = FPSTR(HTTP_INFO_fchipid); - p.replace("{1}",(String)ESP.getFlashChipId()); + p.replace(F("{1}"),(String)ESP.getFlashChipId()); } - else if(id=="idesize"){ + else if(id==F("idesize")){ p = FPSTR(HTTP_INFO_idesize); - p.replace("{1}",(String)ESP.getFlashChipSize()); + p.replace(F("{1}"),(String)ESP.getFlashChipSize()); } - else if(id=="flashsize"){ + else if(id==F("flashsize")){ p = FPSTR(HTTP_INFO_flashsize); - p.replace("{1}",(String)ESP.getFlashChipRealSize()); + p.replace(F("{1}"),(String)ESP.getFlashChipRealSize()); } - else if(id=="sdkver"){ + else if(id==F("sdkver")){ p = FPSTR(HTTP_INFO_sdkver); - p.replace("{1}",(String)system_get_sdk_version()); + p.replace(F("{1}"),(String)system_get_sdk_version()); } - else if(id=="corever"){ + else if(id==F("corever")){ p = FPSTR(HTTP_INFO_corever); - p.replace("{1}",(String)ESP.getCoreVersion()); + p.replace(F("{1}"),(String)ESP.getCoreVersion()); } - else if(id=="bootver"){ + else if(id==F("bootver")){ p = FPSTR(HTTP_INFO_bootver); - p.replace("{1}",(String)system_get_boot_version()); + p.replace(F("{1}"),(String)system_get_boot_version()); } - else if(id=="cpufreq"){ + else if(id==F("cpufreq")){ p = FPSTR(HTTP_INFO_cpufreq); - p.replace("{1}",(String)ESP.getCpuFreqMHz()); + p.replace(F("{1}"),(String)ESP.getCpuFreqMHz()); } - else if(id=="freeheap"){ + else if(id==F("freeheap")){ p = FPSTR(HTTP_INFO_freeheap); - p.replace("{1}",(String)ESP.getFreeHeap()); + p.replace(F("{1}"),(String)ESP.getFreeHeap()); } - else if(id=="memsketch"){ + else if(id==F("memsketch")){ p = FPSTR(HTTP_INFO_memsketch); - p.replace("{1}",(String)((ESP.getSketchSize()+ESP.getFreeSketchSpace())-ESP.getFreeSketchSpace())); - p.replace("{2}",(String)(ESP.getSketchSize()+ESP.getFreeSketchSpace())); + p.replace(F("{1}"),(String)((ESP.getSketchSize()+ESP.getFreeSketchSpace())-ESP.getFreeSketchSpace())); + p.replace(F("{2}"),(String)(ESP.getSketchSize()+ESP.getFreeSketchSpace())); } - else if(id=="memsmeter"){ + else if(id==F("memsmeter")){ p = FPSTR(HTTP_INFO_memsmeter); - p.replace("{1}",(String)((ESP.getSketchSize()+ESP.getFreeSketchSpace())-ESP.getFreeSketchSpace())); - p.replace("{2}",(String)(ESP.getSketchSize()+ESP.getFreeSketchSpace())); + p.replace(F("{1}"),(String)((ESP.getSketchSize()+ESP.getFreeSketchSpace())-ESP.getFreeSketchSpace())); + p.replace(F("{2}"),(String)(ESP.getSketchSize()+ESP.getFreeSketchSpace())); } - else if(id=="lastreset"){ + else if(id==F("lastreset")){ p = FPSTR(HTTP_INFO_lastreset); - p.replace("{1}",(String)ESP.getResetReason()); + p.replace(F("{1}"),(String)ESP.getResetReason()); } - else if(id=="apip"){ + else if(id==F("apip")){ p = FPSTR(HTTP_INFO_apip); - p.replace("{1}",WiFi.softAPIP().toString()); + p.replace(F("{1}"),WiFi.softAPIP().toString()); } - else if(id=="apmac"){ + else if(id==F("apmac")){ p = FPSTR(HTTP_INFO_apmac); - p.replace("{1}",(String)WiFi.softAPmacAddress()); + p.replace(F("{1}"),(String)WiFi.softAPmacAddress()); } - else if(id=="apssid"){ + else if(id==F("apssid")){ p = FPSTR(HTTP_INFO_apssid); - p.replace("{1}",(String)WiFi.SSID()); + p.replace(F("{1}"),(String)WiFi.SSID()); } - else if(id=="apbssid"){ + else if(id==F("apbssid")){ p = FPSTR(HTTP_INFO_apbssid); - p.replace("{1}",(String)WiFi.BSSIDstr()); + p.replace(F("{1}"),(String)WiFi.BSSIDstr()); } - else if(id=="staip"){ + else if(id==F("staip")){ p = FPSTR(HTTP_INFO_staip); - p.replace("{1}",WiFi.localIP().toString()); + p.replace(F("{1}"),WiFi.localIP().toString()); } - else if(id=="stagw"){ + else if(id==F("stagw")){ p = FPSTR(HTTP_INFO_stagw); - p.replace("{1}",WiFi.gatewayIP().toString()); + p.replace(F("{1}"),WiFi.gatewayIP().toString()); } - else if(id=="stasub"){ + else if(id==F("stasub")){ p = FPSTR(HTTP_INFO_stasub); - p.replace("{1}",WiFi.subnetMask().toString()); + p.replace(F("{1}"),WiFi.subnetMask().toString()); } - else if(id=="dnss"){ + else if(id==F("dnss")){ p = FPSTR(HTTP_INFO_dnss); - p.replace("{1}",WiFi.dnsIP().toString()); + p.replace(F("{1}"),WiFi.dnsIP().toString()); } - else if(id=="host"){ + else if(id==F("host")){ p = FPSTR(HTTP_INFO_host); - p.replace("{1}",WiFi.hostname()); + p.replace(F("{1}"),WiFi.hostname()); } - else if(id=="stamac)"){ + else if(id==F("stamac")){ p = FPSTR(HTTP_INFO_stamac); - p.replace("{1}",WiFi.macAddress()); + p.replace(F("{1}"),WiFi.macAddress()); } - else if(id=="conx"){ + else if(id==F("conx")){ p = FPSTR(HTTP_INFO_conx); - p.replace("{1}",WiFi.isConnected() ? FPSTR(S_y) : FPSTR(S_n)); + p.replace(F("{1}"),WiFi.isConnected() ? FPSTR(S_y) : FPSTR(S_n)); } - else if(id=="autoconx"){ + else if(id==F("autoconx")){ p = FPSTR(HTTP_INFO_autoconx); - p.replace("{1}",WiFi.getAutoConnect() ? FPSTR(S_enable) : FPSTR(S_disable)); + p.replace(F("{1}"),WiFi.getAutoConnect() ? FPSTR(S_enable) : FPSTR(S_disable)); } return p; @@ -1084,8 +1084,8 @@ void WiFiManager::handleExit() { handleRequest(); String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit page += FPSTR(S_exiting); // @token exiting - server->sendHeader("Content-Length", String(page.length())); - server->send(200, "text/html", page); + server->sendHeader(F("Content-Length"), String(page.length())); + server->send(200, F("text/html"), page); abort = true; } @@ -1099,8 +1099,8 @@ void WiFiManager::handleReset() { page += FPSTR(S_resetting); //@token resetting page += FPSTR(HTTP_END); - server->sendHeader("Content-Length", String(page.length())); - server->send(200, "text/html", page); + server->sendHeader(F("Content-Length"), String(page.length())); + server->send(200, F("text/html"), page); DEBUG_WM(F("RESETTING ESP")); delay(1000); @@ -1125,8 +1125,8 @@ void WiFiManager::handleErase() { } page += FPSTR(HTTP_END); - server->sendHeader("Content-Length", String(page.length())); - server->send(200, "text/html", page); + server->sendHeader(F("Content-Length"), String(page.length())); + server->send(200, F("text/html"), page); if(ret){ delay(2000); @@ -1145,19 +1145,19 @@ void WiFiManager::handleNotFound() { message += FPSTR(S_uri); // @token uri message += server->uri(); message += FPSTR(S_method); // @token method - message += ( server->method() == HTTP_GET ) ? "GET" : "POST"; + message += ( server->method() == HTTP_GET ) ? F("GET") : F("POST"); message += FPSTR(S_args); // @token args message += server->args(); - message += "\n"; + message += F("\n"); for ( uint8_t i = 0; i < server->args(); i++ ) { message += " " + server->argName ( i ) + ": " + server->arg ( i ) + "\n"; } - server->sendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); - server->sendHeader("Pragma", "no-cache"); - server->sendHeader("Expires", "-1"); - server->sendHeader("Content-Length", String(message.length())); - server->send ( 404, "text/plain", message ); + server->sendHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate")); + server->sendHeader(F("Pragma"), F("no-cache")); + server->sendHeader(F("Expires"), F("-1")); + server->sendHeader(F("Content-Length"), String(message.length())); + server->send ( 404, F("text/plain"), message ); } /** @@ -1172,8 +1172,8 @@ boolean WiFiManager::captivePortal() { if (!isIp(server->hostHeader())) { DEBUG_WM(F("<- Request redirected to captive portal")); - server->sendHeader("Location", String("http://") + toStringIp(server->client().localIP()), true); - server->send ( 302, "text/plain", ""); // Empty content inhibits Content-length header so we have to close the socket ourselves. + server->sendHeader(F("Location"), (String)F("http://") + toStringIp(server->client().localIP()), true); + server->send ( 302, F("text/plain"), ""); // Empty content inhibits Content-length header so we have to close the socket ourselves. server->client().stop(); // Stop is needed because we sent no content length return true; } @@ -1185,12 +1185,12 @@ void WiFiManager::reportStatus(String &page){ if (WiFi.SSID() != ""){ if (WiFi.status()==WL_CONNECTED){ str = FPSTR(HTTP_STATUS_ON); - str.replace("{u}",WiFi.localIP().toString()); - str.replace("{s}",WiFi.SSID()); + str.replace(F("{u}"),WiFi.localIP().toString()); + str.replace(F("{s}"),WiFi.SSID()); } else { str = FPSTR(HTTP_STATUS_OFF); - str.replace("{s}",WiFi.SSID()); + str.replace(F("{s}"),WiFi.SSID()); } } else { @@ -1254,6 +1254,8 @@ void WiFiManager::setWebPortalClientCheck(boolean enabled){ template void WiFiManager::DEBUG_WM(Generic text) { if (_debug) { + _debugPort.print("MEM: "); + _debugPort.println((String)ESP.getFreeHeap()); _debugPort.print("*WM: "); _debugPort.print(text); _debugPort.print("\n"); @@ -1263,6 +1265,8 @@ void WiFiManager::DEBUG_WM(Generic text) { template void WiFiManager::DEBUG_WM(Generic text,Genericb textb) { if (_debug) { + _debugPort.print("MEM: "); + _debugPort.println((String)ESP.getFreeHeap()); _debugPort.print("*WM: "); _debugPort.print(text); _debugPort.print(" "); @@ -1290,9 +1294,10 @@ void WiFiManager::debugSoftAPConfig(){ void WiFiManager::debugPlatformInfo(){ system_print_meminfo(); - DEBUG_WM("getCoreVersion():",ESP.getCoreVersion()); - DEBUG_WM("system_get_sdk_version():",system_get_sdk_version()); - DEBUG_WM("system_get_boot_version():",system_get_boot_version()); + DEBUG_WM(F("getCoreVersion():"),ESP.getCoreVersion()); + DEBUG_WM(F("system_get_sdk_version():"),system_get_sdk_version()); + DEBUG_WM(F("system_get_boot_version():"),system_get_boot_version()); + DEBUG_WM((String)ESP.getFreeHeap()); } int WiFiManager::getRSSIasQuality(int RSSI) { @@ -1357,23 +1362,23 @@ String WiFiManager::getWLStatusString(uint8_t status){ }; if(status >=0 && status <=6) return WIFI_STA_STATUS[status]; - return "UNKNOWN"; + return F("UNKNOWN"); } String WiFiManager::encryptionTypeStr(uint8_t authmode) { switch(authmode) { case ENC_TYPE_NONE: - return "None"; + return F("None"); case ENC_TYPE_WEP: - return "WEP"; + return F("WEP"); case ENC_TYPE_TKIP: - return "WPA_PSK"; + return F("WPA_PSK"); case ENC_TYPE_CCMP: - return "WPA2_PSK"; + return F("WPA2_PSK"); case ENC_TYPE_AUTO: - return "WPA_WPA2_PSK"; + return F("WPA_WPA2_PSK"); default: - return "Unknown"; + return F("Unknown"); } } From e342fd9b71f2225ba204c0b7ba37d7c821ea5273 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 14 Feb 2018 10:33:28 -0600 Subject: [PATCH 154/424] refactor ip form outputs --- WiFiManager.cpp | 103 ++++++++++++++++++------------------------------ WiFiManager.h | 4 ++ 2 files changed, 43 insertions(+), 64 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index f4da82a..e4d7db2 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -11,7 +11,6 @@ **************************************************************/ #include "WiFiManager.h" -#include "strings_en.h" // PARAMETERS @@ -114,7 +113,7 @@ WiFiManager::WiFiManager(Stream& consolePort):_debugPort(consolePort) { } WiFiManager::WiFiManager():_debugPort(Serial) { - if(_debug) debugPlatformInfo(); + if(_debug && _debugLevel > 0) debugPlatformInfo(); _usermode = WiFi.getMode(); WiFi.persistent(false); // disable persistent so scannetworks and mode switching do not cause overwrites @@ -178,7 +177,7 @@ bool WiFiManager::startAP(){ ret = WiFi.softAP(_apName.c_str()); } - debugSoftAPConfig(); + if(_debugLevel > 1) debugSoftAPConfig(); if(!ret) DEBUG_WM("[ERROR] There was a problem starting the AP"); // @bug startAP returns unreliable success status @@ -211,7 +210,7 @@ boolean WiFiManager::configPortalHasTimeout(){ if(_configPortalTimeout == 0 || (_cpClientCheck && (wifi_softap_get_station_num() > 0))){ if(millis() - timer > 30000){ timer = millis(); - DEBUG_WM("NUM CLIENTS: " + (String)wifi_softap_get_station_num()); + if(_debugLevel > 0) DEBUG_WM("NUM CLIENTS: " + (String)wifi_softap_get_station_num()); } _configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts return false; @@ -222,7 +221,7 @@ boolean WiFiManager::configPortalHasTimeout(){ if(millis() > _configPortalStart + _configPortalTimeout){ DEBUG_WM(F("config portal has timed out")); return true; - } else { + } else if(_debugLevel > 0) { if((millis() - timer) > 1000){ timer = millis(); DEBUG_WM(F("Portal Timeout In"),(String)((_configPortalStart + _configPortalTimeout-millis())/1000) + (String)F(" seconds")); @@ -375,7 +374,7 @@ uint8_t WiFiManager::handleConfigPortal(){ // sta off to stabilize AP on connect failure WiFi_Disconnect(); WiFi_enableSTA(false); - DEBUG_WM(F("Disabling STA")); + DEBUG_WM(F("Disabling STA")); } } @@ -407,6 +406,7 @@ boolean WiFiManager::stopConfigPortal(){ // @todo bug *WM: disconnect configportal // [APdisconnect] set_config failed! // *WM: disconnect configportal - softAPdisconnect failed + // still no way to reproduce reliably DEBUG_WM(F("disconnect configportal")); bool ret = WiFi.softAPdisconnect(false); if(!ret)DEBUG_WM(F("disconnect configportal - softAPdisconnect failed")); @@ -508,7 +508,6 @@ String WiFiManager::getConfigPortalSSID() { // SETTERS void WiFiManager::resetSettings() { DEBUG_WM(F("SETTINGS ERASED")); - DEBUG_WM(F("THIS MAY CAUSE AP NOT TO START UP PROPERLY. YOU NEED TO COMMENT IT OUT AFTER ERASING THE DATA.")); // @todo WHUT? WiFi.persistent(true); WiFi.disconnect(true); WiFi.persistent(false); @@ -712,59 +711,31 @@ String WiFiManager::getScanItemOut(){ return page; } +String WiFiManager::getIpForm(String id, String title, String value){ + String item = FPSTR(HTTP_FORM_LABEL); + item += FPSTR(HTTP_FORM_PARAM); + item.replace(F("{i}"), id); + item.replace(F("{n}"), id); + item.replace(F("{p}"), F("{t}")); + // item.replace(F("{p}"), default); + item.replace(F("{t}"), title); + item.replace(F("{l}"), F("15")); + item.replace(F("{v}"), value); + item.replace(F("{c}"), ""); + return item; +} + String WiFiManager::getStaticOut(){ String page; if (_staShowStaticFields || _sta_static_ip) { - // @todo how can we get these settings from memory , wifi_get_ip_info does not seem to reveal if struct ip_info is static or not - // @todo move titles to params for i18n - - String item = FPSTR(HTTP_FORM_LABEL); - item += FPSTR(HTTP_FORM_PARAM); - item.replace(F("{i}"), F("ip")); - item.replace(F("{n}"), F("ip")); - item.replace(F("{p}"), F("{t}")); - item.replace(F("{t}"), FPSTR(S_staticip)); // @token staticip - item.replace(F("{l}"), F("15")); - item.replace(F("{v}"), (_sta_static_ip ? _sta_static_ip.toString() : "")); - item.replace(F("{c}"), ""); - - // actuals as placeholder - // IPAddress sta_ip = WiFi.localIP(); - // item.replace(F("{p}"), sta_ip.toString()); - - page += item; - - item = FPSTR(HTTP_FORM_LABEL); - item += FPSTR(HTTP_FORM_PARAM); - item.replace(F("{i}"), F("gw")); - item.replace(F("{n}"), F("gw")); - item.replace(F("{p}"), F("{t}")); - item.replace(F("{t}"), FPSTR(S_staticgw)); // @token staticgw - item.replace(F("{l}"), F("15")); - item.replace(F("{v}"), (_sta_static_gw ? _sta_static_gw.toString() : "")); - item.replace(F("{c}"), ""); - - // actuals as placeholder - // IPAddress sta_gateway = WiFi.gatewayIP(); - // item.replace(F("{p}"), sta_gateway.toString()); - - page += item; - - item = FPSTR(HTTP_FORM_LABEL); - item += FPSTR(HTTP_FORM_PARAM); - item.replace(F("{i}"), F("sn")); - item.replace(F("{n}"), F("sn")); - item.replace(F("{p}"), F("{t}")); - item.replace(F("{t}"), FPSTR(S_subnet)); // @token subnet - item.replace(F("{l}"), F("15")); - item.replace(F("{v}"), (_sta_static_sn ? _sta_static_sn.toString() : "")); - item.replace(F("{c}"), ""); - - // actuals as placeholder - // IPAddress sta_subnet = WiFi.subnetMask(); - // item.replace("{p}", sta_subnet.toString()); - page += item; + // @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 + page += getIpForm(F("ip"),FPSTR(S_staticip),(_sta_static_ip ? _sta_static_ip.toString() : "")); // @token staticip + // WiFi.localIP().toString(); + page += getIpForm(F("gw"),FPSTR(S_staticgw),(_sta_static_gw ? _sta_static_gw.toString() : "")); // @token staticgw + // WiFi.gatewayIP().toString(); + page += getIpForm(F("sn"),FPSTR(S_subnet),(_sta_static_sn ? _sta_static_sn.toString() : "")); // @token subnet + // WiFi.subnetMask().toString(); page += F("
"); // @todo remove these, use css } return page; @@ -1254,8 +1225,10 @@ void WiFiManager::setWebPortalClientCheck(boolean enabled){ template void WiFiManager::DEBUG_WM(Generic text) { if (_debug) { - _debugPort.print("MEM: "); - _debugPort.println((String)ESP.getFreeHeap()); + if(_debugLevel > 2){ + _debugPort.print("MEM: "); + _debugPort.println((String)ESP.getFreeHeap()); + } _debugPort.print("*WM: "); _debugPort.print(text); _debugPort.print("\n"); @@ -1265,8 +1238,10 @@ void WiFiManager::DEBUG_WM(Generic text) { template void WiFiManager::DEBUG_WM(Generic text,Genericb textb) { if (_debug) { - _debugPort.print("MEM: "); - _debugPort.println((String)ESP.getFreeHeap()); + if(_debugLevel > 2){ + _debugPort.print("MEM: "); + _debugPort.println((String)ESP.getFreeHeap()); + } _debugPort.print("*WM: "); _debugPort.print(text); _debugPort.print(" "); @@ -1294,10 +1269,10 @@ void WiFiManager::debugSoftAPConfig(){ void WiFiManager::debugPlatformInfo(){ system_print_meminfo(); - DEBUG_WM(F("getCoreVersion():"),ESP.getCoreVersion()); - DEBUG_WM(F("system_get_sdk_version():"),system_get_sdk_version()); + DEBUG_WM(F("getCoreVersion(): "),ESP.getCoreVersion()); + DEBUG_WM(F("system_get_sdk_version(): "),system_get_sdk_version()); DEBUG_WM(F("system_get_boot_version():"),system_get_boot_version()); - DEBUG_WM((String)ESP.getFreeHeap()); + DEBUG_WM(F("getFreeHeap(): "),(String)ESP.getFreeHeap()); } int WiFiManager::getRSSIasQuality(int RSSI) { @@ -1406,7 +1381,7 @@ bool WiFiManager::WiFi_Disconnect() { DEBUG_WM(F("wifi station disconnect")); ETS_UART_INTR_DISABLE(); ret = wifi_station_disconnect(); - ETS_UART_INTR_ENABLE(); + ETS_UART_INTR_ENABLE(); return ret; } } diff --git a/WiFiManager.h b/WiFiManager.h index d828e0d..f39f8fa 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -27,6 +27,8 @@ } #endif +#include "strings_en.h" + #define WIFI_getChipId() ESP.getChipId() #define WIFI_AUTH_OPEN ENC_TYPE_NONE @@ -214,6 +216,7 @@ class WiFiManager // output helpers String getParamOut(); + String getIpForm(String id, String title, String value); String getScanItemOut(); String getStaticOut(); String getHTTPHead(String title); @@ -247,6 +250,7 @@ class WiFiManager // debugging boolean _debug = true; + uint8_t _debugLevel = 2; Stream& _debugPort; // debug output stream ref template void DEBUG_WM(Generic text); From 3d3518a10a63eaf4ddae764ed41286085477d1d0 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 14 Feb 2018 10:50:57 -0600 Subject: [PATCH 155/424] adds disconnect method for users non persistent disconnect --- WiFiManager.cpp | 4 ++++ WiFiManager.h | 1 + 2 files changed, 5 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index e4d7db2..d46fd44 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1374,6 +1374,10 @@ bool WiFiManager::WiFi_Mode(WiFiMode_t m) { return WiFi_Mode(m,false); } +bool WiFiManager::disconnect(){ + return WiFi_Disconnect(); +} + // sta disconnect without persistent bool WiFiManager::WiFi_Disconnect() { if((WiFi.getMode() & WIFI_STA) != 0) { diff --git a/WiFiManager.h b/WiFiManager.h index f39f8fa..ede7d87 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -95,6 +95,7 @@ class WiFiManager void resetSettings(); void reboot(); + boolean disconnect(); // non persistent disconnect //sets timeout before AP,webserver loop ends and exits even if there has been no setup. //useful for devices that failed to connect at some point and got stuck in a webserver loop From 78f7de38adfba799cf8c3c1e14f8117d228bb8d2 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 14 Feb 2018 10:54:04 -0600 Subject: [PATCH 156/424] publicized debug helpers --- WiFiManager.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WiFiManager.h b/WiFiManager.h index ede7d87..7de558a 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -140,6 +140,9 @@ class WiFiManager //if true, reset timeout when webclient connects (true), suggest disabling if captiveportal is open void setWebPortalClientCheck(boolean enabled); + void debugSoftAPConfig(); + void debugPlatformInfo(); + private: std::unique_ptr dnsServer; std::unique_ptr server; @@ -213,7 +216,6 @@ class WiFiManager bool WiFi_enableSTA(bool enable); bool WiFi_enableSTA(bool enable,bool persistent); bool WiFi_eraseConfig(); - void debugSoftAPConfig(); // output helpers String getParamOut(); @@ -230,7 +232,6 @@ class WiFiManager boolean validApPassword(); String encryptionTypeStr(uint8_t authmode); void reportStatus(String &page); - void debugPlatformInfo(); String getInfoData(String id); // flags From 8e7663b52b043f0e87e731be1e48a8d6391e5316 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 14 Feb 2018 11:13:28 -0600 Subject: [PATCH 157/424] ugh aliases --- WiFiManager.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.h b/WiFiManager.h index 7de558a..8ad4629 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -95,7 +95,7 @@ class WiFiManager void resetSettings(); void reboot(); - boolean disconnect(); // non persistent disconnect + bool disconnect(); // non persistent disconnect //sets timeout before AP,webserver loop ends and exits even if there has been no setup. //useful for devices that failed to connect at some point and got stuck in a webserver loop @@ -142,7 +142,7 @@ class WiFiManager void debugSoftAPConfig(); void debugPlatformInfo(); - + private: std::unique_ptr dnsServer; std::unique_ptr server; From ba3a2c8451da3251c69557a5c319ed22ed8ecb25 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 14 Feb 2018 12:41:38 -0600 Subject: [PATCH 158/424] moved all tokens to strings.h --- WiFiManager.cpp | 155 ++++++++++++++++++++++++------------------------ WiFiManager.h | 6 +- strings_en.h | 28 +++++++-- 3 files changed, 105 insertions(+), 84 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index d46fd44..79eac51 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -137,7 +137,7 @@ WiFiManager::~WiFiManager() { // AUTOCONNECT boolean WiFiManager::autoConnect() { - String ssid = "ESP" + String(WIFI_getChipId()); + String ssid = (String)F("ESP") + String(WIFI_getChipId()); return autoConnect(ssid.c_str(), NULL); } @@ -261,7 +261,7 @@ void WiFiManager::setupConfigPortal() { } boolean WiFiManager::startConfigPortal() { - String ssid = "ESP" + String(WIFI_getChipId()); + String ssid = (String)F("ESP") + String(WIFI_getChipId()); return startConfigPortal(ssid.c_str(), NULL); } @@ -488,7 +488,7 @@ uint8_t WiFiManager::waitForConnectResult() { if (status == WL_CONNECTED || status == WL_CONNECT_FAILED) { return status; } - DEBUG_WM ("."); + DEBUG_WM (F(".")); delay(100); } return status; @@ -553,7 +553,7 @@ void WiFiManager::setBreakAfterConfig(boolean shouldBreak) { String WiFiManager::getHTTPHead(String title){ String page; page += FPSTR(HTTP_HEAD); - page.replace(F("{v}"), title); + page.replace(FPSTR(T_v), title); page += FPSTR(HTTP_SCRIPT); page += FPSTR(HTTP_STYLE); page += _customHeadElement; @@ -577,7 +577,7 @@ void WiFiManager::handleRoot() { handleRequest(); String page = getHTTPHead(FPSTR(S_options)); // @token options String str = FPSTR(HTTP_ROOT_MAIN); - str.replace(F("{v}"),configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading + str.replace(FPSTR(T_v),configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading page += str; page += FPSTR(HTTP_PORTAL_OPTIONS); reportStatus(page); @@ -599,7 +599,7 @@ void WiFiManager::handleWifi(boolean scan) { page += getScanItemOut(); } String pitem = FPSTR(HTTP_FORM_START); - pitem.replace(F("{v}"), WiFi.SSID()); + pitem.replace(FPSTR(T_v), WiFi.SSID()); page += pitem; page += getStaticOut(); @@ -668,11 +668,12 @@ String WiFiManager::getScanItemOut(){ // token precheck, to speed up replacements on large ap lists String HTTP_ITEM_STR = FPSTR(HTTP_ITEM); - bool tok_r = HTTP_ITEM_STR.indexOf(F("{r}")) > 0; - bool tok_R = HTTP_ITEM_STR.indexOf(F("{R}")) > 0; - bool tok_e = HTTP_ITEM_STR.indexOf(F("{e}")) > 0; - bool tok_q = HTTP_ITEM_STR.indexOf(F("{q}")) > 0; - bool tok_i = HTTP_ITEM_STR.indexOf(F("{i}")) > 0; + bool tok_r = HTTP_ITEM_STR.indexOf(FPSTR(T_r)) > 0; + bool tok_R = HTTP_ITEM_STR.indexOf(FPSTR(T_R)) > 0; + bool tok_e = HTTP_ITEM_STR.indexOf(FPSTR(T_e)) > 0; + bool tok_q = HTTP_ITEM_STR.indexOf(FPSTR(T_q)) > 0; + bool tok_i = HTTP_ITEM_STR.indexOf(FPSTR(T_i)) > 0; + //display networks in page for (int i = 0; i < n; i++) { @@ -684,17 +685,17 @@ String WiFiManager::getScanItemOut(){ uint8_t enc_type = WiFi.encryptionType(indices[i]); if (_minimumQuality == -1 || _minimumQuality < rssiperc) { - String item = FPSTR(HTTP_ITEM); - item.replace(F("{v}"), WiFi.SSID(indices[i])); // ssid no encoding - if(tok_e) item.replace(F("{e}"), encryptionTypeStr(enc_type)); - if(tok_r) item.replace(F("{r}"), (String)rssiperc); // rssi percentage 0-100 - if(tok_R) item.replace(F("{R}"), (String)WiFi.RSSI(indices[i])); // rssi db - if(tok_q) item.replace(F("{q}"), (String)round(map(rssiperc,0,100,1,4))); //quality icon 1-4 + String item = HTTP_ITEM_STR; + item.replace(FPSTR(T_v), WiFi.SSID(indices[i])); // ssid no encoding + if(tok_e) item.replace(FPSTR(T_e), encryptionTypeStr(enc_type)); + if(tok_r) item.replace(FPSTR(T_r), (String)rssiperc); // rssi percentage 0-100 + if(tok_R) item.replace(FPSTR(T_R), (String)WiFi.RSSI(indices[i])); // rssi db + if(tok_q) item.replace(FPSTR(T_q), (String)round(map(rssiperc,0,100,1,4))); //quality icon 1-4 if(tok_i){ if (enc_type != WIFI_AUTH_OPEN) { - item.replace(F("{i}"), F("l")); + item.replace(FPSTR(T_i), FPSTR(T_l)); } else { - item.replace(F("{i}"), ""); + item.replace(FPSTR(T_i), ""); } } //DEBUG_WM(item); @@ -714,14 +715,14 @@ String WiFiManager::getScanItemOut(){ String WiFiManager::getIpForm(String id, String title, String value){ String item = FPSTR(HTTP_FORM_LABEL); item += FPSTR(HTTP_FORM_PARAM); - item.replace(F("{i}"), id); - item.replace(F("{n}"), id); - item.replace(F("{p}"), F("{t}")); - // item.replace(F("{p}"), default); - item.replace(F("{t}"), title); - item.replace(F("{l}"), F("15")); - item.replace(F("{v}"), value); - item.replace(F("{c}"), ""); + item.replace(FPSTR(T_i), id); + item.replace(FPSTR(T_n), id); + item.replace(FPSTR(T_p), FPSTR(T_t)); + // item.replace(FPSTR(T_p), default); + item.replace(FPSTR(T_t), title); + item.replace(FPSTR(T_l), F("15")); + item.replace(FPSTR(T_v), value); + item.replace(FPSTR(T_c), ""); return item; } @@ -748,14 +749,14 @@ String WiFiManager::getParamOut(){ String HTTP_PARAM_temp = FPSTR(HTTP_FORM_LABEL); HTTP_PARAM_temp += FPSTR(HTTP_FORM_PARAM); - bool tok_I = HTTP_PARAM_temp.indexOf(F("{I}")) > 0; - bool tok_i = HTTP_PARAM_temp.indexOf(F("{i}")) > 0; - bool tok_n = HTTP_PARAM_temp.indexOf(F("{n}")) > 0; - bool tok_p = HTTP_PARAM_temp.indexOf(F("{p}")) > 0; - bool tok_t = HTTP_PARAM_temp.indexOf(F("{t}")) > 0; - bool tok_l = HTTP_PARAM_temp.indexOf(F("{l}")) > 0; - bool tok_v = HTTP_PARAM_temp.indexOf(F("{v}")) > 0; - bool tok_c = HTTP_PARAM_temp.indexOf(F("{c}")) > 0; + bool tok_I = HTTP_PARAM_temp.indexOf(FPSTR(T_i)) > 0; + bool tok_i = HTTP_PARAM_temp.indexOf(FPSTR(T_i)) > 0; + bool tok_n = HTTP_PARAM_temp.indexOf(FPSTR(T_n)) > 0; + bool tok_p = HTTP_PARAM_temp.indexOf(FPSTR(T_p)) > 0; + bool tok_t = HTTP_PARAM_temp.indexOf(FPSTR(T_t)) > 0; + bool tok_l = HTTP_PARAM_temp.indexOf(FPSTR(T_l)) > 0; + bool tok_v = HTTP_PARAM_temp.indexOf(FPSTR(T_v)) > 0; + bool tok_c = HTTP_PARAM_temp.indexOf(FPSTR(T_c)) > 0; page += FPSTR(HTTP_FORM_PARAM_START); @@ -785,15 +786,15 @@ String WiFiManager::getParamOut(){ // if no ID use customhtml for item, else generate from param string if (_params[i]->getID() != NULL) { - if(tok_I)pitem.replace(F("{I}"), (String)F("param_")+(String)i); - if(tok_i)pitem.replace(F("{i}"), _params[i]->getID()); - if(tok_n)pitem.replace(F("{n}"), _params[i]->getID()); - if(tok_p)pitem.replace(F("{p}"), F("{t}")); - if(tok_t)pitem.replace(F("{t}"), _params[i]->getPlaceholder()); - snprintf(parLength, 5, "%d", _params[i]->getValueLength()); - if(tok_l)pitem.replace(F("{l}"), parLength); - if(tok_v)pitem.replace(F("{v}"), _params[i]->getValue()); - if(tok_c)pitem.replace(F("{c}"), _params[i]->getCustomHTML()); // meant for additional attributes, not html + if(tok_I)pitem.replace(FPSTR(T_i), (String)F("param_")+(String)i); + if(tok_i)pitem.replace(FPSTR(T_i), _params[i]->getID()); + if(tok_n)pitem.replace(FPSTR(T_n), _params[i]->getID()); + if(tok_p)pitem.replace(FPSTR(T_p), FPSTR(T_t)); + if(tok_t)pitem.replace(FPSTR(T_t), _params[i]->getPlaceholder()); + snprintf(parLength, 5, PSTR("%d"), _params[i]->getValueLength()); + if(tok_l)pitem.replace(FPSTR(T_l), parLength); + if(tok_v)pitem.replace(FPSTR(T_v), _params[i]->getValue()); + if(tok_c)pitem.replace(FPSTR(T_c), _params[i]->getCustomHTML()); // meant for additional attributes, not html } else { pitem = _params[i]->getCustomHTML(); } @@ -813,7 +814,9 @@ void WiFiManager::handleWiFiStatus(){ handleRequest(); String page; // String page = "{\"result\":true,\"count\":1}"; - page = FPSTR(HTTP_JS); + #ifdef JSTEST + page = FPSTR(HTTP_JS); + #endif server->sendHeader(F("Content-Length"), String(page.length())); server->send(200, F("text/html"), page); } @@ -942,106 +945,106 @@ String WiFiManager::getInfoData(String id){ else if(id==F("uptime")){ // subject to rollover! p = FPSTR(HTTP_INFO_uptime); - p.replace(F("{1}"),(String)(millis() / 1000 / 60)); - p.replace(F("{2}"),(String)((millis() / 1000)%60)); + p.replace(FPSTR(T_1),(String)(millis() / 1000 / 60)); + p.replace(FPSTR(T_2),(String)((millis() / 1000) % 60)); } else if(id==F("chipid")){ p = FPSTR(HTTP_INFO_chipid); - p.replace(F("{1}"),(String)WIFI_getChipId()); + p.replace(FPSTR(T_1),(String)WIFI_getChipId()); } else if(id==F("fchipid")){ p = FPSTR(HTTP_INFO_fchipid); - p.replace(F("{1}"),(String)ESP.getFlashChipId()); + p.replace(FPSTR(T_1),(String)ESP.getFlashChipId()); } else if(id==F("idesize")){ p = FPSTR(HTTP_INFO_idesize); - p.replace(F("{1}"),(String)ESP.getFlashChipSize()); + p.replace(FPSTR(T_1),(String)ESP.getFlashChipSize()); } else if(id==F("flashsize")){ p = FPSTR(HTTP_INFO_flashsize); - p.replace(F("{1}"),(String)ESP.getFlashChipRealSize()); + p.replace(FPSTR(T_1),(String)ESP.getFlashChipRealSize()); } else if(id==F("sdkver")){ p = FPSTR(HTTP_INFO_sdkver); - p.replace(F("{1}"),(String)system_get_sdk_version()); + p.replace(FPSTR(T_1),(String)system_get_sdk_version()); } else if(id==F("corever")){ p = FPSTR(HTTP_INFO_corever); - p.replace(F("{1}"),(String)ESP.getCoreVersion()); + p.replace(FPSTR(T_1),(String)ESP.getCoreVersion()); } else if(id==F("bootver")){ p = FPSTR(HTTP_INFO_bootver); - p.replace(F("{1}"),(String)system_get_boot_version()); + p.replace(FPSTR(T_1),(String)system_get_boot_version()); } else if(id==F("cpufreq")){ p = FPSTR(HTTP_INFO_cpufreq); - p.replace(F("{1}"),(String)ESP.getCpuFreqMHz()); + p.replace(FPSTR(T_1),(String)ESP.getCpuFreqMHz()); } else if(id==F("freeheap")){ p = FPSTR(HTTP_INFO_freeheap); - p.replace(F("{1}"),(String)ESP.getFreeHeap()); + p.replace(FPSTR(T_1),(String)ESP.getFreeHeap()); } else if(id==F("memsketch")){ p = FPSTR(HTTP_INFO_memsketch); - p.replace(F("{1}"),(String)((ESP.getSketchSize()+ESP.getFreeSketchSpace())-ESP.getFreeSketchSpace())); - p.replace(F("{2}"),(String)(ESP.getSketchSize()+ESP.getFreeSketchSpace())); + p.replace(FPSTR(T_1),(String)((ESP.getSketchSize()+ESP.getFreeSketchSpace())-ESP.getFreeSketchSpace())); + p.replace(FPSTR(T_2),(String)(ESP.getSketchSize()+ESP.getFreeSketchSpace())); } else if(id==F("memsmeter")){ p = FPSTR(HTTP_INFO_memsmeter); - p.replace(F("{1}"),(String)((ESP.getSketchSize()+ESP.getFreeSketchSpace())-ESP.getFreeSketchSpace())); - p.replace(F("{2}"),(String)(ESP.getSketchSize()+ESP.getFreeSketchSpace())); + p.replace(FPSTR(T_1),(String)((ESP.getSketchSize()+ESP.getFreeSketchSpace())-ESP.getFreeSketchSpace())); + p.replace(FPSTR(T_2),(String)(ESP.getSketchSize()+ESP.getFreeSketchSpace())); } else if(id==F("lastreset")){ p = FPSTR(HTTP_INFO_lastreset); - p.replace(F("{1}"),(String)ESP.getResetReason()); + p.replace(FPSTR(T_1),(String)ESP.getResetReason()); } else if(id==F("apip")){ p = FPSTR(HTTP_INFO_apip); - p.replace(F("{1}"),WiFi.softAPIP().toString()); + p.replace(FPSTR(T_1),WiFi.softAPIP().toString()); } else if(id==F("apmac")){ p = FPSTR(HTTP_INFO_apmac); - p.replace(F("{1}"),(String)WiFi.softAPmacAddress()); + p.replace(FPSTR(T_1),(String)WiFi.softAPmacAddress()); } else if(id==F("apssid")){ p = FPSTR(HTTP_INFO_apssid); - p.replace(F("{1}"),(String)WiFi.SSID()); + p.replace(FPSTR(T_1),(String)WiFi.SSID()); } else if(id==F("apbssid")){ p = FPSTR(HTTP_INFO_apbssid); - p.replace(F("{1}"),(String)WiFi.BSSIDstr()); + p.replace(FPSTR(T_1),(String)WiFi.BSSIDstr()); } else if(id==F("staip")){ p = FPSTR(HTTP_INFO_staip); - p.replace(F("{1}"),WiFi.localIP().toString()); + p.replace(FPSTR(T_1),WiFi.localIP().toString()); } else if(id==F("stagw")){ p = FPSTR(HTTP_INFO_stagw); - p.replace(F("{1}"),WiFi.gatewayIP().toString()); + p.replace(FPSTR(T_1),WiFi.gatewayIP().toString()); } else if(id==F("stasub")){ p = FPSTR(HTTP_INFO_stasub); - p.replace(F("{1}"),WiFi.subnetMask().toString()); + p.replace(FPSTR(T_1),WiFi.subnetMask().toString()); } else if(id==F("dnss")){ p = FPSTR(HTTP_INFO_dnss); - p.replace(F("{1}"),WiFi.dnsIP().toString()); + p.replace(FPSTR(T_1),WiFi.dnsIP().toString()); } else if(id==F("host")){ p = FPSTR(HTTP_INFO_host); - p.replace(F("{1}"),WiFi.hostname()); + p.replace(FPSTR(T_1),WiFi.hostname()); } else if(id==F("stamac")){ p = FPSTR(HTTP_INFO_stamac); - p.replace(F("{1}"),WiFi.macAddress()); + p.replace(FPSTR(T_1),WiFi.macAddress()); } else if(id==F("conx")){ p = FPSTR(HTTP_INFO_conx); - p.replace(F("{1}"),WiFi.isConnected() ? FPSTR(S_y) : FPSTR(S_n)); + p.replace(FPSTR(T_1),WiFi.isConnected() ? FPSTR(S_y) : FPSTR(S_n)); } else if(id==F("autoconx")){ p = FPSTR(HTTP_INFO_autoconx); - p.replace(F("{1}"),WiFi.getAutoConnect() ? FPSTR(S_enable) : FPSTR(S_disable)); + p.replace(FPSTR(T_1),WiFi.getAutoConnect() ? FPSTR(S_enable) : FPSTR(S_disable)); } return p; @@ -1156,12 +1159,12 @@ void WiFiManager::reportStatus(String &page){ if (WiFi.SSID() != ""){ if (WiFi.status()==WL_CONNECTED){ str = FPSTR(HTTP_STATUS_ON); - str.replace(F("{u}"),WiFi.localIP().toString()); - str.replace(F("{s}"),WiFi.SSID()); + str.replace(FPSTR(T_i),WiFi.localIP().toString()); + str.replace(FPSTR(T_v),WiFi.SSID()); } else { str = FPSTR(HTTP_STATUS_OFF); - str.replace(F("{s}"),WiFi.SSID()); + str.replace(FPSTR(T_v),WiFi.SSID()); } } else { diff --git a/WiFiManager.h b/WiFiManager.h index 8ad4629..f993ac4 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -95,7 +95,7 @@ class WiFiManager void resetSettings(); void reboot(); - bool disconnect(); // non persistent disconnect + bool disconnect(); // non persistent disconnect //sets timeout before AP,webserver loop ends and exits even if there has been no setup. //useful for devices that failed to connect at some point and got stuck in a webserver loop @@ -123,8 +123,6 @@ class WiFiManager void setBreakAfterConfig(boolean shouldBreak); //if this is set, portal will be blocking and wait until save or exit, is false user must manually process to handle config portal void setConfigPortalBlocking(boolean shouldBlock); - - //if this is set, customise style void setCustomHeadElement(const char* element); //if this is true, remove duplicated Access Points - defaut true @@ -139,6 +137,8 @@ class WiFiManager void setCaptivePortalClientCheck(boolean enabled); //if true, reset timeout when webclient connects (true), suggest disabling if captiveportal is open void setWebPortalClientCheck(boolean enabled); + // if true, wifiscan will show percentage instead of quality icons, until we have better templating + void setScanDispPerc(boolean enabled); void debugSoftAPConfig(); void debugPlatformInfo(); diff --git a/strings_en.h b/strings_en.h index 3767942..13b0f72 100644 --- a/strings_en.h +++ b/strings_en.h @@ -23,8 +23,8 @@ const char HTTP_SAVED[] PROGMEM = "
Saving Credential const char HTTP_END[] PROGMEM = "
"; const char HTTP_ERASEBTN[] PROGMEM = "
"; -const char HTTP_STATUS_ON[] PROGMEM = "
Connected to {s}
with IP {u}
"; -const char HTTP_STATUS_OFF[] PROGMEM = "
Not Connected to {s}
"; +const char HTTP_STATUS_ON[] PROGMEM = "
Connected to {v}
with IP {i}
"; +const char HTTP_STATUS_OFF[] PROGMEM = "
Not Connected to {v}
"; const char HTTP_STATUS_NONE[] PROGMEM = "
No AP set
"; const char HTTP_STYLE[] PROGMEM = ""; const char HTTP_HELP[] PROGMEM = @@ -213,6 +214,7 @@ const char T_e[] PROGMEM = "{e}"; // @token e const char T_q[] PROGMEM = "{q}"; // @token q const char T_r[] PROGMEM = "{r}"; // @token r const char T_R[] PROGMEM = "{R}"; // @token R +const char T_h[] PROGMEM = "{h}"; // @token h // http const char HTTP_HEAD_CL[] PROGMEM = "Content-Length"; From 41b47171485624ed2fe81350d06b063eaa368e89 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 15 Feb 2018 12:23:20 -0600 Subject: [PATCH 180/424] more strings progmem --- WiFiManager.cpp | 8 ++++---- strings_en.h | 38 ++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 82a3e29..9a0ee69 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -743,7 +743,7 @@ String WiFiManager::getScanItemOut(){ } } - page += "
"; + page += FPSTR(HTTP_BR); } return page; @@ -774,7 +774,7 @@ String WiFiManager::getStaticOut(){ // WiFi.gatewayIP().toString(); page += getIpForm(FPSTR(S_sn),FPSTR(S_subnet),(_sta_static_sn ? _sta_static_sn.toString() : "")); // @token subnet // WiFi.subnetMask().toString(); - page += F("
"); // @todo remove these, use css + page += FPSTR(HTTP_BR); // @todo remove these, use css } return page; } @@ -823,7 +823,7 @@ String WiFiManager::getParamOut(){ // if no ID use customhtml for item, else generate from param string if (_params[i]->getID() != NULL) { - if(tok_I)pitem.replace(FPSTR(T_i), (String)F("param_")+(String)i); + if(tok_I)pitem.replace(FPSTR(T_i), (String)FPSTR(S_parampre)+(String)i); if(tok_i)pitem.replace(FPSTR(T_i), _params[i]->getID()); if(tok_n)pitem.replace(FPSTR(T_n), _params[i]->getID()); if(tok_p)pitem.replace(FPSTR(T_p), FPSTR(T_t)); @@ -880,7 +880,7 @@ void WiFiManager::handleWifiSave() { } //read parameter from server String value; - if(server->arg("param_"+(String)i) != NULL) value = server->arg("param_"+(String)i).c_str(); + if(server->arg((String)FPSTR(S_parampre)+(String)i) != NULL) value = server->arg((String)FPSTR(S_parampre)+(String)i).c_str(); else value = server->arg(_params[i]->getID()).c_str(); //store it in array diff --git a/strings_en.h b/strings_en.h index 31e1adc..69bf2f1 100644 --- a/strings_en.h +++ b/strings_en.h @@ -45,6 +45,7 @@ const char HTTP_ERASEBTN[] PROGMEM = "
Date: Thu, 15 Feb 2018 13:11:36 -0600 Subject: [PATCH 181/424] oops broke lock icons --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 9a0ee69..d6fb33f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -730,7 +730,7 @@ String WiFiManager::getScanItemOut(){ if(tok_q) item.replace(FPSTR(T_q), (String)round(map(rssiperc,0,100,1,4))); //quality icon 1-4 if(tok_i){ if (enc_type != WIFI_AUTH_OPEN) { - item.replace(FPSTR(T_i), FPSTR(T_l)); + item.replace(FPSTR(T_i), F("l")); } else { item.replace(FPSTR(T_i), ""); } From 14c5169ac91192355be8c37300db2f643a256ec8 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 15 Feb 2018 16:59:16 -0600 Subject: [PATCH 182/424] bugged --- WiFiManager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index d6fb33f..85b9dec 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -438,7 +438,8 @@ boolean WiFiManager::stopConfigPortal(){ DEBUG_WM(F("disconnect configportal")); bool ret = WiFi.softAPdisconnect(false); if(!ret)DEBUG_WM(F("disconnect configportal - softAPdisconnect failed")); - WiFi_Mode(_usermode); // restore users wifi mode + // WiFi_Mode(_usermode); // restore users wifi mode + DEBUG_WM("uswermode",_usermode); configPortalActive = false; return ret; } From 1ee8f5a1a9a5af4331c4dc8cf5fcd68ca5897fcc Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sun, 18 Feb 2018 09:43:52 -0600 Subject: [PATCH 183/424] #528 adds getLastConxResult --- WiFiManager.cpp | 6 ++++++ WiFiManager.h | 11 +++++++---- strings_en.h | 8 ++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 85b9dec..f3f196c 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -170,6 +170,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { if (WiFi.status() == WL_CONNECTED || connectWifi("", "") == WL_CONNECTED) { //connected DEBUG_WM(F("IP Address:"),WiFi.localIP()); + _lastconxresult = WL_CONNECTED; return true; } // not connected start configportal @@ -492,6 +493,7 @@ int WiFiManager::connectWifi(String ssid, String pass) { connRes = waitForConnectResult(); } + _lastconxresult = connRes; return connRes; } @@ -1429,6 +1431,10 @@ void WiFiManager::setScanDispPerc(boolean enabled){ _scanDispOptions = true; } +uint8_t WiFiManager::getLastConxResult(){ + return _lastconxresult; +} + // HELPERS template diff --git a/WiFiManager.h b/WiFiManager.h index 9a9ce8c..7dd3f83 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -173,6 +173,10 @@ class WiFiManager void debugSoftAPConfig(); // debug output platform info and versioning void debugPlatformInfo(); + // get last connection result, includes autoconnect and wifisave + uint8_t getLastConxResult(); + // get a status as string + String getWLStatusString(uint8_t status); private: std::unique_ptr dnsServer; @@ -204,8 +208,8 @@ class WiFiManager unsigned long _configPortalStart = 0; // config portal start time (updated for timeouts) unsigned long _webPortalAccessed = 0; // last web access time WiFiMode_t _usermode = WIFI_OFF; - - String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid + String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid + uint8_t _lastconxresult = WL_IDLE_STATUS; // option parameters int _minimumQuality = -1; // filter wifiscan ap by this rssi @@ -272,7 +276,6 @@ class WiFiManager String getHTTPHead(String title); //helpers - String getWLStatusString(uint8_t status); int getRSSIasQuality(int RSSI); boolean isIp(String str); String toStringIp(IPAddress ip); @@ -299,7 +302,7 @@ class WiFiManager // debugging boolean _debug = true; - uint8_t _debugLevel = 2; + uint8_t _debugLevel = 1; Stream& _debugPort; // debug output stream ref template void DEBUG_WM(Generic text); diff --git a/strings_en.h b/strings_en.h index 69bf2f1..968bfff 100644 --- a/strings_en.h +++ b/strings_en.h @@ -225,11 +225,11 @@ const char HTTP_HEAD_CT2[] PROGMEM = "text/plain"; const char * const WIFI_STA_STATUS[] PROGMEM { - "WL_IDLE_STATUS", - "WL_NO_SSID_AVAIL", + "WL_IDLE_STATUS", // STATION_IDLE + "WL_NO_SSID_AVAIL", // STATION_NO_AP_FOUND "WL_SCAN_COMPLETED", - "WL_CONNECTED", - "WL_CONNECT_FAILED", + "WL_CONNECTED", // STATION_GOT_IP + "WL_CONNECT_FAILED",// STATION_CONNECT_FAIL, STATION_WRONG_PASSWORD(NI) "WL_CONNECTION_LOST", "WL_DISCONNECTED" }; From 1d6a7275e7a6cd668504b6b22a46d2306f5f252d Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sun, 18 Feb 2018 10:24:03 -0600 Subject: [PATCH 184/424] gitignore no gitignore? add more stuff --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d837572 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +platformio.ini From f3db838ae186f96ebbe6dc0c64642ac9c33ec33c Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sun, 18 Feb 2018 10:39:35 -0600 Subject: [PATCH 185/424] fix info page and adds esp32 aphostname --- WiFiManager.cpp | 11 +++++++++-- strings_en.h | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index f3f196c..a9f7e51 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -963,7 +963,7 @@ void WiFiManager::handleInfo() { F("autoconx") }; - for(int i=0; i<25;i++){ + for(int i=0; i<27;i++){ if(infoids[i] != NULL) page += getInfoData(infoids[i]); } page += F("
"); @@ -988,6 +988,7 @@ void WiFiManager::handleInfo() { F("wifihead"), F("apip"), F("apmac"), + F("aphost"), F("apssid"), F("apbssid"), F("staip"), @@ -1000,7 +1001,7 @@ void WiFiManager::handleInfo() { F("autoconx") }; - for(int i=0; i<19;i++){ + for(int i=0; i<23;i++){ if(infoids[i] != NULL) page += getInfoData(infoids[i]); } page += F(""); @@ -1137,6 +1138,12 @@ String WiFiManager::getInfoData(String id){ p = FPSTR(HTTP_INFO_apmac); p.replace(FPSTR(T_1),(String)WiFi.softAPmacAddress()); } + #ifdef ESP32 + else if(id==F("aphost")){ + p = FPSTR(HTTP_INFO_aphost); + p.replace(FPSTR(T_1),WiFi.softAPgetHostname()); + } + #endif else if(id==F("apssid")){ p = FPSTR(HTTP_INFO_apssid); p.replace(FPSTR(T_1),(String)WiFi_SSID()); diff --git a/strings_en.h b/strings_en.h index 968bfff..b198ecb 100644 --- a/strings_en.h +++ b/strings_en.h @@ -114,7 +114,8 @@ const char HTTP_JS[] PROGMEM = #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_lastreset[] PROGMEM = "
Last reset reason
CPU0: {1}
CPU1: {2}
"; + const char HTTP_INFO_aphost[] PROGMEM = "
Acccess Point Hostname
{1}
"; #else const char HTTP_INFO_esphead[] PROGMEM = "

esp8266


"; const char HTTP_INFO_flashsize[] PROGMEM = "
Real Flash Size
{1} bytes
"; From cb7cbec1f8829774c485f6e06d7ba475fa168a66 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sun, 18 Feb 2018 12:27:20 -0600 Subject: [PATCH 186/424] testing #527 --- WiFiManager.cpp | 39 ++++++++++++++++++++++++++++++++++++--- WiFiManager.h | 4 ++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index a9f7e51..994a761 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -166,6 +166,14 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { // so we must force it on else, if not connectimeout then waitforconnectionresult gets stuck endless loop WiFi_autoReconnect(); + if(_hostname != ""){ + #ifdef ESP8266 + WiFi.hostname(_hostname); + #elif defined(ESP32) + WiFi.setHostname(_hostname); + #endif + } + // if already connected, or try stored connect if (WiFi.status() == WL_CONNECTED || connectWifi("", "") == WL_CONNECTED) { //connected @@ -208,7 +216,13 @@ bool WiFiManager::startAP(){ if ( _apcallback != NULL) { _apcallback(this); } - + + #ifdef ESP32 + if(ret && _hostname != ""){ + WiFi.softAPsetHostname(_hostname); + } + #endif + return ret; } @@ -279,6 +293,7 @@ void WiFiManager::setupConfigPortal() { server->on((String)F("/i"), std::bind(&WiFiManager::handleInfo, this)); server->on((String)F("/r"), std::bind(&WiFiManager::handleReset, this)); server->on((String)F("/exit"), std::bind(&WiFiManager::handleExit, this)); + // server->on((String)F("/exit"), std::bind(&WiFiManager::stopCaptivePortal, this)); server->on((String)F("/erase"), std::bind(&WiFiManager::handleErase, this)); server->on((String)F("/status"), std::bind(&WiFiManager::handleWiFiStatus, this)); //server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler. @@ -439,8 +454,8 @@ boolean WiFiManager::stopConfigPortal(){ DEBUG_WM(F("disconnect configportal")); bool ret = WiFi.softAPdisconnect(false); if(!ret)DEBUG_WM(F("disconnect configportal - softAPdisconnect failed")); - // WiFi_Mode(_usermode); // restore users wifi mode - DEBUG_WM("uswermode",_usermode); + // WiFi_Mode(_usermode); // restore users wifi mode, BUG https://github.com/esp8266/Arduino/issues/4372 + // DEBUG_WM("usermode",_usermode); configPortalActive = false; return ret; } @@ -494,6 +509,15 @@ int WiFiManager::connectWifi(String ssid, String pass) { } _lastconxresult = connRes; + + if(connRes == WL_CONNECTED && _hostname != ""){ + #ifdef ESP8266 + WiFi.hostname(_hostname); + #elif defined(ESP32) + WiFi.setHostname(_hostname); + #endif + } + return connRes; } @@ -1295,6 +1319,10 @@ boolean WiFiManager::captivePortal() { return false; } +void WiFiManager::stopCaptivePortal(){ + _enableCaptivePortal= false; +} + void WiFiManager::reportStatus(String &page){ String str; if (WiFi_SSID() != ""){ @@ -1442,6 +1470,11 @@ uint8_t WiFiManager::getLastConxResult(){ return _lastconxresult; } +bool WiFiManager::setHostname(const char * hostname){ + //@todo max length 32 + _hostname = hostname; +} + // HELPERS template diff --git a/WiFiManager.h b/WiFiManager.h index 7dd3f83..51e40c8 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -177,6 +177,7 @@ class WiFiManager uint8_t getLastConxResult(); // get a status as string String getWLStatusString(uint8_t status); + bool setHostname(const char * hostname); private: std::unique_ptr dnsServer; @@ -211,6 +212,7 @@ class WiFiManager String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid uint8_t _lastconxresult = WL_IDLE_STATUS; + // option parameters int _minimumQuality = -1; // filter wifiscan ap by this rssi boolean _removeDuplicateAPs = true; // remove dup aps from wifiscan @@ -224,6 +226,7 @@ class WiFiManager boolean _cpClientCheck = false; // keep cp alive if cp have station boolean _webClientCheck = true; // keep cp alive if web have client boolean _scanDispOptions = false; // show percentage in scans not icons + const char * _hostname = ""; const char* _customHeadElement = ""; // store custom head element html from user @@ -252,6 +255,7 @@ class WiFiManager boolean configPortalHasTimeout(); boolean stopConfigPortal(); uint8_t handleConfigPortal(); + void stopCaptivePortal(); // wifi platform abstractions bool WiFi_Mode(WiFiMode_t m); From 9f4156437b26e4aa73220f486f376bd377e6b848 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sun, 18 Feb 2018 20:15:55 -0600 Subject: [PATCH 187/424] fixes #527 --- WiFiManager.cpp | 50 +++++++++++++++++++++++++++++++------------------ WiFiManager.h | 8 ++++---- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 994a761..14b44d9 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -158,7 +158,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { DEBUG_WM(F("AutoConnect")); // attempt to connect using saved settings, on fail fallback to AP config portal - WiFi_enableSTA(true); + WiFi.enableSTA(true); _usermode = WIFI_STA; // no getter for autoreconnectpolicy before this @@ -166,19 +166,36 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { // so we must force it on else, if not connectimeout then waitforconnectionresult gets stuck endless loop WiFi_autoReconnect(); + // set hostname before stating if(_hostname != ""){ #ifdef ESP8266 WiFi.hostname(_hostname); #elif defined(ESP32) WiFi.setHostname(_hostname); + if(WiFi.status() == WL_CONNECTED){ + DEBUG_WM("reconnecting to set new hostname"); + // WiFi.reconnect(); // does not reset dhcp + WiFi_Disconnect(); + delay(500); // need a delay for disconnect to change status() + } #endif } // if already connected, or try stored connect + // @note @todo ESP32 has no autoconnect, so connectwifi will always be called unless user called begin etc before if (WiFi.status() == WL_CONNECTED || connectWifi("", "") == WL_CONNECTED) { //connected DEBUG_WM(F("IP Address:"),WiFi.localIP()); _lastconxresult = WL_CONNECTED; + + if(_hostname != ""){ + #ifdef ESP8266 + DEBUG_WM("hostname: ",WiFi.hostname()); + #elif defined(ESP32) + DEBUG_WM("hostname: ",WiFi.getHostname()); + #endif + } + return true; } // not connected start configportal @@ -510,14 +527,6 @@ int WiFiManager::connectWifi(String ssid, String pass) { _lastconxresult = connRes; - if(connRes == WL_CONNECTED && _hostname != ""){ - #ifdef ESP8266 - WiFi.hostname(_hostname); - #elif defined(ESP32) - WiFi.setHostname(_hostname); - #endif - } - return connRes; } @@ -1628,6 +1637,10 @@ bool WiFiManager::WiFi_Mode(WiFiMode_t m) { * @return bool success */ bool WiFiManager::disconnect(){ + if(WiFi.status() != WL_CONNECTED){ + DEBUG_WM("Disconnect: Not connected"); + return false; + } return WiFi_Disconnect(); } @@ -1654,13 +1667,13 @@ bool WiFiManager::WiFi_Disconnect() { // toggle STA without persistent bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) { - WiFiMode_t newMode; - WiFiMode_t currentMode = WiFi.getMode(); - bool isEnabled = (currentMode & WIFI_STA) != 0; - if(enable) newMode = (WiFiMode_t)(currentMode | WIFI_STA); - else newMode = (WiFiMode_t)(currentMode & (~WIFI_STA)); - #ifdef ESP8266 + WiFiMode_t newMode; + WiFiMode_t currentMode = WiFi.getMode(); + bool isEnabled = (currentMode & WIFI_STA) != 0; + if(enable) newMode = (WiFiMode_t)(currentMode | WIFI_STA); + else newMode = (WiFiMode_t)(currentMode & (~WIFI_STA)); + if((isEnabled != enable) || persistent) { if(enable) { if(persistent) DEBUG_WM(F("enableSTA PERSISTENT ON")); @@ -1672,7 +1685,7 @@ bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) { return true; } #elif defined(ESP32) - return WiFi.mode(newMode); // @todo persistent not implemented? + return WiFi.enableSTA(enable); // @todo handle persistent when it is implemented in platform #endif } bool WiFiManager::WiFi_enableSTA(bool enable) { @@ -1730,10 +1743,11 @@ String WiFiManager::WiFi_SSID(){ void WiFiManager::WiFiEvent(WiFiEvent_t event){ #ifdef ESP32 - WiFiManager _WiFiManager; + // WiFiManager _WiFiManager; + // if(event == SYSTEM_EVENT_STA_START) WiFi.setHostname("wmtest"); if(event == SYSTEM_EVENT_STA_DISCONNECTED){ // Serial.println("Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); - _WiFiManager.DEBUG_WM("ESP32 Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); // @todo remove debugging from prod, or change static method + // _WiFiManager.DEBUG_WM("ESP32 Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); // @todo remove debugging from prod, or change static method WiFi.reconnect(); } #endif diff --git a/WiFiManager.h b/WiFiManager.h index 51e40c8..3bdec84 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -204,10 +204,10 @@ class WiFiManager String _pass = ""; // options flags - unsigned long _configPortalTimeout = 0; // close config portal loop if set (depending on _cp/webClientCheck options) - unsigned long _connectTimeout = 0; // stop trying to connect to ap if set - unsigned long _configPortalStart = 0; // config portal start time (updated for timeouts) - unsigned long _webPortalAccessed = 0; // last web access time + unsigned long _configPortalTimeout = 0; // ms close config portal loop if set (depending on _cp/webClientCheck options) + unsigned long _connectTimeout = 0; // ms stop trying to connect to ap if set + unsigned long _configPortalStart = 0; // ms config portal start time (updated for timeouts) + unsigned long _webPortalAccessed = 0; // ms last web access time WiFiMode_t _usermode = WIFI_OFF; String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid uint8_t _lastconxresult = WL_IDLE_STATUS; From 97398d7ce2bd50f35431a04b32ae67f653487aa6 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Sun, 18 Feb 2018 20:23:04 -0600 Subject: [PATCH 188/424] fix #527 for esp8266 --- WiFiManager.cpp | 13 +++++++------ WiFiManager.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 14b44d9..dd91b49 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -172,13 +172,14 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { WiFi.hostname(_hostname); #elif defined(ESP32) WiFi.setHostname(_hostname); - if(WiFi.status() == WL_CONNECTED){ - DEBUG_WM("reconnecting to set new hostname"); - // WiFi.reconnect(); // does not reset dhcp - WiFi_Disconnect(); - delay(500); // need a delay for disconnect to change status() - } #endif + + if(WiFi.status() == WL_CONNECTED){ + DEBUG_WM("reconnecting to set new hostname"); + // WiFi.reconnect(); // does not reset dhcp + WiFi_Disconnect(); + delay(500); // need a delay for disconnect to change status() + } } // if already connected, or try stored connect diff --git a/WiFiManager.h b/WiFiManager.h index 3bdec84..5cb7de3 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -226,7 +226,7 @@ class WiFiManager boolean _cpClientCheck = false; // keep cp alive if cp have station boolean _webClientCheck = true; // keep cp alive if web have client boolean _scanDispOptions = false; // show percentage in scans not icons - const char * _hostname = ""; + const char * _hostname = "wmtest"; const char* _customHeadElement = ""; // store custom head element html from user From ea994d5ccd6e3b09874071c6b74481aa9b5bcb21 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 19 Feb 2018 08:21:22 -0600 Subject: [PATCH 189/424] adds getWiFiIsSaved() --- WiFiManager.cpp | 23 +++++++++++++++++++++++ WiFiManager.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index dd91b49..d49bdf1 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1476,13 +1476,36 @@ void WiFiManager::setScanDispPerc(boolean enabled){ _scanDispOptions = true; } +/** + * return the last known connection result + * logged on autoconnect and wifisave, can be used to check why failed + * get as readable string with getWLStatusString(getLastConxResult); + * @since $dev + * @return bool return wl_status codes + */ uint8_t WiFiManager::getLastConxResult(){ return _lastconxresult; } +/** + * set the hostname (dhcp client id) + * @since $dev + * @param char* hostname 32 character hostname to use for sta+ap in esp32, sta in esp8266 + * @return bool false if hostname is not valid + */ bool WiFiManager::setHostname(const char * hostname){ //@todo max length 32 _hostname = hostname; + return true; +} + +/** + * check if wifi has a saved ap or not + * @since $dev + * @return bool true if a saved ap config exists + */ +bool WiFiManager::getWiFiIsSaved(){ + return WiFi_hasAutoConnect(); } // HELPERS diff --git a/WiFiManager.h b/WiFiManager.h index 5cb7de3..6cc27e6 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -177,7 +177,10 @@ class WiFiManager uint8_t getLastConxResult(); // get a status as string String getWLStatusString(uint8_t status); + // set a custom hostname, sets sta and ap dhcp client id for esp32, and sta for esp8266 bool setHostname(const char * hostname); + // check if the module has a saved ap to connect to + bool getWiFiIsSaved(); private: std::unique_ptr dnsServer; From 9d16a6866550cdf1055f0dcf2ffface5cafe700a Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 19 Feb 2018 08:37:12 -0600 Subject: [PATCH 190/424] doc blocks, reformatting code --- WiFiManager.cpp | 294 +++++++++++++++++++++++++++++++++++------------- WiFiManager.h | 13 ++- 2 files changed, 225 insertions(+), 82 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index d49bdf1..38db1c6 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -80,6 +80,11 @@ const char* WiFiManagerParameter::getCustomHTML() { return _customHTML; } +/** + * [addParameter description] + * @access public + * @param {[type]} WiFiManagerParameter *p [description] + */ bool WiFiManager::addParameter(WiFiManagerParameter *p) { // check param id is valid @@ -149,11 +154,19 @@ WiFiManager::~WiFiManager() { } // AUTOCONNECT + boolean WiFiManager::autoConnect() { String ssid = _wifissidprefix + "_" + String(WIFI_getChipId()); return autoConnect(ssid.c_str(), NULL); } +/** + * [autoConnect description] + * @access public + * @param {[type]} char const *apName [description] + * @param {[type]} char const *apPassword [description] + * @return {[type]} [description] + */ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { DEBUG_WM(F("AutoConnect")); @@ -244,12 +257,22 @@ bool WiFiManager::startAP(){ return ret; } +/** + * [startWebPortal description] + * @access public + * @return {[type]} [description] + */ void WiFiManager::startWebPortal() { if(configPortalActive || webPortalActive) return; setupConfigPortal(); webPortalActive = true; } +/** + * [stopWebPortal description] + * @access public + * @return {[type]} [description] + */ void WiFiManager::stopWebPortal() { if(!configPortalActive && !webPortalActive) return; DEBUG_WM(F("Stopping Web Portal")); @@ -326,6 +349,13 @@ boolean WiFiManager::startConfigPortal() { return startConfigPortal(ssid.c_str(), NULL); } +/** + * [startConfigPortal description] + * @access public + * @param {[type]} char const *apName [description] + * @param {[type]} char const *apPassword [description] + * @return {[type]} [description] + */ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) { //setup AP @@ -396,6 +426,11 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo return result; } +/** + * [process description] + * @access public + * @return {[type]} [description] + */ boolean WiFiManager::process(){ if(webPortalActive || (configPortalActive && !_configPortalIsBlocking)){ uint8_t state = handleConfigPortal(); @@ -449,6 +484,11 @@ uint8_t WiFiManager::handleConfigPortal(){ return WL_IDLE_STATUS; } +/** + * [stopConfigPortal description] + * @access public + * @return {[type]} [description] + */ boolean WiFiManager::stopConfigPortal(){ if(webPortalActive) return false; @@ -569,53 +609,6 @@ void WiFiManager::startWPS() { DEBUG_WM(F("END WPS")); } -// GETTERS -String WiFiManager::getConfigPortalSSID() { - return _apName; -} - -// SETTERS -void WiFiManager::resetSettings() { - DEBUG_WM(F("SETTINGS ERASED")); - WiFi_enableSTA(true,true); - WiFi.disconnect(true); -} - -void WiFiManager::setTimeout(unsigned long seconds) { - setConfigPortalTimeout(seconds); -} - -void WiFiManager::setConfigPortalTimeout(unsigned long seconds) { - _configPortalTimeout = seconds * 1000; -} - -void WiFiManager::setConnectTimeout(unsigned long seconds) { - _connectTimeout = seconds * 1000; -} - -void WiFiManager::setDebugOutput(boolean debug) { - _debug = debug; -} - -void WiFiManager::setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) { - _ap_static_ip = ip; - _ap_static_gw = gw; - _ap_static_sn = sn; -} - -void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) { - _sta_static_ip = ip; - _sta_static_gw = gw; - _sta_static_sn = sn; -} - -void WiFiManager::setMinimumSignalQuality(int quality) { - _minimumQuality = quality; -} - -void WiFiManager::setBreakAfterConfig(boolean shouldBreak) { - _shouldBreakAfterConfig = shouldBreak; -} String WiFiManager::getHTTPHead(String title){ String page; @@ -1352,10 +1345,132 @@ void WiFiManager::reportStatus(String &page){ page += str; } -// MORE SETTERS +// PUBLIC + +// METHODS + +/** + * reset wifi settings, clean stored ap password + */ + +/** + * disconnect + * @access public + * @since $dev + * @return bool success + */ +bool WiFiManager::disconnect(){ + if(WiFi.status() != WL_CONNECTED){ + DEBUG_WM("Disconnect: Not connected"); + return false; + } + return WiFi_Disconnect(); +} + +/** + * reboot the device + * @access public + */ +void WiFiManager::reboot(){ + ESP.restart(); +} + + +/** + * [resetSettings description] + * @access public + */ +void WiFiManager::resetSettings() { + DEBUG_WM(F("SETTINGS ERASED")); + WiFi_enableSTA(true,true); + WiFi.disconnect(true); +} + +// SETTERS + +/** + * [setTimeout description] + * @access public + * @param {[type]} unsigned long seconds [description] + */ +void WiFiManager::setTimeout(unsigned long seconds) { + setConfigPortalTimeout(seconds); +} + +/** + * [setConfigPortalTimeout description] + * @access public + * @param {[type]} unsigned long seconds [description] + */ +void WiFiManager::setConfigPortalTimeout(unsigned long seconds) { + _configPortalTimeout = seconds * 1000; +} + +/** + * [setConnectTimeout description] + * @access public + * @param {[type]} unsigned long seconds [description] + */ +void WiFiManager::setConnectTimeout(unsigned long seconds) { + _connectTimeout = seconds * 1000; +} + +/** + * [setDebugOutput description] + * @access public + * @param {[type]} boolean debug [description] + */ +void WiFiManager::setDebugOutput(boolean debug) { + _debug = debug; +} + +/** + * [setAPStaticIPConfig description] + * @access public + * @param {[type]} IPAddress ip [description] + * @param {[type]} IPAddress gw [description] + * @param {[type]} IPAddress sn [description] + */ +void WiFiManager::setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) { + _ap_static_ip = ip; + _ap_static_gw = gw; + _ap_static_sn = sn; +} + +/** + * [setSTAStaticIPConfig description] + * @access public + * @param {[type]} IPAddress ip [description] + * @param {[type]} IPAddress gw [description] + * @param {[type]} IPAddress sn [description] + */ +void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) { + _sta_static_ip = ip; + _sta_static_gw = gw; + _sta_static_sn = sn; +} + +/** + * [setMinimumSignalQuality description] + * @access public + * @param {[type]} int quality [description] + */ +void WiFiManager::setMinimumSignalQuality(int quality) { + _minimumQuality = quality; +} + +/** + * [setBreakAfterConfig description] + * @access public + * @param {[type]} boolean shouldBreak [description] + */ +void WiFiManager::setBreakAfterConfig(boolean shouldBreak) { + _shouldBreakAfterConfig = shouldBreak; +} /** * setAPCallback, set a callback when softap is started + * @access public * @param {[type]} void (*func)(WiFiManager* myWiFiManager) [description] */ void WiFiManager::setAPCallback( void (*func)(WiFiManager* myWiFiManager) ) { @@ -1365,6 +1480,7 @@ void WiFiManager::setAPCallback( void (*func)(WiFiManager* myWiFiManager) ) { /** * setSaveConfigCallback, set a save config callback after closing configportal * @todo only calls if configportal stopped + * @access public * @param {[type]} void (*func)(void) [description] */ void WiFiManager::setSaveConfigCallback( void (*func)(void) ) { @@ -1374,6 +1490,7 @@ void WiFiManager::setSaveConfigCallback( void (*func)(void) ) { /** * set custom head html * custom element will be added to head, eg. new style tag etc. + * @access public * @param char element */ void WiFiManager::setCustomHeadElement(const char* element) { @@ -1384,6 +1501,7 @@ void WiFiManager::setCustomHeadElement(const char* element) { /** * toggle wifiscan hiding of duplicate ssid names * if enabled, then the webportal wifiscan page will show all aps + * @access public * @param boolean removeDuplicates [true] */ void WiFiManager::setRemoveDuplicateAPs(boolean removeDuplicates) { @@ -1395,6 +1513,7 @@ void WiFiManager::setRemoveDuplicateAPs(boolean removeDuplicates) { * if enabled, then the configportal will enter a blocking loop and wait for configuration * if disabled use with process() to manually process webserver * @since $dev + * @access public * @param boolean shoudlBlock [false] */ void WiFiManager::setConfigPortalBlocking(boolean shoudlBlock) { @@ -1406,6 +1525,7 @@ void WiFiManager::setConfigPortalBlocking(boolean shoudlBlock) { * sets ESP wifi.persistent so we can remember it and restore user preference on destruct * there is no getter in esp8266 platform prior to https://github.com/esp8266/Arduino/pull/3857 * @since $dev + * @access public * @param boolean persistent [true] */ void WiFiManager::setRestorePersistent(boolean persistent) { @@ -1417,6 +1537,7 @@ void WiFiManager::setRestorePersistent(boolean persistent) { * toggle showing static ip form fields * if enabled, then the static ip, gateway, subnet fields will be visible, even if not set in code * @since $dev + * @access public * @param boolean alwaysShow [false] */ void WiFiManager::setShowStaticFields(boolean alwaysShow){ @@ -1428,6 +1549,7 @@ void WiFiManager::setShowStaticFields(boolean alwaysShow){ * if enabled, then devices that use captive portal checks will be redirected to root * if not you will automatically have to navigate to ip [192.168.4.1] * @since $dev + * @access public * @param boolean enabled [true] */ void WiFiManager::setCaptivePortalEnable(boolean enabled){ @@ -1440,6 +1562,7 @@ void WiFiManager::setCaptivePortalEnable(boolean enabled){ * On esp8266 we force this on when autoconnect is called, see notes * On esp32 this is handled on SYSTEM_EVENT_STA_DISCONNECTED since it does not exist in core yet * @since $dev + * @access public * @param boolean enabled [true] */ void WiFiManager::setWiFiAutoReconnect(boolean enabled){ @@ -1451,6 +1574,7 @@ void WiFiManager::setWiFiAutoReconnect(boolean enabled){ * if enabled, then the configportal will start timeout when no stations are connected to softAP * disabled by default as rogue stations can keep it open if there is no auth * @since $dev + * @access public * @param boolean enabled [false] */ void WiFiManager::setCaptivePortalClientCheck(boolean enabled){ @@ -1461,6 +1585,7 @@ void WiFiManager::setCaptivePortalClientCheck(boolean enabled){ * toggle configportal timeout wait for web client * if enabled, then the configportal will restart timeout when client requests come in * @since $dev + * @access public * @param boolean enabled [true] */ void WiFiManager::setWebPortalClientCheck(boolean enabled){ @@ -1470,26 +1595,17 @@ void WiFiManager::setWebPortalClientCheck(boolean enabled){ /** * toggle wifiscan percentages or quality icons * @since $dev + * @access public * @param boolean enabled [false] */ void WiFiManager::setScanDispPerc(boolean enabled){ _scanDispOptions = true; } -/** - * return the last known connection result - * logged on autoconnect and wifisave, can be used to check why failed - * get as readable string with getWLStatusString(getLastConxResult); - * @since $dev - * @return bool return wl_status codes - */ -uint8_t WiFiManager::getLastConxResult(){ - return _lastconxresult; -} - /** * set the hostname (dhcp client id) * @since $dev + * @access public * @param char* hostname 32 character hostname to use for sta+ap in esp32, sta in esp8266 * @return bool false if hostname is not valid */ @@ -1499,15 +1615,42 @@ bool WiFiManager::setHostname(const char * hostname){ return true; } + +// GETTERS + +/** + * get config portal AP SSID + * @since 0.0.1 + * @access public + * @return String the configportal ap name + */ +String WiFiManager::getConfigPortalSSID() { + return _apName; +} + +/** + * return the last known connection result + * logged on autoconnect and wifisave, can be used to check why failed + * get as readable string with getWLStatusString(getLastConxResult); + * @since $dev + * @access public + * @return bool return wl_status codes + */ +uint8_t WiFiManager::getLastConxResult(){ + return _lastconxresult; +} + /** * check if wifi has a saved ap or not * @since $dev + * @access public * @return bool true if a saved ap config exists */ bool WiFiManager::getWiFiIsSaved(){ return WiFi_hasAutoConnect(); } + // HELPERS template @@ -1538,6 +1681,11 @@ void WiFiManager::DEBUG_WM(Generic text,Genericb textb) { } } +/** + * [debugSoftAPConfig description] + * @access public + * @return {[type]} [description] + */ void WiFiManager::debugSoftAPConfig(){ #ifdef ESP8266 softap_config config; @@ -1561,6 +1709,11 @@ void WiFiManager::debugSoftAPConfig(){ DEBUG_WM(FPSTR(D_HR)); } +/** + * [debugPlatformInfo description] + * @access public + * @return {[type]} [description] + */ void WiFiManager::debugPlatformInfo(){ #ifdef ESP8266 system_print_meminfo(); @@ -1624,6 +1777,12 @@ boolean WiFiManager::validApPassword(){ return true; } +/** + * [getWLStatusString description] + * @access public + * @param {[type]} uint8_t status [description] + * @return {[type]} [description] + */ String WiFiManager::getWLStatusString(uint8_t status){ if(status >=0 && status <=6) return WIFI_STA_STATUS[status]; return FPSTR(S_NA); @@ -1655,19 +1814,6 @@ bool WiFiManager::WiFi_Mode(WiFiMode_t m) { return WiFi_Mode(m,false); } -/** - * disconnect - * @since $dev - * @return bool success - */ -bool WiFiManager::disconnect(){ - if(WiFi.status() != WL_CONNECTED){ - DEBUG_WM("Disconnect: Not connected"); - return false; - } - return WiFi_Disconnect(); -} - // sta disconnect without persistent bool WiFiManager::WiFi_Disconnect() { #ifdef ESP8266 @@ -1739,10 +1885,6 @@ bool WiFiManager::WiFi_eraseConfig(void) { #endif } -void WiFiManager::reboot(){ - ESP.restart(); -} - uint8_t WiFiManager::WiFi_softap_num_stations(){ #ifdef ESP8266 return wifi_softap_get_station_num(); diff --git a/WiFiManager.h b/WiFiManager.h index 6cc27e6..73bc94f 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -169,19 +169,20 @@ class WiFiManager void setWiFiAutoReconnect(boolean enabled); // if true, wifiscan will show percentage instead of quality icons, until we have better templating void setScanDispPerc(boolean enabled); - // debug output the softap config - void debugSoftAPConfig(); - // debug output platform info and versioning - void debugPlatformInfo(); + // set a custom hostname, sets sta and ap dhcp client id for esp32, and sta for esp8266 + bool setHostname(const char * hostname); + // get last connection result, includes autoconnect and wifisave uint8_t getLastConxResult(); // get a status as string String getWLStatusString(uint8_t status); - // set a custom hostname, sets sta and ap dhcp client id for esp32, and sta for esp8266 - bool setHostname(const char * hostname); // check if the module has a saved ap to connect to bool getWiFiIsSaved(); + // debug output the softap config + void debugSoftAPConfig(); + // debug output platform info and versioning + void debugPlatformInfo(); private: std::unique_ptr dnsServer; From 374e9f515f5cbbbc6cfecde8ac203b4f997fdb6c Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 19 Feb 2018 09:52:52 -0600 Subject: [PATCH 191/424] stability #527 --- WiFiManager.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 38db1c6..74aabd8 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -184,14 +184,16 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { #ifdef ESP8266 WiFi.hostname(_hostname); #elif defined(ESP32) + // @note hostname must be set after STA_START + delay(200); // do not remove, give time for STA_START WiFi.setHostname(_hostname); #endif if(WiFi.status() == WL_CONNECTED){ DEBUG_WM("reconnecting to set new hostname"); - // WiFi.reconnect(); // does not reset dhcp + // WiFi.reconnect(); // This does not reset dhcp WiFi_Disconnect(); - delay(500); // need a delay for disconnect to change status() + delay(200); // do not remove, need a delay for disconnect to change status() } } @@ -238,7 +240,7 @@ bool WiFiManager::startAP(){ if(_debugLevel > 1) debugSoftAPConfig(); - if(!ret) DEBUG_WM("[ERROR] There was a problem starting the AP"); // @bug startAP returns unreliable success status + if(!ret) DEBUG_WM("[ERROR] There was a problem starting the AP"); delay(500); // slight delay to make sure we get an AP IP DEBUG_WM(F("AP IP address:"),WiFi.softAPIP()); @@ -250,7 +252,7 @@ bool WiFiManager::startAP(){ #ifdef ESP32 if(ret && _hostname != ""){ - WiFi.softAPsetHostname(_hostname); + WiFi.softAPsetHostname(_hostname); } #endif @@ -554,7 +556,7 @@ int WiFiManager::connectWifi(String ssid, String pass) { waitforconx = false; } } - + uint8_t connRes = waitforconx ? waitForConnectResult() : WL_NO_SSID_AVAIL; DEBUG_WM (F("Connection result:"),getWLStatusString(connRes)); @@ -1911,6 +1913,7 @@ void WiFiManager::WiFiEvent(WiFiEvent_t event){ #ifdef ESP32 // WiFiManager _WiFiManager; // if(event == SYSTEM_EVENT_STA_START) WiFi.setHostname("wmtest"); + // if(event == SYSTEM_EVENT_AP_START) WiFi.softAPsetHostname("wmtest"); if(event == SYSTEM_EVENT_STA_DISCONNECTED){ // Serial.println("Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); // _WiFiManager.DEBUG_WM("ESP32 Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); // @todo remove debugging from prod, or change static method From 89cfdfc67f3dcb3fa9d997bd4cb1016fb499e0d1 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 19 Feb 2018 10:04:40 -0600 Subject: [PATCH 192/424] clean up --- WiFiManager.cpp | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 74aabd8..79fdf6b 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -190,7 +190,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { #endif if(WiFi.status() == WL_CONNECTED){ - DEBUG_WM("reconnecting to set new hostname"); + DEBUG_WM(F("reconnecting to set new hostname")); // WiFi.reconnect(); // This does not reset dhcp WiFi_Disconnect(); delay(200); // do not remove, need a delay for disconnect to change status() @@ -203,15 +203,6 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { //connected DEBUG_WM(F("IP Address:"),WiFi.localIP()); _lastconxresult = WL_CONNECTED; - - if(_hostname != ""){ - #ifdef ESP8266 - DEBUG_WM("hostname: ",WiFi.hostname()); - #elif defined(ESP32) - DEBUG_WM("hostname: ",WiFi.getHostname()); - #endif - } - return true; } // not connected start configportal @@ -220,6 +211,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { // CONFIG PORTAL bool WiFiManager::startAP(){ + bool ret = true; DEBUG_WM(F("StartAP with SSID: "),_apName); // setup optional soft AP static ip config @@ -228,8 +220,6 @@ bool WiFiManager::startAP(){ WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn); } - bool ret = true; - // start soft AP with password or anonymous if (_apPassword != "") { ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str());//password option @@ -245,17 +235,19 @@ bool WiFiManager::startAP(){ delay(500); // slight delay to make sure we get an AP IP DEBUG_WM(F("AP IP address:"),WiFi.softAPIP()); + // set ap hostname + #ifdef ESP32 + if(ret && _hostname != ""){ + WiFi.softAPsetHostname(_hostname); + DEBUG_WM(F("aphostname: "),WiFi.softAPgetHostname()); + } + #endif + // do AP callback if set if ( _apcallback != NULL) { _apcallback(this); } - - #ifdef ESP32 - if(ret && _hostname != ""){ - WiFi.softAPsetHostname(_hostname); - } - #endif - + return ret; } From 7a5a72eed4a999b01fe3cc7f83efd62ff681dc5f Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 19 Feb 2018 10:12:25 -0600 Subject: [PATCH 193/424] remove debugging --- WiFiManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.h b/WiFiManager.h index 73bc94f..d6811a8 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -230,7 +230,7 @@ class WiFiManager boolean _cpClientCheck = false; // keep cp alive if cp have station boolean _webClientCheck = true; // keep cp alive if web have client boolean _scanDispOptions = false; // show percentage in scans not icons - const char * _hostname = "wmtest"; + const char * _hostname = ""; const char* _customHeadElement = ""; // store custom head element html from user From aaad9ca4c37f3dbeed736d104e23eace2c35be62 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 19 Feb 2018 10:32:34 -0600 Subject: [PATCH 194/424] add result checking #527 --- WiFiManager.cpp | 23 ++++++++++++++++++----- WiFiManager.h | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 79fdf6b..5c14823 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -181,14 +181,17 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { // set hostname before stating if(_hostname != ""){ + bool res = true; #ifdef ESP8266 - WiFi.hostname(_hostname); + res = WiFi.hostname(_hostname); #elif defined(ESP32) // @note hostname must be set after STA_START delay(200); // do not remove, give time for STA_START - WiFi.setHostname(_hostname); + res = WiFi.setHostname(_hostname); #endif + if(!res)DEBUG_WM(F("hostname: set failed!")); + if(WiFi.status() == WL_CONNECTED){ DEBUG_WM(F("reconnecting to set new hostname")); // WiFi.reconnect(); // This does not reset dhcp @@ -203,8 +206,17 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { //connected DEBUG_WM(F("IP Address:"),WiFi.localIP()); _lastconxresult = WL_CONNECTED; + + if(_hostname != ""){ + #ifdef ESP8266 + DEBUG_WM("hostname: STA",WiFi.hostname()); + #elif defined(ESP32) + DEBUG_WM("hostname: STA",WiFi.getHostname()); + #endif + } return true; } + // not connected start configportal return startConfigPortal(apName, apPassword); } @@ -238,8 +250,9 @@ bool WiFiManager::startAP(){ // set ap hostname #ifdef ESP32 if(ret && _hostname != ""){ - WiFi.softAPsetHostname(_hostname); - DEBUG_WM(F("aphostname: "),WiFi.softAPgetHostname()); + bool res = WiFi.softAPsetHostname(_hostname); + if(!res)DEBUG_WM(F("hostname: AP set failed!")); + DEBUG_WM(F("hostname: AP"),WiFi.softAPgetHostname()); } #endif @@ -247,7 +260,7 @@ bool WiFiManager::startAP(){ if ( _apcallback != NULL) { _apcallback(this); } - + return ret; } diff --git a/WiFiManager.h b/WiFiManager.h index d6811a8..73bc94f 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -230,7 +230,7 @@ class WiFiManager boolean _cpClientCheck = false; // keep cp alive if cp have station boolean _webClientCheck = true; // keep cp alive if web have client boolean _scanDispOptions = false; // show percentage in scans not icons - const char * _hostname = ""; + const char * _hostname = "wmtest"; const char* _customHeadElement = ""; // store custom head element html from user From 0c6d4df7a721a7da707dc6dc8d74475e88e6eca1 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 19 Feb 2018 10:33:19 -0600 Subject: [PATCH 195/424] remove debugging --- WiFiManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.h b/WiFiManager.h index 73bc94f..d6811a8 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -230,7 +230,7 @@ class WiFiManager boolean _cpClientCheck = false; // keep cp alive if cp have station boolean _webClientCheck = true; // keep cp alive if web have client boolean _scanDispOptions = false; // show percentage in scans not icons - const char * _hostname = "wmtest"; + const char * _hostname = ""; const char* _customHeadElement = ""; // store custom head element html from user From 9eec7f97ddfb99b46827210f4662261a2c938c85 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 19 Feb 2018 10:46:55 -0600 Subject: [PATCH 196/424] change some uneeded ints --- WiFiManager.cpp | 6 +++--- WiFiManager.h | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 5c14823..eec8f8f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -528,7 +528,7 @@ boolean WiFiManager::stopConfigPortal(){ // @todo refactor this up into seperate functions // one for connecting to flash , one for new client // clean up, flow is convoluted, and causes bugs -int WiFiManager::connectWifi(String ssid, String pass) { +uint8_t WiFiManager::connectWifi(String ssid, String pass) { DEBUG_WM(F("Connecting as wifi client...")); bool waitforconx = true; @@ -1735,8 +1735,8 @@ void WiFiManager::debugPlatformInfo(){ #endif } -int WiFiManager::getRSSIasQuality(int RSSI) { - int quality = 0; +uint8_t WiFiManager::getRSSIasQuality(uint8_t RSSI) { + uint8_t quality = 0; if (RSSI <= -100) { quality = 0; diff --git a/WiFiManager.h b/WiFiManager.h index d6811a8..1b26f96 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -238,8 +238,7 @@ class WiFiManager void startWPS(); bool startAP(); - int status = WL_IDLE_STATUS; - int connectWifi(String ssid, String pass); + uint8_t connectWifi(String ssid, String pass); uint8_t waitForConnectResult(); uint8_t waitForConnectResult(uint16_t timeout); @@ -284,7 +283,7 @@ class WiFiManager String getHTTPHead(String title); //helpers - int getRSSIasQuality(int RSSI); + uint8_t getRSSIasQuality(uint8_t RSSI); boolean isIp(String str); String toStringIp(IPAddress ip); boolean validApPassword(); From 64075bc7f98ec9fc63fed0e64f010347df5c9805 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 19 Feb 2018 13:31:43 -0600 Subject: [PATCH 197/424] feature #533 failure details --- WiFiManager.cpp | 34 +++++++++++++++++++++++++++++++--- WiFiManager.h | 5 ++++- strings_en.h | 20 ++++++++++++-------- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index eec8f8f..1a4048e 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -573,7 +573,17 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) { connRes = waitForConnectResult(); } - _lastconxresult = connRes; + if(connRes != WL_SCAN_COMPLETED){ + _lastconxresult = connRes; + #ifdef ESP8266 + // hack in wrong password detection + if(_lastconxresult == WL_CONNECT_FAILED){ + if(wifi_station_get_connect_status() == STATION_WRONG_PASSWORD){ + _lastconxresult = WL_STATION_WRONG_PASSWORD; + } + } + #endif + } return connRes; } @@ -736,7 +746,6 @@ String WiFiManager::getScanItemOut(){ // token precheck, to speed up replacements on large ap lists String HTTP_ITEM_STR = FPSTR(HTTP_ITEM); - // toggle icons with percentage HTTP_ITEM_STR.replace("{qp}", FPSTR(HTTP_ITEM_QP)); HTTP_ITEM_STR.replace("{h}",_scanDispOptions ? "" : "h"); @@ -1344,6 +1353,25 @@ void WiFiManager::reportStatus(String &page){ else { str = FPSTR(HTTP_STATUS_OFF); str.replace(FPSTR(T_v),WiFi_SSID()); + if(_lastconxresult == WL_STATION_WRONG_PASSWORD){ + // wrong password + str.replace(FPSTR(T_c),"D"); // class + str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_OFFPW)); + } + else if(_lastconxresult == WL_NO_SSID_AVAIL){ + // connect failed, or ap not found + str.replace(FPSTR(T_c),"D"); + str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_OFFNOAP)); + } + else if(_lastconxresult == WL_CONNECT_FAILED){ + // connect failed + str.replace(FPSTR(T_c),"D"); + str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_OFFFAIL)); + } + else{ + str.replace(FPSTR(T_c),""); + str.replace(FPSTR(T_r),""); + } } } else { @@ -1791,7 +1819,7 @@ boolean WiFiManager::validApPassword(){ * @return {[type]} [description] */ String WiFiManager::getWLStatusString(uint8_t status){ - if(status >=0 && status <=6) return WIFI_STA_STATUS[status]; + if(status >=0 && status <=7) return WIFI_STA_STATUS[status]; return FPSTR(S_NA); } diff --git a/WiFiManager.h b/WiFiManager.h index 1b26f96..02c85d3 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -215,7 +215,10 @@ class WiFiManager WiFiMode_t _usermode = WIFI_OFF; String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid uint8_t _lastconxresult = WL_IDLE_STATUS; - + + #ifndef WL_STATION_WRONG_PASSWORD + uint8_t WL_STATION_WRONG_PASSWORD = 7; + #endif // option parameters int _minimumQuality = -1; // filter wifiscan ap by this rssi diff --git a/strings_en.h b/strings_en.h index b198ecb..0212a2c 100644 --- a/strings_en.h +++ b/strings_en.h @@ -43,7 +43,10 @@ const char HTTP_END[] PROGMEM = "
"; const char HTTP_ERASEBTN[] PROGMEM = "
"; const char HTTP_STATUS_ON[] PROGMEM = "
Connected to {v}
with IP {i}
"; -const char HTTP_STATUS_OFF[] PROGMEM = "
Not Connected to {v}
"; +const char HTTP_STATUS_OFF[] PROGMEM = "
Not Connected to {v}{r}
"; +const char HTTP_STATUS_OFFPW[] PROGMEM = "
Wrong Password"; +const char HTTP_STATUS_OFFNOAP[] PROGMEM = "
AP not found"; +const char HTTP_STATUS_OFFFAIL[] PROGMEM = "
Could not Connect"; const char HTTP_STATUS_NONE[] PROGMEM = "
No AP set
"; const char HTTP_BR[] PROGMEM = "
"; @@ -226,13 +229,14 @@ const char HTTP_HEAD_CT2[] PROGMEM = "text/plain"; const char * const WIFI_STA_STATUS[] PROGMEM { - "WL_IDLE_STATUS", // STATION_IDLE - "WL_NO_SSID_AVAIL", // STATION_NO_AP_FOUND - "WL_SCAN_COMPLETED", - "WL_CONNECTED", // STATION_GOT_IP - "WL_CONNECT_FAILED",// STATION_CONNECT_FAIL, STATION_WRONG_PASSWORD(NI) - "WL_CONNECTION_LOST", - "WL_DISCONNECTED" + "WL_IDLE_STATUS", // 0 STATION_IDLE + "WL_NO_SSID_AVAIL", // 1 STATION_NO_AP_FOUND + "WL_SCAN_COMPLETED", // 2 + "WL_CONNECTED", // 3 STATION_GOT_IP + "WL_CONNECT_FAILED", // 4 STATION_CONNECT_FAIL, STATION_WRONG_PASSWORD(NI) + "WL_CONNECTION_LOST", // 5 + "WL_DISCONNECTED", // 6 + "WL_STATION_WRONG_PASSWORD" // 7 KLUDGE }; #ifdef ESP32 From f9a8f5bdab9a93d197cc573a9bcc687825b4f4c6 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 19 Feb 2018 13:32:12 -0600 Subject: [PATCH 198/424] allow empty ssids, bail earlier --- WiFiManager.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 1a4048e..c233aa2 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -365,6 +365,11 @@ boolean WiFiManager::startConfigPortal() { */ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) { //setup AP + _apName = apName; // @todo check valid apname ? + _apPassword = apPassword; + + if(_apName == "") _apName = _wifissidprefix + "_" + String(WIFI_getChipId()); + if(!validApPassword()) return false; bool disableSTA = false; // debug, always disable sta @@ -381,24 +386,19 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo WiFi_enableSTA(true); } - DEBUG_WM(F("Enabling AP")); - - _apName = apName; // @todo check valid apname ? - _apPassword = apPassword; - if(!validApPassword()) return false; - // init configportal globals to known states configPortalActive = true; bool result = connect = abort = false; // loop flags, connect true success, abort true break uint8_t state; - DEBUG_WM(F("setupConfigPortal")); _configPortalStart = millis(); // start access point + DEBUG_WM(F("Enabling AP")); startAP(); // init configportal + DEBUG_WM(F("setupConfigPortal")); setupConfigPortal(); if(!_configPortalIsBlocking){ From e5edf536a5262868a0942fa500c97c57d4db3eaf Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 19 Feb 2018 14:03:52 -0600 Subject: [PATCH 199/424] template update --- extras/WiFiManager.template.html | 30 ++++++++++++++++++++++++++---- strings_en.h | 6 +++--- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/extras/WiFiManager.template.html b/extras/WiFiManager.template.html index aa83cc2..52f9660 100644 --- a/extras/WiFiManager.template.html +++ b/extras/WiFiManager.template.html @@ -178,7 +178,7 @@ td { -


+


custom parameter


@@ -198,10 +198,32 @@ td {
-

Saving Credentials

Trying to connect ESP to network.
If it fails reconnect to AP to try again
+

Saving Credentials

Trying to connect ESP to network.
If it fails reconnect to AP to try again
+ +
Connected to {v}
with IP {i}
+ + +
Not Connected to {v}{r}
+ + +
Not Connected to apname + + +
Wrong Password + + +
AP not found + + +
Could not Connect + +
-

Information

Connected to AP: homeAP
+ +
No AP set
+ +

Information

Connected to AP: homeAP

Connect Failed

An error occured
@@ -238,7 +260,7 @@ td { /erase Erase WiFi configuration and reboot Device. Device will not reconnect to a network until new WiFi configuration data is entered. -

More information about WiFiManager at https://github.com/tzapu/WiFiManager.; +

More information about WiFiManager at https://github.com/tzapu/WiFiManager

diff --git a/strings_en.h b/strings_en.h index 0212a2c..2d3ea9d 100644 --- a/strings_en.h +++ b/strings_en.h @@ -44,9 +44,9 @@ const char HTTP_ERASEBTN[] PROGMEM = "
Date: Mon, 19 Feb 2018 21:32:17 -0600 Subject: [PATCH 200/424] debuggin esp32 auth fail events --- WiFiManager.cpp | 10 +++++++--- WiFiManager.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index c233aa2..e3f3624 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -128,7 +128,7 @@ WiFiManager::WiFiManager(Stream& consolePort):_debugPort(consolePort) { } WiFiManager::WiFiManager():_debugPort(Serial) { - if(_debug && _debugLevel > 0) debugPlatformInfo(); + if(_debug && _debugLevel > 2) debugPlatformInfo(); _usermode = WiFi.getMode(); WiFi.persistent(false); // disable persistent so scannetworks and mode switching do not cause overwrites @@ -1942,12 +1942,16 @@ String WiFiManager::WiFi_SSID(){ #endif } -void WiFiManager::WiFiEvent(WiFiEvent_t event){ +void WiFiManager::WiFiEvent(WiFiEvent_t event,system_event_info_t info){ #ifdef ESP32 // WiFiManager _WiFiManager; // if(event == SYSTEM_EVENT_STA_START) WiFi.setHostname("wmtest"); // if(event == SYSTEM_EVENT_AP_START) WiFi.softAPsetHostname("wmtest"); - if(event == SYSTEM_EVENT_STA_DISCONNECTED){ + if(event == SYSTEM_EVENT_STA_DISCONNECTED){ + // Serial.println(info.disconnected.reason); + if(info.disconnected.reason == WIFI_REASON_AUTH_EXPIRE) Serial.println("*WM: EVENT: WIFI_REASON: AUTH_EXPIRE"); + if(info.disconnected.reason == WIFI_REASON_AUTH_FAIL) Serial.println("*WM: EVENT: WIFI_REASON: AUTH_FAIL"); + if(info.disconnected.reason == WIFI_REASON_NO_AP_FOUND) Serial.println("*WM: EVENT: WIFI_REASON: NO_AP_FOUND"); // Serial.println("Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); // _WiFiManager.DEBUG_WM("ESP32 Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); // @todo remove debugging from prod, or change static method WiFi.reconnect(); diff --git a/WiFiManager.h b/WiFiManager.h index 02c85d3..62917fa 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -275,7 +275,7 @@ class WiFiManager void WiFi_autoReconnect(); String WiFi_SSID(); - static void WiFiEvent(WiFiEvent_t event); + static void WiFiEvent(WiFiEvent_t event, system_event_info_t info); // output helpers From 3d7074166c35d4f75def32e9ed221624db3f2165 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 20 Feb 2018 08:49:54 -0600 Subject: [PATCH 201/424] #528 using a static var for esp32 event for now to get this working and test. Probably not the best, not sure what the best option is here for esp32 onevent static member function callbacks --- WiFiManager.cpp | 40 +++++++++++++++++++++++++--------------- WiFiManager.h | 5 +++-- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index e3f3624..1ffba8c 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -11,6 +11,7 @@ */ #include "WiFiManager.h" +uint8_t WiFiManager::_lastconxresulttmp = WL_IDLE_STATUS; /** * -------------------------------------------------------------------------------- @@ -575,14 +576,21 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) { if(connRes != WL_SCAN_COMPLETED){ _lastconxresult = connRes; - #ifdef ESP8266 // hack in wrong password detection if(_lastconxresult == WL_CONNECT_FAILED){ - if(wifi_station_get_connect_status() == STATION_WRONG_PASSWORD){ - _lastconxresult = WL_STATION_WRONG_PASSWORD; - } + #ifdef ESP8266 + if(wifi_station_get_connect_status() == STATION_WRONG_PASSWORD){ + _lastconxresult = WL_STATION_WRONG_PASSWORD; + } + #elif defined(ESP32) + // DEBUG_WM("lastconxresulttmp:",getWLStatusString(_lastconxresulttmp)); + if(_lastconxresulttmp != WL_IDLE_STATUS){ + _lastconxresult = _lastconxresulttmp; + _lastconxresulttmp = WL_IDLE_STATUS; + } + #endif } - #endif + DEBUG_WM("lastconxresult:",getWLStatusString(_lastconxresult)); } return connRes; @@ -1945,15 +1953,17 @@ String WiFiManager::WiFi_SSID(){ void WiFiManager::WiFiEvent(WiFiEvent_t event,system_event_info_t info){ #ifdef ESP32 // WiFiManager _WiFiManager; - // if(event == SYSTEM_EVENT_STA_START) WiFi.setHostname("wmtest"); - // if(event == SYSTEM_EVENT_AP_START) WiFi.softAPsetHostname("wmtest"); - if(event == SYSTEM_EVENT_STA_DISCONNECTED){ - // Serial.println(info.disconnected.reason); - if(info.disconnected.reason == WIFI_REASON_AUTH_EXPIRE) Serial.println("*WM: EVENT: WIFI_REASON: AUTH_EXPIRE"); - if(info.disconnected.reason == WIFI_REASON_AUTH_FAIL) Serial.println("*WM: EVENT: WIFI_REASON: AUTH_FAIL"); - if(info.disconnected.reason == WIFI_REASON_NO_AP_FOUND) Serial.println("*WM: EVENT: WIFI_REASON: NO_AP_FOUND"); - // Serial.println("Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); - // _WiFiManager.DEBUG_WM("ESP32 Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); // @todo remove debugging from prod, or change static method + // Serial.print("WM: EVENT: ");Serial.println(event); + if(event == SYSTEM_EVENT_STA_DISCONNECTED){ + if(info.disconnected.reason == WIFI_REASON_AUTH_EXPIRE || info.disconnected.reason == WIFI_REASON_AUTH_FAIL){ + Serial.print("WM: EVENT: WIFI_REASON: ");Serial.println(info.disconnected.reason); + _lastconxresulttmp = 7; + return; + } + // if(event == SYSTEM_EVENT_STA_START) WiFi.setHostname("wmtest"); + // if(event == SYSTEM_EVENT_AP_START) WiFi.softAPsetHostname("wmtest"); + // if(info.disconnected.reason == WIFI_REASON_NO_AP_FOUND) Serial.println("*WM: EVENT: WIFI_REASON: NO_AP_FOUND"); + Serial.println("*WM: Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); WiFi.reconnect(); } #endif @@ -1964,7 +1974,7 @@ void WiFiManager::WiFi_autoReconnect(){ WiFi.setAutoReconnect(_wifiAutoReconnect); #elif defined(ESP32) if(_wifiAutoReconnect){ - DEBUG_WM("ESP32 autoreconnect handler enabled"); + DEBUG_WM("ESP32 event handler enabled"); WiFi.onEvent(WiFiEvent); } #endif diff --git a/WiFiManager.h b/WiFiManager.h index 62917fa..fdb7ddd 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -209,12 +209,13 @@ class WiFiManager // options flags unsigned long _configPortalTimeout = 0; // ms close config portal loop if set (depending on _cp/webClientCheck options) - unsigned long _connectTimeout = 0; // ms stop trying to connect to ap if set + unsigned long _connectTimeout = 10000; // ms stop trying to connect to ap if set unsigned long _configPortalStart = 0; // ms config portal start time (updated for timeouts) unsigned long _webPortalAccessed = 0; // ms last web access time WiFiMode_t _usermode = WIFI_OFF; String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid - uint8_t _lastconxresult = WL_IDLE_STATUS; + uint8_t _lastconxresult = WL_IDLE_STATUS; + static uint8_t _lastconxresulttmp; #ifndef WL_STATION_WRONG_PASSWORD uint8_t WL_STATION_WRONG_PASSWORD = 7; From 39f20a6adcbcc55c4674182bd7ad2b0f6522e7c9 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 20 Feb 2018 11:13:46 -0600 Subject: [PATCH 202/424] #528 WL_DISCONNECTED support for testing --- WiFiManager.cpp | 19 ++++++++++++------- WiFiManager.h | 7 +++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 1ffba8c..d3179a9 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -11,7 +11,10 @@ */ #include "WiFiManager.h" + +#ifdef ESP32 uint8_t WiFiManager::_lastconxresulttmp = WL_IDLE_STATUS; +#endif /** * -------------------------------------------------------------------------------- @@ -217,7 +220,6 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { } return true; } - // not connected start configportal return startConfigPortal(apName, apPassword); } @@ -577,19 +579,22 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) { if(connRes != WL_SCAN_COMPLETED){ _lastconxresult = connRes; // hack in wrong password detection - if(_lastconxresult == WL_CONNECT_FAILED){ - #ifdef ESP8266 + #ifdef ESP8266 + if(_lastconxresult == WL_CONNECT_FAILED){ if(wifi_station_get_connect_status() == STATION_WRONG_PASSWORD){ _lastconxresult = WL_STATION_WRONG_PASSWORD; } - #elif defined(ESP32) - // DEBUG_WM("lastconxresulttmp:",getWLStatusString(_lastconxresulttmp)); + } + #elif defined(ESP32) + // if(_lastconxresult == WL_CONNECT_FAILED){ + if(_lastconxresult == WL_CONNECT_FAILED || _lastconxresult == WL_DISCONNECTED){ + DEBUG_WM("lastconxresulttmp:",getWLStatusString(_lastconxresulttmp)); if(_lastconxresulttmp != WL_IDLE_STATUS){ _lastconxresult = _lastconxresulttmp; _lastconxresulttmp = WL_IDLE_STATUS; } + } #endif - } DEBUG_WM("lastconxresult:",getWLStatusString(_lastconxresult)); } @@ -1955,8 +1960,8 @@ void WiFiManager::WiFiEvent(WiFiEvent_t event,system_event_info_t info){ // WiFiManager _WiFiManager; // Serial.print("WM: EVENT: ");Serial.println(event); if(event == SYSTEM_EVENT_STA_DISCONNECTED){ + Serial.print("WM: EVENT: WIFI_REASON: ");Serial.println(info.disconnected.reason); if(info.disconnected.reason == WIFI_REASON_AUTH_EXPIRE || info.disconnected.reason == WIFI_REASON_AUTH_FAIL){ - Serial.print("WM: EVENT: WIFI_REASON: ");Serial.println(info.disconnected.reason); _lastconxresulttmp = 7; return; } diff --git a/WiFiManager.h b/WiFiManager.h index fdb7ddd..4a5e239 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -209,14 +209,17 @@ class WiFiManager // options flags unsigned long _configPortalTimeout = 0; // ms close config portal loop if set (depending on _cp/webClientCheck options) - unsigned long _connectTimeout = 10000; // ms stop trying to connect to ap if set + unsigned long _connectTimeout = 0; // ms stop trying to connect to ap if set unsigned long _configPortalStart = 0; // ms config portal start time (updated for timeouts) unsigned long _webPortalAccessed = 0; // ms last web access time WiFiMode_t _usermode = WIFI_OFF; String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid uint8_t _lastconxresult = WL_IDLE_STATUS; - static uint8_t _lastconxresulttmp; + #ifdef ESP32 + static uint8_t _lastconxresulttmp; // tmp var for esp32 callback + #endif + #ifndef WL_STATION_WRONG_PASSWORD uint8_t WL_STATION_WRONG_PASSWORD = 7; #endif From e01101eff1c22d46bed1d76fde833abca888ab47 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 20 Feb 2018 11:54:14 -0600 Subject: [PATCH 203/424] #534 --- WiFiManager.cpp | 26 ++++++++++++------- WiFiManager.h | 2 ++ .../AutoConnectWithFSParameters.ino | 6 ++++- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index d3179a9..190febb 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -31,6 +31,10 @@ WiFiManagerParameter::WiFiManagerParameter(const char *custom) { _customHTML = custom; } +WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder) { + init(id, placeholder, "", 0, "", WFM_LABEL_BEFORE); +} + WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length) { init(id, placeholder, defaultValue, length, "", WFM_LABEL_BEFORE); } @@ -46,17 +50,9 @@ WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placehold void WiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) { _id = id; _placeholder = placeholder; - _length = length; _labelPlacement = labelPlacement; - _value = new char[length + 1]; - for (int i = 0; i < length + 1; i++) { - _value[i] = 0; - } - if (defaultValue != NULL) { - strncpy(_value, defaultValue, length + 1); // length+1 due to null terminated string - } - - _customHTML = custom; + _customHTML = custom; + setValue(defaultValue,length); } WiFiManagerParameter::~WiFiManagerParameter() { @@ -65,6 +61,16 @@ WiFiManagerParameter::~WiFiManagerParameter() { } } +void WiFiManagerParameter::setValue(const char *defaultValue, int length) { + _length = length; + _value = new char[length + 1]; + for (int i = 0; i < length + 1; i++) { + _value[i] = 0; + } + if (defaultValue != NULL) { + strncpy(_value, defaultValue, length + 1); // length+1 due to null terminated string + } +} const char* WiFiManagerParameter::getValue() { return _value; } diff --git a/WiFiManager.h b/WiFiManager.h index 4a5e239..5b4f445 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -67,6 +67,7 @@ class WiFiManagerParameter { @id is used for HTTP queries and must not contain spaces nor other special characters */ WiFiManagerParameter(const char *custom); + WiFiManagerParameter(const char *id, const char *placeholder); WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length); WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom); WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement); @@ -78,6 +79,7 @@ class WiFiManagerParameter { int getValueLength(); int getLabelPlacement(); const char *getCustomHTML(); + void setValue(const char *defaultValue, int length); private: const char *_id; const char *_placeholder; diff --git a/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino b/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino index d46729c..8445054 100644 --- a/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino +++ b/examples/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino @@ -1,6 +1,7 @@ #include // this needs to be first, or it all crashes and burns... #include // https://github.com/tzapu/WiFiManager #include // https://github.com/bblanchon/ArduinoJson +#include //define your default values here, if there are different values in config.json, they are overwritten. char mqtt_server[40]; @@ -68,7 +69,10 @@ void setup() { // id/name placeholder/prompt default length WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 40); WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 6); - WiFiManagerParameter custom_blynk_token("blynk", "blynk token", blynk_token, 32); + // WiFiManagerParameter custom_blynk_token("blynk", "blynk token", "", 0); + + WiFiManagerParameter custom_blynk_token("blynk", "blynk token"); + custom_blynk_token.setValue("setvalue override",32); //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around From 35bf4a94bd569d2ed99e04c1c18d6d4cbc8ae284 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 20 Feb 2018 12:59:37 -0600 Subject: [PATCH 204/424] change webserver pointer to using --- WiFiManager.cpp | 6 +----- WiFiManager.h | 5 +++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 190febb..1a7fc7f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -332,11 +332,7 @@ void WiFiManager::setupConfigPortal() { // setup dns and web servers dnsServer.reset(new DNSServer()); - #if defined(ESP32) && defined(WEBSERVERSHIM) - server.reset(new WebServer(80)); - #else - server.reset(new ESP8266WebServer(80)); - #endif + server.reset(new WM_WebServer(80)); /* Setup the DNS server redirecting all the domains to the apIP */ dnsServer->setErrorReplyCode(DNSReplyCode::NoError); diff --git a/WiFiManager.h b/WiFiManager.h index 5b4f445..754764e 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -189,10 +189,11 @@ class WiFiManager std::unique_ptr dnsServer; #if defined(ESP32) && defined(WEBSERVERSHIM) - std::unique_ptr server; + using WM_WebServer = WebServer; #else - std::unique_ptr server; + using WM_WebServer = ESP8266WebServer; #endif + std::unique_ptr server; // ip configs IPAddress _ap_static_ip; From 4e57d74e87bfdc67debadd28774b5afa5a923394 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 21 Feb 2018 10:52:55 -0600 Subject: [PATCH 205/424] fix some minor warnings --- WiFiManager.cpp | 18 +++++++++--------- WiFiManager.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 0bb02f7..59ce192 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -190,7 +190,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { WiFi_autoReconnect(); // set hostname before stating - if(_hostname != ""){ + if((String)_hostname != ""){ bool res = true; #ifdef ESP8266 res = WiFi.hostname(_hostname); @@ -217,7 +217,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { DEBUG_WM(F("IP Address:"),WiFi.localIP()); _lastconxresult = WL_CONNECTED; - if(_hostname != ""){ + if((String)_hostname != ""){ #ifdef ESP8266 DEBUG_WM("hostname: STA",WiFi.hostname()); #elif defined(ESP32) @@ -258,7 +258,7 @@ bool WiFiManager::startAP(){ // set ap hostname #ifdef ESP32 - if(ret && _hostname != ""){ + if(ret && (String)_hostname != ""){ bool res = WiFi.softAPsetHostname(_hostname); if(!res)DEBUG_WM(F("hostname: AP set failed!")); DEBUG_WM(F("hostname: AP"),WiFi.softAPgetHostname()); @@ -307,7 +307,7 @@ boolean WiFiManager::configPortalHasTimeout(){ return false; } // handle timeout - if(_webClientCheck && _webPortalAccessed>_configPortalStart>0) _configPortalStart = _webPortalAccessed; + if(_webClientCheck && (_webPortalAccessed>_configPortalStart)>0) _configPortalStart = _webPortalAccessed; if(millis() > _configPortalStart + _configPortalTimeout){ DEBUG_WM(F("config portal has timed out")); @@ -567,7 +567,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) { } } - uint8_t connRes = waitforconx ? waitForConnectResult() : WL_NO_SSID_AVAIL; + uint8_t connRes = waitforconx ? waitForConnectResult() : (uint8_t)WL_NO_SSID_AVAIL; DEBUG_WM (F("Connection result:"),getWLStatusString(connRes)); // do WPS, if WPS options enabled and not connected and no password was supplied @@ -616,7 +616,7 @@ uint8_t WiFiManager::waitForConnectResult() { } DEBUG_WM (F("connectTimeout set, waiting for connect....")); - uint8_t status; + uint8_t status = WiFi.status(); int timeout = millis() + _connectTimeout; while(millis() < timeout) { @@ -1778,8 +1778,8 @@ void WiFiManager::debugPlatformInfo(){ #endif } -uint8_t WiFiManager::getRSSIasQuality(uint8_t RSSI) { - uint8_t quality = 0; +int WiFiManager::getRSSIasQuality(int RSSI) { + int quality = 0; if (RSSI <= -100) { quality = 0; @@ -1834,7 +1834,7 @@ boolean WiFiManager::validApPassword(){ * @return {[type]} [description] */ String WiFiManager::getWLStatusString(uint8_t status){ - if(status >=0 && status <=7) return WIFI_STA_STATUS[status]; + if(status <= 7) return WIFI_STA_STATUS[status]; return FPSTR(S_NA); } diff --git a/WiFiManager.h b/WiFiManager.h index 754764e..1a9e98c 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -293,7 +293,7 @@ class WiFiManager String getHTTPHead(String title); //helpers - uint8_t getRSSIasQuality(uint8_t RSSI); + int getRSSIasQuality(int RSSI); boolean isIp(String str); String toStringIp(IPAddress ip); boolean validApPassword(); From c2bdbfafb9cf908042bdc184d4f66ec4f26057c3 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 21 Feb 2018 17:11:57 -0600 Subject: [PATCH 206/424] adding menu control, in progress --- WiFiManager.cpp | 56 +++++++++++++++++++++++++++++++++++++++++-------- WiFiManager.h | 27 ++++++++++++++++++++---- strings_en.h | 23 +++++++++++++++----- 3 files changed, 88 insertions(+), 18 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 59ce192..256eb9e 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -145,7 +145,7 @@ WiFiManager::WiFiManager():_debugPort(Serial) { //parameters // @todo belongs to wifimanagerparameter _max_params = WIFI_MANAGER_MAX_PARAMS; - _params = (WiFiManagerParameter**)malloc(_max_params * sizeof(WiFiManagerParameter*)); + _params = (WiFiManagerParameter**)malloc(_max_params * sizeof(WiFiManagerParameter*)); } // destructor @@ -180,6 +180,8 @@ boolean WiFiManager::autoConnect() { boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { DEBUG_WM(F("AutoConnect")); + Serial.println(getMenuOut()); + // attempt to connect using saved settings, on fail fallback to AP config portal WiFi.enableSTA(true); _usermode = WIFI_STA; @@ -343,10 +345,11 @@ void WiFiManager::setupConfigPortal() { server->on((String)F("/wifi"), std::bind(&WiFiManager::handleWifi, this, true)); server->on((String)F("/0wifi"), std::bind(&WiFiManager::handleWifi, this, false)); server->on((String)F("/wifisave"), std::bind(&WiFiManager::handleWifiSave, this)); - server->on((String)F("/i"), std::bind(&WiFiManager::handleInfo, this)); - server->on((String)F("/r"), std::bind(&WiFiManager::handleReset, this)); + server->on((String)F("/info"), std::bind(&WiFiManager::handleInfo, this)); + server->on((String)F("/param"), std::bind(&WiFiManager::handleParam, this)); + server->on((String)F("/restart"), std::bind(&WiFiManager::handleReset, this)); server->on((String)F("/exit"), std::bind(&WiFiManager::handleExit, this)); - // server->on((String)F("/exit"), std::bind(&WiFiManager::stopCaptivePortal, this)); + server->on((String)F("/close"), std::bind(&WiFiManager::stopCaptivePortal, this)); server->on((String)F("/erase"), std::bind(&WiFiManager::handleErase, this)); server->on((String)F("/status"), std::bind(&WiFiManager::handleWiFiStatus, this)); //server->on("/fwlink", std::bind(&WiFiManager::handleRoot, this)); //Microsoft captive portal. Maybe not needed. Might be handled by notFound handler. @@ -423,7 +426,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo break; } - state = handleConfigPortal(); + state = processConfigPortal(); // status change, break if(state != WL_IDLE_STATUS){ @@ -445,14 +448,14 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo */ boolean WiFiManager::process(){ if(webPortalActive || (configPortalActive && !_configPortalIsBlocking)){ - uint8_t state = handleConfigPortal(); + uint8_t state = processConfigPortal(); return state == WL_CONNECTED; } return false; } //using esp enums returns for now, should be fine -uint8_t WiFiManager::handleConfigPortal(){ +uint8_t WiFiManager::processConfigPortal(){ //DNS handler dnsServer->processNextRequest(); //HTTP handler @@ -672,6 +675,7 @@ void WiFiManager::handleRoot() { str.replace(FPSTR(T_v),configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading page += str; page += FPSTR(HTTP_PORTAL_OPTIONS); + page += getMenuOut(); reportStatus(page); page += FPSTR(HTTP_END); @@ -695,8 +699,7 @@ void WiFiManager::handleWifi(boolean scan) { page += pitem; page += getStaticOut(); - page += getParamOut(); - + if(_paramsInWifi) page += getParamOut(); page += FPSTR(HTTP_FORM_END); page += FPSTR(HTTP_SCAN_LINK); reportStatus(page); @@ -711,6 +714,38 @@ void WiFiManager::handleWifi(boolean scan) { DEBUG_WM(F("Sent config page")); } +/** + * HTTPD CALLBACK Wifi param page handler + */ +void WiFiManager::handleParam(){ + DEBUG_WM(F("<- HTTP Param")); + handleRequest(); + String page = getHTTPHead(FPSTR(S_titleparam)); // @token titlewifi + + page += getParamOut(); + page += FPSTR(HTTP_FORM_END); + reportStatus(page); + page += FPSTR(HTTP_END); + + server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); + server->send(200, FPSTR(HTTP_HEAD_CT), page); + + DEBUG_WM(F("Sent param page")); +} + + +String WiFiManager::getMenuOut(){ + String page; + int i; + for(i=0;i server; + // std:vector _menuids; + uint8_t _menuIds[7] = {MENU_WIFI,MENU_INFO,MENU_PARAM,MENU_SEP,MENU_CLOSE,MENU_ERASE,MENU_EXIT}; + // ip configs IPAddress _ap_static_ip; IPAddress _ap_static_gw; @@ -217,14 +234,14 @@ class WiFiManager unsigned long _webPortalAccessed = 0; // ms last web access time WiFiMode_t _usermode = WIFI_OFF; String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid - uint8_t _lastconxresult = WL_IDLE_STATUS; + uint8_t _lastconxresult = WL_IDLE_STATUS; #ifdef ESP32 static uint8_t _lastconxresulttmp; // tmp var for esp32 callback #endif #ifndef WL_STATION_WRONG_PASSWORD - uint8_t WL_STATION_WRONG_PASSWORD = 7; + uint8_t WL_STATION_WRONG_PASSWORD = 7; // @kludge define a WL status for wrong password #endif // option parameters @@ -240,6 +257,7 @@ class WiFiManager boolean _cpClientCheck = false; // keep cp alive if cp have station boolean _webClientCheck = true; // keep cp alive if web have client boolean _scanDispOptions = false; // show percentage in scans not icons + boolean _paramsInWifi = true; // show custom parameters on wifi page const char * _hostname = ""; const char* _customHeadElement = ""; // store custom head element html from user @@ -261,13 +279,14 @@ class WiFiManager void handleNotFound(); void handleExit(); void handleErase(); + void handleParam(); void handleWiFiStatus(); void handleRequest(); boolean captivePortal(); boolean configPortalHasTimeout(); boolean stopConfigPortal(); - uint8_t handleConfigPortal(); + uint8_t processConfigPortal(); void stopCaptivePortal(); // wifi platform abstractions @@ -291,7 +310,7 @@ class WiFiManager String getScanItemOut(); String getStaticOut(); String getHTTPHead(String title); - + String getMenuOut(); //helpers int getRSSIasQuality(int RSSI); boolean isIp(String str); diff --git a/strings_en.h b/strings_en.h index 2d3ea9d..6e7c11b 100644 --- a/strings_en.h +++ b/strings_en.h @@ -22,8 +22,20 @@ const char HTTP_SCRIPT[] PROGMEM = ""; const char HTTP_HEAD_END[] PROGMEM = "
"; From 17f2316ea84c694240b8ac7d02b20efce4e70ba4 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 13 Jul 2018 18:41:14 -0500 Subject: [PATCH 336/424] fixes #655 --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 0245a88..765b65b 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1078,7 +1078,7 @@ String WiFiManager::getParamOut(){ String HTTP_PARAM_temp = FPSTR(HTTP_FORM_LABEL); HTTP_PARAM_temp += FPSTR(HTTP_FORM_PARAM); - bool tok_I = HTTP_PARAM_temp.indexOf(FPSTR(T_i)) > 0; + bool tok_I = HTTP_PARAM_temp.indexOf(FPSTR(T_I)) > 0; bool tok_i = HTTP_PARAM_temp.indexOf(FPSTR(T_i)) > 0; bool tok_n = HTTP_PARAM_temp.indexOf(FPSTR(T_n)) > 0; bool tok_p = HTTP_PARAM_temp.indexOf(FPSTR(T_p)) > 0; @@ -1113,7 +1113,7 @@ String WiFiManager::getParamOut(){ // if no ID use customhtml for item, else generate from param string if (_params[i]->getID() != NULL) { - if(tok_I)pitem.replace(FPSTR(T_i), (String)FPSTR(S_parampre)+(String)i); + if(tok_I)pitem.replace(FPSTR(T_I), (String)FPSTR(S_parampre)+(String)i); if(tok_i)pitem.replace(FPSTR(T_i), _params[i]->getID()); if(tok_n)pitem.replace(FPSTR(T_n), _params[i]->getID()); if(tok_p)pitem.replace(FPSTR(T_p), FPSTR(T_t)); From 933f86720ab8a12d7a74ad67ad6710e189861fa0 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 13 Jul 2018 23:43:07 -0500 Subject: [PATCH 337/424] param was using user length for strncpy, causing overflows --- WiFiManager.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 576d10f..0e4f36f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -63,12 +63,17 @@ WiFiManagerParameter::~WiFiManagerParameter() { void WiFiManagerParameter::setValue(const char *defaultValue, int length) { _length = length; + length = strlen(defaultValue); // length actual + if(_length < length){ + // Serial.println("defaultValue length mismatch"); + } _value = new char[length + 1]; for (int i = 0; i < length + 1; i++) { _value[i] = 0; } if (defaultValue != NULL) { - strncpy(_value, defaultValue, length + 1); // length+1 due to null terminated string + strncpy(_value, defaultValue, length); + _value[length] = '\0'; // explicit null } } const char* WiFiManagerParameter::getValue() { From fc84e7a2607b0d35c750ce1b7983238d2e4bf87e Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 13 Jul 2018 23:52:36 -0500 Subject: [PATCH 338/424] trying to fix param issues when param is out of scope Ideally this should be done entirely different so params can follow wm scope and object lifetime.. --- WiFiManager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 0e4f36f..45aa4bf 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -59,6 +59,7 @@ WiFiManagerParameter::~WiFiManagerParameter() { if (_value != NULL) { delete[] _value; } + _length=0; // setting length 0, ideally the entire parameter should be removed, or added to wifimanager scope so it follows } void WiFiManagerParameter::setValue(const char *defaultValue, int length) { @@ -1095,7 +1096,8 @@ String WiFiManager::getParamOut(){ char parLength[5]; // add the extra parameters to the form for (int i = 0; i < _paramsCount; i++) { - if (_params[i] == NULL) { + if (_params[i] == NULL || _params[i]->_length == 0) { + DEBUG_WM(DEBUG_ERROR,"[ERROR] WiFiManagerParameter is out of scope"); break; } From 85dd747949f302c022330dbd509107237fed7ecd Mon Sep 17 00:00:00 2001 From: Christopher Liebman Date: Sun, 15 Jul 2018 10:44:06 -0700 Subject: [PATCH 339/424] Use hasParam() instead of checking server.arg() for NULL, it returns a String anyway. Don't use .c_str() when its being assigned to a String anyway --- WiFiManager.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 45aa4bf..fb5eb08 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1228,9 +1228,13 @@ void WiFiManager::doParamSave(){ break; } //read parameter from server + String name = (String)FPSTR(S_parampre)+(String)i; String value; - if(server->arg((String)FPSTR(S_parampre)+(String)i) != NULL) value = server->arg((String)FPSTR(S_parampre)+(String)i).c_str(); - else value = server->arg(_params[i]->getID()).c_str(); + if(server->hasArg(name)) { + value = server->arg(name); + } else { + value = server->arg(_params[i]->getID()); + } //store it in params array value.toCharArray(_params[i]->_value, _params[i]->_length+1); // length+1 null terminated From 2fac07cbf0228d49a479fa2811bf97591a2d532d Mon Sep 17 00:00:00 2001 From: Christopher Liebman Date: Sun, 15 Jul 2018 14:39:11 -0700 Subject: [PATCH 340/424] WiFiManagerParameter::setValue used length of default value for i allocation and not passed length. Changed to use passed length or length of default value if > passed length. --- WiFiManager.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index fb5eb08..477dde4 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -67,14 +67,16 @@ void WiFiManagerParameter::setValue(const char *defaultValue, int length) { length = strlen(defaultValue); // length actual if(_length < length){ // Serial.println("defaultValue length mismatch"); + // use the length if it's longer. + _length = length; } - _value = new char[length + 1]; - for (int i = 0; i < length + 1; i++) { + _value = new char[_length + 1]; + for (int i = 0; i < _length + 1; i++) { _value[i] = 0; } if (defaultValue != NULL) { - strncpy(_value, defaultValue, length); - _value[length] = '\0'; // explicit null + strncpy(_value, defaultValue, _length); + _value[_length] = '\0'; // explicit null } } const char* WiFiManagerParameter::getValue() { @@ -1231,9 +1233,9 @@ void WiFiManager::doParamSave(){ String name = (String)FPSTR(S_parampre)+(String)i; String value; if(server->hasArg(name)) { - value = server->arg(name); + value = server->arg(name); } else { - value = server->arg(_params[i]->getID()); + value = server->arg(_params[i]->getID()); } //store it in params array From 9ab4deaf5bf0ff8163875a22f024a018f62f19e8 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 16 Jul 2018 08:06:03 -0500 Subject: [PATCH 341/424] clean up param length Just changing to not modify argument, spacing --- WiFiManager.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 477dde4..a6a6091 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -63,14 +63,15 @@ WiFiManagerParameter::~WiFiManagerParameter() { } void WiFiManagerParameter::setValue(const char *defaultValue, int length) { - _length = length; - length = strlen(defaultValue); // length actual + _length = length; + deflength = strlen(defaultValue); // length actual + // use the defult length if it's longer, + // @todo consider it might be useful to fail, so user knows they were wrong if(_length < length){ // Serial.println("defaultValue length mismatch"); - // use the length if it's longer. - _length = length; + _length = deflength; } - _value = new char[_length + 1]; + _value = new char[_length + 1]; for (int i = 0; i < _length + 1; i++) { _value[i] = 0; } From 08bb2322aa2987702786752f9d450b4b622e8768 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 16 Jul 2018 17:07:31 -0500 Subject: [PATCH 342/424] Oops --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index a6a6091..c21374f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -64,7 +64,7 @@ WiFiManagerParameter::~WiFiManagerParameter() { void WiFiManagerParameter::setValue(const char *defaultValue, int length) { _length = length; - deflength = strlen(defaultValue); // length actual + int deflength = strlen(defaultValue); // length actual // use the defult length if it's longer, // @todo consider it might be useful to fail, so user knows they were wrong if(_length < length){ From 74ceba740976b841aaeb18aea701b8de82039299 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Wed, 18 Jul 2018 14:01:45 -0500 Subject: [PATCH 343/424] add non blocking example --- .../AutoConnectNonBlocking.ino | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/AutoConnect/AutoConnectNonBlocking/AutoConnectNonBlocking.ino diff --git a/examples/AutoConnect/AutoConnectNonBlocking/AutoConnectNonBlocking.ino b/examples/AutoConnect/AutoConnectNonBlocking/AutoConnectNonBlocking.ino new file mode 100644 index 0000000..3187bec --- /dev/null +++ b/examples/AutoConnect/AutoConnectNonBlocking/AutoConnectNonBlocking.ino @@ -0,0 +1,26 @@ +#include // https://github.com/tzapu/WiFiManager +WiFiManager wm; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + + //reset settings - wipe credentials for testing + //wm.resetSettings(); + + wm.setConfigPortalBlocking(false); + + //automatically connect using saved credentials if they exist + //If connection fails it starts an access point with the specified name + if(wm.autoConnect("AutoConnectAP")){ + Serial.println("connected...yeey :)"); + } + else { + Serial.println("Configportal running"); + } +} + +void loop() { + wm.process(); + // put your main code here, to run repeatedly: +} From a39b96be9ca51b0f942077d6419fc621c6524726 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Wed, 18 Jul 2018 16:25:53 -0500 Subject: [PATCH 344/424] disable autoreconect esp32 --- WiFiManager.cpp | 2 +- WiFiManager.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index c21374f..838b45a 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2445,7 +2445,7 @@ void WiFiManager::WiFiEvent(WiFiEvent_t event,system_event_info_t info){ void WiFiManager::WiFi_autoReconnect(){ #ifdef ESP8266 WiFi.setAutoReconnect(_wifiAutoReconnect); - #elif defined(ESP32) + #elif defined(ESP32) && defined(esp32autoreconnect) if(_wifiAutoReconnect){ DEBUG_WM(DEBUG_VERBOSE,"ESP32 event handler enabled"); WiFi.onEvent(WiFiEvent); diff --git a/WiFiManager.h b/WiFiManager.h index 795f67d..99f4330 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -22,6 +22,9 @@ // #include "soc/efuse_reg.h" // include to add efuse chip rev to info, getChipRevision() is almost always the same though, so not sure why it matters. +// #define esp32autoreconnect // implement esp32 autoreconnect event listener kludge +// autoreconnect status WORKING https://github.com/espressif/arduino-esp32/issues/653#issuecomment-405604766 + #define WM_WEBSERVERSHIM // use webserver shim lib #ifdef ESP8266 From 0e6ed389864162056b754829f2133380f0c9b8e2 Mon Sep 17 00:00:00 2001 From: 0x1abin <270995079@qq.com> Date: Thu, 19 Jul 2018 14:36:18 +0800 Subject: [PATCH 345/424] compat macos newline --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 838b45a..85751aa 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2164,7 +2164,7 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { _debugPort.print(" "); _debugPort.print(textb); } - _debugPort.print("\n"); + _debugPort.println(); } From f1fd553ac66edc205d9fc880ba475ce0a9b37b58 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 19 Jul 2018 08:40:46 -0500 Subject: [PATCH 346/424] fix autoreconnect, forgot we use event for other stuff --- WiFiManager.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 838b45a..1a2521a 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2437,7 +2437,9 @@ void WiFiManager::WiFiEvent(WiFiEvent_t event,system_event_info_t info){ } else _lastconxresulttmp = WiFi.status(); // if(info.disconnected.reason == WIFI_REASON_NO_AP_FOUND) Serial.println("*WM: EVENT: WIFI_REASON: NO_AP_FOUND"); // Serial.println("*WM: Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); - WiFi.reconnect(); + #ifdef esp32autoreconnect + WiFi.reconnect(); + #endif } } #endif @@ -2445,7 +2447,7 @@ void WiFiManager::WiFiEvent(WiFiEvent_t event,system_event_info_t info){ void WiFiManager::WiFi_autoReconnect(){ #ifdef ESP8266 WiFi.setAutoReconnect(_wifiAutoReconnect); - #elif defined(ESP32) && defined(esp32autoreconnect) + #elif defined(ESP32) if(_wifiAutoReconnect){ DEBUG_WM(DEBUG_VERBOSE,"ESP32 event handler enabled"); WiFi.onEvent(WiFiEvent); From d140ccff84fc4881095aeddced2b7917e708963f Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 19 Jul 2018 10:02:53 -0500 Subject: [PATCH 347/424] adds setCountry, default US accepts US JP CN, codes must be added to strings and WiFiSetCountry atm --- WiFiManager.cpp | 28 +++++++++++++++++++++++++++- WiFiManager.h | 4 ++++ strings_en.h | 4 ++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 4f5ecaa..b18423e 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -218,6 +218,8 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { DEBUG_WM(DEBUG_ERROR,"[FATAL] Unable to enable wifi!"); return false; } + + WiFiSetCountry(); #ifdef ESP32 if(esp32persistent) WiFi.persistent(false); // disable persistent for esp32 after esp_wifi_start or else saves wont work @@ -484,6 +486,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo // start access point DEBUG_WM(DEBUG_VERBOSE,F("Enabling AP")); startAP(); + WiFiSetCountry(); // init configportal DEBUG_WM(DEBUG_DEV,F("setupConfigPortal")); @@ -2129,6 +2132,14 @@ bool WiFiManager::getWiFiIsSaved(){ return WiFi_hasAutoConnect(); } +/** + * setCountry + * @since $dev + * @param String cc country code, must be defined in WiFiSetCountry, US, JP, CN + */ +void WiFiManager::setCountry(String cc){ + _wificountry = cc; +} // HELPERS @@ -2167,7 +2178,6 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { _debugPort.println(); } - /** * [debugSoftAPConfig description] * @access public @@ -2303,6 +2313,22 @@ String WiFiManager::getModeString(uint8_t mode){ return FPSTR(S_NA); } + +bool WiFiManager::WiFiSetCountry(){ + bool ret = false; + // @todo check if wifi is init, no idea how, doesnt seem to be exposed + if(_wificountry == "") return ret; // skip not set + else if(WiFi.getMode() == WIFI_MODE_NULL); // exception if wifi not init! + else if(_wificountry == "US") ret = esp_wifi_set_country(&WM_COUNTRY_US) == ESP_OK; + else if(_wificountry == "JP") ret = esp_wifi_set_country(&WM_COUNTRY_JP) == ESP_OK; + else if(_wificountry == "CN") ret = esp_wifi_set_country(&WM_COUNTRY_CN) == ESP_OK; + else DEBUG_WM(DEBUG_ERROR,"[ERROR] country code not found"); + + if(ret) DEBUG_WM(DEBUG_VERBOSE,"esp_wifi_set_country: " + _wificountry); + else DEBUG_WM(DEBUG_ERROR,"[ERROR] esp_wifi_set_country failed"); + return ret; +} + // set mode ignores WiFi.persistent bool WiFiManager::WiFi_Mode(WiFiMode_t m,bool persistent) { bool ret; diff --git a/WiFiManager.h b/WiFiManager.h index 99f4330..6720ce5 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -235,6 +235,7 @@ class WiFiManager // debug output platform info and versioning void debugPlatformInfo(); String htmlEntities(String str); + void setCountry(String cc); private: std::unique_ptr dnsServer; @@ -314,6 +315,8 @@ class WiFiManager boolean _preloadwifiscan = true; // preload wifiscan if true boolean _disableIpFields = false; // edge case, if true, showxFields(false) forces ip fields off instead of default show when set + String _wificountry = "US"; // country code, @todo define in strings lang + // wrapper functions for handling setting and unsetting persistent for now. bool esp32persistent = false; bool _hasBegun = false; @@ -372,6 +375,7 @@ class WiFiManager bool WiFi_scanNetworks(); bool WiFi_scanNetworks(bool force); bool WiFi_scanNetworks(unsigned int cachetime); + bool WiFiSetCountry(); #ifdef ESP32 static void WiFiEvent(WiFiEvent_t event, system_event_info_t info); diff --git a/strings_en.h b/strings_en.h index 60850a2..de5d57d 100644 --- a/strings_en.h +++ b/strings_en.h @@ -318,3 +318,7 @@ const char * const AUTH_MODE_NAMES[] PROGMEM #endif const char* const WIFI_MODES[] PROGMEM = { "NULL", "STA", "AP", "STA+AP" }; + +const wifi_country_t WM_COUNTRY_US{"US",1,11,WIFI_COUNTRY_POLICY_AUTO}; +const wifi_country_t WM_COUNTRY_CN{"CN",1,13,WIFI_COUNTRY_POLICY_AUTO}; +const wifi_country_t WM_COUNTRY_JP{"JP",1,14,WIFI_COUNTRY_POLICY_AUTO}; \ No newline at end of file From 2db93d28c74ab4444ba118c7345c184e757d0a43 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 19 Jul 2018 10:05:25 -0500 Subject: [PATCH 348/424] clean up --- WiFiManager.h | 6 +- .../OnDemandConfigPortal.ino | 67 ++++++++++--------- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/WiFiManager.h b/WiFiManager.h index 6720ce5..1c26eab 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -294,9 +294,6 @@ class WiFiManager int _staShowDns = 0; // ternary always show dns, only if not set in code, never(cannot change dns via web!) boolean _removeDuplicateAPs = true; // remove dup aps from wifiscan boolean _shouldBreakAfterConfig = false; // stop configportal on save failure -#ifdef NO_EXTRA_4K_HEAP - boolean _tryWPS = false; // try WPS on save failure, unsupported -#endif boolean _configPortalIsBlocking = true; // configportal enters blocking loop boolean _enableCaptivePortal = true; // enable captive portal redirection boolean _userpersistent = true; // users preffered persistence to restore @@ -324,9 +321,12 @@ class WiFiManager void _end(); void setupConfigPortal(); + #ifdef NO_EXTRA_4K_HEAP + boolean _tryWPS = false; // try WPS on save failure, unsupported void startWPS(); #endif + bool startAP(); uint8_t connectWifi(String ssid, String pass); diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 0060d6d..cdd718c 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -1,12 +1,9 @@ #include // https://github.com/tzapu/WiFiManager -// select which pin will trigger the configuration portal when set to LOW -// ESP-01 users please note: the only pins available (0 and 2), are shared -// with the bootloader, so always set them HIGH at power-up #define TRIGGER_PIN 0 const char* modes[] = { "NULL", "STA", "AP", "STA+AP" }; -WiFiManager wifiManager; +WiFiManager wm; void setup() { @@ -21,27 +18,27 @@ void setup() { // Serial.println(modes[WiFi.getMode()]); //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around - // WiFiManager wifiManager; + // WiFiManager wm; //Local intialization. Once its business is done, there is no need to keep it around //reset settings - for testing - //wifiManager.resetSettings(); + //wm.resetSettings(); //sets timeout until configuration portal gets turned off //useful to make it all retry or go to sleep //in seconds - wifiManager.setConfigPortalTimeout(60); - wifiManager.setConnectTimeout(20); - // wifiManager.setShowStaticFields(true); + wm.setConfigPortalTimeout(60); + wm.setConnectTimeout(10); + // wm.setShowStaticFields(true); - // uint8_t menu[] = {wifiManager.MENU_WIFI,wifiManager.MENU_INFO,wifiManager.MENU_PARAM,wifiManager.MENU_CLOSE}; - // wifiManager.setMenu(menu); + // uint8_t menu[] = {wm.MENU_WIFI,wm.MENU_INFO,wm.MENU_PARAM,wm.MENU_CLOSE}; + // wm.setMenu(menu); - // std::vector menu = {wifiManager.MENU_WIFI,wifiManager.MENU_INFO,wifiManager.MENU_PARAM,wifiManager.MENU_CLOSE,wifiManager.MENU_SEP,wifiManager.MENU_ERASE,wifiManager.MENU_EXIT}; - // wifiManager.setMenu(menu); + // std::vector menu = {wm.MENU_WIFI,wm.MENU_INFO,wm.MENU_PARAM,wm.MENU_CLOSE,wm.MENU_SEP,wm.MENU_ERASE,wm.MENU_EXIT}; + // wm.setMenu(menu); -// std::vector menu = {wifiManager.MENU_WIFI,wifiManager.MENU_INFO,wifiManager.MENU_PARAM,wifiManager.MENU_CLOSE,wifiManager.MENU_SEP,wifiManager.MENU_ERASE,wifiManager.MENU_EXIT}; - // wifiManager.setMenu(menu); +// std::vector menu = {wm.MENU_WIFI,wm.MENU_INFO,wm.MENU_PARAM,wm.MENU_CLOSE,wm.MENU_SEP,wm.MENU_ERASE,wm.MENU_EXIT}; + // wm.setMenu(menu); WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40); @@ -50,10 +47,10 @@ void setup() { WiFiManagerParameter custom_tokenb("invalid token", "invalid token", "", 0); //add all your parameters here - wifiManager.addParameter(&custom_mqtt_server); - wifiManager.addParameter(&custom_mqtt_port); - wifiManager.addParameter(&custom_token); - wifiManager.addParameter(&custom_tokenb); + wm.addParameter(&custom_mqtt_server); + wm.addParameter(&custom_mqtt_port); + wm.addParameter(&custom_token); + wm.addParameter(&custom_tokenb); // MENU_WIFI = 0, // MENU_WIFINOSCAN = 1, @@ -66,24 +63,32 @@ void setup() { // MENU_SEP = 8 // const char* menu[] = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"}; - // wifiManager.setMenu(menu,9); + // wm.setMenu(menu,9); std::vector menu = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"}; - wifiManager.setMenu(menu); + wm.setMenu(menu); //set static ip - // wifiManager.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); - // wifiManager.setShowStaticFields(false); - // wifiManager.setShowDnsFields(false); + // wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); + // wm.setShowStaticFields(false); + // wm.setShowDnsFields(false); - wifiManager.setConfigPortalTimeout(60); - wifiManager.startConfigPortal("AutoConnectAP", "password"); + // WiFi.mode(WIFI_STA); + // const wifi_country_t COUNTRY_US{"US",1,11,WIFI_COUNTRY_POLICY_AUTO}; + // const wifi_country_t COUNTRY_CN{"CN",1,13,WIFI_COUNTRY_POLICY_AUTO}; + // const wifi_country_t COUNTRY_JP{"JP",1,14,WIFI_COUNTRY_POLICY_AUTO}; + // esp_wifi_set_country(&COUNTRY_US); + + wm.setCountry("US"); + + // wm.setConfigPortalTimeout(120); + // wm.startConfigPortal("AutoConnectAP", "password"); //fetches ssid and pass and tries to connect //if it does not connect it starts an access point with the specified name //here "AutoConnectAP" //and goes into a blocking loop awaiting configuration - if(!wifiManager.autoConnect("AutoConnectAP")) { + if(!wm.autoConnect("AutoConnectAP","password")) { Serial.println("failed to connect and hit timeout"); } @@ -97,12 +102,12 @@ void loop() { //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around //reset settings - for testing - //wifiManager.resetSettings(); + //wm.resetSettings(); //sets timeout until configuration portal gets turned off //useful to make it all retry or go to sleep //in seconds - wifiManager.setConfigPortalTimeout(120); + wm.setConfigPortalTimeout(120); //it starts an access point with the specified name //here "AutoConnectAP" @@ -112,9 +117,9 @@ void loop() { //WiFi.mode(WIFI_STA); // disable captive portal redirection - // wifiManager.setCaptivePortalEnable(false); + // wm.setCaptivePortalEnable(false); - if (!wifiManager.startConfigPortal("OnDemandAP")) { + if (!wm.startConfigPortal("OnDemandAP")) { Serial.println("failed to connect and hit timeout"); delay(3000); } else { From c9ca210803c30a84269e170eb0c06ff8e35c965a Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 19 Jul 2018 11:33:38 -0500 Subject: [PATCH 349/424] removing US default --- WiFiManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.h b/WiFiManager.h index 1c26eab..6433261 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -312,7 +312,7 @@ class WiFiManager boolean _preloadwifiscan = true; // preload wifiscan if true boolean _disableIpFields = false; // edge case, if true, showxFields(false) forces ip fields off instead of default show when set - String _wificountry = "US"; // country code, @todo define in strings lang + String _wificountry = ""; // country code, @todo define in strings lang // wrapper functions for handling setting and unsetting persistent for now. bool esp32persistent = false; From 37cdda33c7b0ebd525892fc23f825cb530febcc9 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 19 Jul 2018 13:10:37 -0500 Subject: [PATCH 350/424] adds setClass(invert) black theme adds class string to body, invert(black) is built in ` wm.setClass("invert");` --- WiFiManager.cpp | 20 ++++++++++++++++++-- WiFiManager.h | 5 +++++ extras/WiFiManager.template.html | 24 +++++++++++++++++++----- strings_en.h | 28 ++++++++++++++-------------- 4 files changed, 56 insertions(+), 21 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index b18423e..39cea64 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -817,7 +817,16 @@ String WiFiManager::getHTTPHead(String title){ page += FPSTR(HTTP_SCRIPT); page += FPSTR(HTTP_STYLE); page += _customHeadElement; - page += FPSTR(HTTP_HEAD_END); + + if(_bodyClass != ""){ + String p = FPSTR(HTTP_HEAD_END); + p.replace(FPSTR(T_c), _bodyClass); // add class str + page += p; + } + else { + page += FPSTR(HTTP_HEAD_END); + } + return page; } @@ -1567,7 +1576,6 @@ void WiFiManager::handleErase(boolean opt) { DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Erase")); handleRequest(); String page = getHTTPHead(FPSTR(S_titleerase)); // @token titleerase - page += FPSTR(HTTP_HEAD_END); bool ret = erase(opt); @@ -2141,6 +2149,14 @@ void WiFiManager::setCountry(String cc){ _wificountry = cc; } +/** + * setClass + * @param String str body class string + */ +void WiFiManager::setClass(String str){ + _bodyClass = str; +} + // HELPERS // DEBUG diff --git a/WiFiManager.h b/WiFiManager.h index 6433261..7f63817 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -235,7 +235,11 @@ class WiFiManager // debug output platform info and versioning void debugPlatformInfo(); String htmlEntities(String str); + + // set the country code for wifi settings void setCountry(String cc); + // set body class (invert) + void setClass(String str); private: std::unique_ptr dnsServer; @@ -307,6 +311,7 @@ class WiFiManager const char * _hostname = ""; const char* _customHeadElement = ""; // store custom head element html from user + String _bodyClass = ""; // class to add to body // internal options boolean _preloadwifiscan = true; // preload wifiscan if true diff --git a/extras/WiFiManager.template.html b/extras/WiFiManager.template.html index e3b6ee9..e4dc77f 100644 --- a/extras/WiFiManager.template.html +++ b/extras/WiFiManager.template.html @@ -7,6 +7,23 @@ "; const char HTTP_HELP[] PROGMEM = @@ -134,7 +134,7 @@ const char HTTP_JS[] PROGMEM = #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_lastreset[] PROGMEM = "
Last reset reason
CPU0: {1}
CPU1: {2}
"; const char HTTP_INFO_aphost[] PROGMEM = "
Acccess Point Hostname
{1}
"; #else const char HTTP_INFO_esphead[] PROGMEM = "

esp8266


"; @@ -245,11 +245,11 @@ const char S_dns[] PROGMEM = "dns"; // softap ssid default prefix #ifdef ESP8266 - const char S_ssidpre[] PROGMEM = "ESP"; + const char S_ssidpre[] PROGMEM = "ESP"; #elif defined(ESP32) - const char S_ssidpre[] PROGMEM = "ESP32"; + const char S_ssidpre[] PROGMEM = "ESP32"; #else - const char S_ssidpre[] PROGMEM = "WM"; + const char S_ssidpre[] PROGMEM = "WM"; #endif //Tokens @@ -276,8 +276,8 @@ const char T_h[] PROGMEM = "{h}"; // @token h const char HTTP_HEAD_CL[] PROGMEM = "Content-Length"; const char HTTP_HEAD_CT[] PROGMEM = "text/html"; const char HTTP_HEAD_CT2[] PROGMEM = "text/plain"; -const char HTTP_HEAD_CORS[] PROGMEM = "Access-Control-Allow-Origin"; -const char HTTP_HEAD_CORS_ALLOW_ALL[] PROGMEM = "*"; +const char HTTP_HEAD_CORS[] PROGMEM = "Access-Control-Allow-Origin"; +const char HTTP_HEAD_CORS_ALLOW_ALL[] PROGMEM = "*"; const char * const WIFI_STA_STATUS[] PROGMEM { From f2f0aabe3e75fd495c87f1b4a4a14f82184f02f8 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 19 Jul 2018 14:02:02 -0500 Subject: [PATCH 351/424] dark theme tweaks --- examples/Advanced/Advanced.ino | 3 +++ extras/WiFiManager.template.html | 23 ++++++++++++----------- strings_en.h | 8 ++++---- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/examples/Advanced/Advanced.ino b/examples/Advanced/Advanced.ino index f47b021..7bc3795 100644 --- a/examples/Advanced/Advanced.ino +++ b/examples/Advanced/Advanced.ino @@ -30,6 +30,9 @@ void setup() { // wm.setMenu(menu,6); std::vector menu = {"wifi","info","param","sep","restart","exit"}; wm.setMenu(menu); + + // set dark theme + // wm.setClass("invert"); //set static ip // wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); // set static ip,gw,sn diff --git a/extras/WiFiManager.template.html b/extras/WiFiManager.template.html index e4dc77f..ecb09de 100644 --- a/extras/WiFiManager.template.html +++ b/extras/WiFiManager.template.html @@ -11,13 +11,14 @@ body.invert, body.invert a, body.invert h1 { - background-color:black; + background-color:#060606; color:white; } body.invert .msg{ - border-top: 1px solid #696969; - border-right: 1px solid #696969; - border-bottom: 1px solid #696969; + background-color: #282828; + border-top: 1px solid #555; + border-right: 1px solid #555; + border-bottom: 1px solid #555; } body.invert .q[role=img] { -webkit-filter: invert(1); @@ -46,7 +47,7 @@ input { button { border: 0; border-radius: .3rem; - background-color: #1fa3ec; + background-color: #9933CC; color: #fff; line-height: 2.4rem; font-size: 1.2rem; @@ -58,7 +59,7 @@ a { text-decoration: none; } a:hover { - color: #1fa3ec; + color: #9933CC; text-decoration: underline; } .h { @@ -123,10 +124,10 @@ a:hover { margin-bottom: 5px; } .msg.P { - border-left-color: #1fa3ec; + border-left-color: #9933CC; } .msg.P h4 { - color: #1fa3ec; + color: #9933CC; } /*.msg.S { border-left-color: #5cb85c; @@ -135,10 +136,10 @@ a:hover { color: #5cb85c; }*/ .msg.D { - border-left-color: #d9534f; + border-left-color: #dc3630; } .msg.D h4 { - color: #d9534f; + color: #dc3630; } dt { @@ -152,7 +153,7 @@ td { vertical-align: top; } button.D{ - background-color:#d9534f; + background-color:#dc3630; } diff --git a/strings_en.h b/strings_en.h index 097d971..2ef052e 100644 --- a/strings_en.h +++ b/strings_en.h @@ -73,15 +73,15 @@ const char HTTP_STYLE[] PROGMEM = ""; From ad623cb586ec73ed92fc28e3087101e76742fec4 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 19 Jul 2018 16:03:14 -0500 Subject: [PATCH 352/424] oops --- strings_en.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strings_en.h b/strings_en.h index 2ef052e..2fd34af 100644 --- a/strings_en.h +++ b/strings_en.h @@ -80,8 +80,8 @@ const char HTTP_STYLE[] PROGMEM = ""; From 24de319c7ecd618bacb65206a85cf678939c2cca Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 19 Jul 2018 16:54:38 -0500 Subject: [PATCH 353/424] issues with captive portals and preloadscan hammering --- WiFiManager.cpp | 10 +++++++--- extras/WiFiManager.template.html | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 39cea64..c051ef0 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -856,7 +856,10 @@ void WiFiManager::handleRoot() { server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); // server->close(); // testing reliability fix for content length mismatches during mutiple flood hits WiFi_scanNetworks(); // preload wifiscan - if(_preloadwifiscan) WiFi_scanNetworks((unsigned)10000); // preload wifiscan throttled + if(_preloadwifiscan) WiFi_scanNetworks((unsigned)20000); // preload wifiscan throttled + // @todo buggy, captive portals make a query on every page load, causing this to run every time in addition to the real page load + // I dont understand why, when you are already in the captive portal, I guess they want to know that its still up and not done or gone + // if we can detect these and ignore them that would be great, since they come from the captive portal redirect maybe there is a refferer } /** @@ -945,11 +948,12 @@ bool WiFiManager::WiFi_scanNetworks(bool force){ // DEBUG_WM("scanNetworks force:",force == true); // DEBUG_WM(_numNetworks,(millis()-_lastscan )); if(force || _numNetworks == 0 || (millis()-_lastscan > 60000)){ + unsigned int _scanstart = millis(); _numNetworks = WiFi.scanNetworks(); _lastscan = millis(); - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan done")); + DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan done"), "in "+(String)(_lastscan - _scanstart)+"ms"); return true; - } else DEBUG_WM(DEBUG_VERBOSE,"Scan is cached"); + } else DEBUG_WM(DEBUG_VERBOSE,"Scan is cached",(String)(millis()-_lastscan )+"ago"); return false; } diff --git a/extras/WiFiManager.template.html b/extras/WiFiManager.template.html index ecb09de..9a0b082 100644 --- a/extras/WiFiManager.template.html +++ b/extras/WiFiManager.template.html @@ -19,6 +19,7 @@ body.invert .msg{ border-top: 1px solid #555; border-right: 1px solid #555; border-bottom: 1px solid #555; + color:#fff; } body.invert .q[role=img] { -webkit-filter: invert(1); From 8d5e9e397728ae63509b6d977b3617bed0510b7c Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 20 Jul 2018 16:16:08 -0500 Subject: [PATCH 354/424] esp32 autoconnect is deprecated https://github.com/espressif/esp-idf/issues/1960 --- WiFiManager.cpp | 5 +++-- WiFiManager.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index c051ef0..72ebaaa 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1338,8 +1338,7 @@ void WiFiManager::handleInfo() { F("dnss"), F("host"), F("stamac"), - F("conx"), - F("autoconx") + F("conx") }; for(size_t i=0; i<23;i++){ @@ -1532,8 +1531,10 @@ String WiFiManager::getInfoData(String id){ p.replace(FPSTR(T_1),WiFi.isConnected() ? FPSTR(S_y) : FPSTR(S_n)); } else if(id==F("autoconx")){ + #ifdef ESP8266 p = FPSTR(HTTP_INFO_autoconx); p.replace(FPSTR(T_1),WiFi.getAutoConnect() ? FPSTR(S_enable) : FPSTR(S_disable)); + #endif } return p; } diff --git a/WiFiManager.h b/WiFiManager.h index 7f63817..49f17fd 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -428,7 +428,7 @@ class WiFiManager } wm_debuglevel_t; boolean _debug = true; - uint8_t _debugLevel = DEBUG_VERBOSE; + uint8_t _debugLevel = DEBUG_DEV; Stream& _debugPort; // debug output stream ref template From cba606b84697615629040ddeb3c1260e600dfd65 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 20 Jul 2018 16:23:38 -0500 Subject: [PATCH 355/424] password invalid better error msg --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 72ebaaa..b3a7deb 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2285,7 +2285,7 @@ boolean WiFiManager::validApPassword(){ if (_apPassword == NULL) _apPassword = ""; if (_apPassword != "") { if (_apPassword.length() < 8 || _apPassword.length() > 63) { - DEBUG_WM(F("AccessPoint set password is INVALID")); + DEBUG_WM(F("AccessPoint set password is INVALID or <8 chars")); _apPassword = ""; return false; // @todo FATAL or fallback to empty ? } From afbad01ee10196edb07c8958c524a3a3095d46e4 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 20 Jul 2018 16:32:43 -0500 Subject: [PATCH 356/424] dev test sketch --- .../OnDemandConfigPortal.ino | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index cdd718c..fcf1b8f 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -12,7 +12,7 @@ void setup() { Serial.setDebugOutput(true); delay(3000); Serial.println("\n Starting"); - + // WiFi.mode(WIFI_STA); // WiFi.printDiag(Serial); // Serial.println(modes[WiFi.getMode()]); @@ -22,12 +22,14 @@ void setup() { //Local intialization. Once its business is done, there is no need to keep it around //reset settings - for testing - //wm.resetSettings(); + // wm.resetSettings(); + // + wm.setClass("invert"); //sets timeout until configuration portal gets turned off //useful to make it all retry or go to sleep //in seconds - wm.setConfigPortalTimeout(60); + // wm.setConfigPortalTimeout(600); wm.setConnectTimeout(10); // wm.setShowStaticFields(true); @@ -43,7 +45,7 @@ void setup() { WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40); WiFiManagerParameter custom_mqtt_port("port", "mqtt port", "", 6); - WiFiManagerParameter custom_token("api_token", "api token", "", 0); + WiFiManagerParameter custom_token("api_token", "api token", "", 16); WiFiManagerParameter custom_tokenb("invalid token", "invalid token", "", 0); //add all your parameters here @@ -79,8 +81,8 @@ void setup() { // const wifi_country_t COUNTRY_JP{"JP",1,14,WIFI_COUNTRY_POLICY_AUTO}; // esp_wifi_set_country(&COUNTRY_US); - wm.setCountry("US"); - + // wm.setCountry("US"); + // wm.setConfigPortalTimeout(120); // wm.startConfigPortal("AutoConnectAP", "password"); @@ -88,7 +90,7 @@ void setup() { //if it does not connect it starts an access point with the specified name //here "AutoConnectAP" //and goes into a blocking loop awaiting configuration - if(!wm.autoConnect("AutoConnectAP","password")) { + if(!wm.autoConnect("AutoConnectAP","123456789")) { Serial.println("failed to connect and hit timeout"); } From 2c41af00f5ac244dca1500fd628736a12365cf5e Mon Sep 17 00:00:00 2001 From: tablatronix Date: Sun, 22 Jul 2018 10:41:50 -0500 Subject: [PATCH 357/424] fixes #671 --- WiFiManager.cpp | 4 +++- strings_en.h | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index b3a7deb..a088478 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2334,9 +2334,9 @@ String WiFiManager::getModeString(uint8_t mode){ return FPSTR(S_NA); } - bool WiFiManager::WiFiSetCountry(){ bool ret = false; + #ifdef ESP32 // @todo check if wifi is init, no idea how, doesnt seem to be exposed if(_wificountry == "") return ret; // skip not set else if(WiFi.getMode() == WIFI_MODE_NULL); // exception if wifi not init! @@ -2347,9 +2347,11 @@ bool WiFiManager::WiFiSetCountry(){ if(ret) DEBUG_WM(DEBUG_VERBOSE,"esp_wifi_set_country: " + _wificountry); else DEBUG_WM(DEBUG_ERROR,"[ERROR] esp_wifi_set_country failed"); + #endif return ret; } + // set mode ignores WiFi.persistent bool WiFiManager::WiFi_Mode(WiFiMode_t m,bool persistent) { bool ret; diff --git a/strings_en.h b/strings_en.h index 2fd34af..09a0e8b 100644 --- a/strings_en.h +++ b/strings_en.h @@ -319,6 +319,8 @@ const char * const AUTH_MODE_NAMES[] PROGMEM const char* const WIFI_MODES[] PROGMEM = { "NULL", "STA", "AP", "STA+AP" }; +#ifdef esp32 const wifi_country_t WM_COUNTRY_US{"US",1,11,WIFI_COUNTRY_POLICY_AUTO}; const wifi_country_t WM_COUNTRY_CN{"CN",1,13,WIFI_COUNTRY_POLICY_AUTO}; -const wifi_country_t WM_COUNTRY_JP{"JP",1,14,WIFI_COUNTRY_POLICY_AUTO}; \ No newline at end of file +const wifi_country_t WM_COUNTRY_JP{"JP",1,14,WIFI_COUNTRY_POLICY_AUTO}; +#endif \ No newline at end of file From e18bc49a2a25c19035c5dbb44217cb8f3b52ac73 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 23 Jul 2018 07:06:22 -0500 Subject: [PATCH 358/424] Wrong case --- strings_en.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strings_en.h b/strings_en.h index 09a0e8b..edbc84e 100644 --- a/strings_en.h +++ b/strings_en.h @@ -319,8 +319,8 @@ const char * const AUTH_MODE_NAMES[] PROGMEM const char* const WIFI_MODES[] PROGMEM = { "NULL", "STA", "AP", "STA+AP" }; -#ifdef esp32 +#ifdef ESP32 const wifi_country_t WM_COUNTRY_US{"US",1,11,WIFI_COUNTRY_POLICY_AUTO}; const wifi_country_t WM_COUNTRY_CN{"CN",1,13,WIFI_COUNTRY_POLICY_AUTO}; const wifi_country_t WM_COUNTRY_JP{"JP",1,14,WIFI_COUNTRY_POLICY_AUTO}; -#endif \ No newline at end of file +#endif From b855c0a4404d0b10dd2b72847f54a69630121ca2 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Sun, 5 Aug 2018 10:48:23 -0500 Subject: [PATCH 359/424] updating library managers --- library.json | 20 ++++++++++++++++---- library.properties | 10 +++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/library.json b/library.json index 99b43c3..0ceb4c8 100644 --- a/library.json +++ b/library.json @@ -1,8 +1,20 @@ { "name": "WifiManager", - "keywords": "wifi, wi-fi", - "description": "ESP8266 WiFi Connection manager with fallback web configuration portal", - "repository": + "keywords": "wifi,wi-fi,esp,esp8266,esp32,espressif8266,espressif32,nodemcu,wemos,arduino", + "description": "WiFi Configuration manager with web configuration portal for ESP boards", +"authors": +[ + { + "name": "tzapu", + "url": "https://github.com/tzapu" + }, + { + "name": "tablatronix", + "url": "https://github.com/tablatronix", + "maintainer": true + } +], +"repository": { "type": "git", "url": "https://github.com/tzapu/WiFiManager.git" @@ -13,5 +25,5 @@ "espressif8266", "espressif32" ], - "version": "0.12" + "version": "1.0.0" } diff --git a/library.properties b/library.properties index 382a56a..5ee6e46 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=WiFiManager -version=0.12 -author=tzapu -maintainer=tzapu -sentence=WiFi Connection manager with fallback web configuration portal for ESP boards -paragraph=Library for configuring ESP8266 modules WiFi credentials at runtime. +version=1.0.0 +author=tzapu,tablatronix +maintainer=tablatronix +sentence=WiFi Configuration manager with web configuration portal for ESP boards +paragraph=Library for configuring ESP8266/ESP32 modules WiFi credentials and custom parameters at runtime. category=Communication url=https://github.com/tzapu/WiFiManager.git architectures=esp8266,esp32 From 573f8113ef9dbae21cd709500b4e1e4046f9e8c3 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 7 Aug 2018 12:48:00 -0500 Subject: [PATCH 360/424] fixes #691 --- WiFiManager.cpp | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index a088478..8393e18 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1272,8 +1272,11 @@ void WiFiManager::handleInfo() { String page = getHTTPHead(FPSTR(S_titleinfo)); // @token titleinfo reportStatus(page); - //@todo convert to enum + int infos = 0; + + //@todo convert to enum or refactor to strings #ifdef ESP8266 + infos = 27; String infoids[] = { F("esphead"), F("uptime"), @@ -1304,28 +1307,18 @@ void WiFiManager::handleInfo() { F("autoconx") }; - for(size_t i=0; i<27;i++){ - if(infoids[i] != NULL) page += getInfoData(infoids[i]); - } - page += F("
"); - #elif defined(ESP32) + infos = 22; String infoids[] = { F("esphead"), F("uptime"), F("chipid"), - F("chiprev"), // esp32 - // "fchipid)", //esp8266 - F("idesize"), //esp8266 - // "flashsize)", //esp8266 + F("chiprev"), + F("idesize"), F("sdkver"), - // "corever)", //esp8266 - // "bootver)", //esp8266 F("cpufreq"), F("freeheap"), - // "memsketch)", //esp8266 - // "memsmeter)", //esp8266 - F("lastreset"), //esp8266 + F("lastreset"), F("wifihead"), F("apip"), F("apmac"), @@ -1340,13 +1333,12 @@ void WiFiManager::handleInfo() { F("stamac"), F("conx") }; - - for(size_t i=0; i<23;i++){ - if(infoids[i] != NULL) page += getInfoData(infoids[i]); - } - page += F("
"); #endif + for(size_t i=0; i"); if(_showInfoErase) page += FPSTR(HTTP_ERASEBTN); page += FPSTR(HTTP_HELP); page += FPSTR(HTTP_END); @@ -1530,12 +1522,12 @@ String WiFiManager::getInfoData(String id){ p = FPSTR(HTTP_INFO_conx); p.replace(FPSTR(T_1),WiFi.isConnected() ? FPSTR(S_y) : FPSTR(S_n)); } + #ifdef ESP8266 else if(id==F("autoconx")){ - #ifdef ESP8266 p = FPSTR(HTTP_INFO_autoconx); p.replace(FPSTR(T_1),WiFi.getAutoConnect() ? FPSTR(S_enable) : FPSTR(S_disable)); - #endif } + #endif return p; } From 5a5f1c631b99129f57a4cf8dd10ec234bbd2c709 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 7 Aug 2018 13:55:14 -0500 Subject: [PATCH 361/424] fix warning --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 8393e18..732fef8 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1272,7 +1272,7 @@ void WiFiManager::handleInfo() { String page = getHTTPHead(FPSTR(S_titleinfo)); // @token titleinfo reportStatus(page); - int infos = 0; + uint16_t infos = 0; //@todo convert to enum or refactor to strings #ifdef ESP8266 From c6ecad1b3a8db814676d7186efa421f01a1cf9fd Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 7 Aug 2018 13:55:45 -0500 Subject: [PATCH 362/424] fixes #678 --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 732fef8..faefd4c 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -25,7 +25,7 @@ uint8_t WiFiManager::_lastconxresulttmp = WL_IDLE_STATUS; WiFiManagerParameter::WiFiManagerParameter(const char *custom) { _id = NULL; _placeholder = NULL; - _length = 0; + _length = 1; _value = NULL; _labelPlacement = WFM_LABEL_BEFORE; _customHTML = custom; @@ -63,7 +63,7 @@ WiFiManagerParameter::~WiFiManagerParameter() { } void WiFiManagerParameter::setValue(const char *defaultValue, int length) { - _length = length; + _length = length; int deflength = strlen(defaultValue); // length actual // use the defult length if it's longer, // @todo consider it might be useful to fail, so user knows they were wrong From 768a965810d5069802cf673c36c7a2d1d307c113 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 7 Aug 2018 13:57:10 -0500 Subject: [PATCH 363/424] remove custom ip from example --- .../AutoConnectWithFSParameters.ino | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/examples/AutoConnect/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino b/examples/AutoConnect/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino index 07c7dd9..41024da 100644 --- a/examples/AutoConnect/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino +++ b/examples/AutoConnect/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino @@ -55,15 +55,15 @@ void setupSpiffs(){ strcpy(mqtt_port, json["mqtt_port"]); strcpy(api_token, json["api_token"]); - if(json["ip"]) { - Serial.println("setting custom ip from config"); - strcpy(static_ip, json["ip"]); - strcpy(static_gw, json["gateway"]); - strcpy(static_sn, json["subnet"]); - Serial.println(static_ip); - } else { - Serial.println("no custom ip in config"); - } + // if(json["ip"]) { + // Serial.println("setting custom ip from config"); + // strcpy(static_ip, json["ip"]); + // strcpy(static_gw, json["gateway"]); + // strcpy(static_sn, json["subnet"]); + // Serial.println(static_ip); + // } else { + // Serial.println("no custom ip in config"); + // } } else { Serial.println("failed to load json config"); @@ -104,11 +104,11 @@ void setup() { wm.addParameter(&custom_api_token); // set static ip - IPAddress _ip,_gw,_sn; - _ip.fromString(static_ip); - _gw.fromString(static_gw); - _sn.fromString(static_sn); - wifiManager.setSTAStaticIPConfig(_ip, _gw, _sn); + // IPAddress _ip,_gw,_sn; + // _ip.fromString(static_ip); + // _gw.fromString(static_gw); + // _sn.fromString(static_sn); + // wm.setSTAStaticIPConfig(_ip, _gw, _sn); //reset settings - wipe credentials for testing //wm.resetSettings(); @@ -125,6 +125,10 @@ void setup() { delay(5000); } + // always start configportal for a little while + wm.setConfigPortalTimeout(60); + wm.startConfigPortal("AutoConnectAP","password"); + //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); @@ -142,9 +146,9 @@ void setup() { json["mqtt_port"] = mqtt_port; json["api_token"] = api_token; - json["ip"] = WiFi.localIP().toString(); - json["gateway"] = WiFi.gatewayIP().toString(); - json["subnet"] = WiFi.subnetMask().toString(); + // json["ip"] = WiFi.localIP().toString(); + // json["gateway"] = WiFi.gatewayIP().toString(); + // json["subnet"] = WiFi.subnetMask().toString(); File configFile = SPIFFS.open("/config.json", "w"); if (!configFile) { From e9c4cdb2c63675ce74dae61c89cc8b0b311fde85 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 7 Aug 2018 14:06:31 -0500 Subject: [PATCH 364/424] disable setvalue on customhtml params --- WiFiManager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index faefd4c..01e9c13 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -63,6 +63,10 @@ WiFiManagerParameter::~WiFiManagerParameter() { } void WiFiManagerParameter::setValue(const char *defaultValue, int length) { + if(!_id){ + // Serial.println("cannot set value of this parameter"); + return; + } _length = length; int deflength = strlen(defaultValue); // length actual // use the defult length if it's longer, From c6027058c906ad8235de6a370888c588d6848383 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 9 Aug 2018 15:21:12 -0500 Subject: [PATCH 365/424] added some debugging and testing --- WiFiManager.cpp | 3 +- .../OnDemandConfigPortal.ino | 131 +++++++++++++++++- 2 files changed, 130 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 01e9c13..330721d 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -627,8 +627,9 @@ boolean WiFiManager::stopConfigPortal(){ if(!ret)DEBUG_WM(DEBUG_ERROR,F("[ERROR] disconnect configportal - softAPdisconnect FAILED")); // WiFi_Mode(_usermode); // restore users wifi mode, BUG https://github.com/esp8266/Arduino/issues/4372 // DEBUG_WM("usermode",_usermode); - // DEBUG_WM(getWLStatusString(WiFi.status())); if(WiFi.status()==WL_IDLE_STATUS) WiFi.reconnect(); // restart wifi since we disconnected it in startconfigportal + DEBUG_WM("wifi status:",getWLStatusString(WiFi.status())); + DEBUG_WM("wifi mode:",getModeString(WiFi.getMode())); configPortalActive = false; return ret; } diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index fcf1b8f..b66f1e7 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -1,3 +1,6 @@ +/** + * This is a kind of unit test for DEV for now + */ #include // https://github.com/tzapu/WiFiManager #define TRIGGER_PIN 0 @@ -5,6 +8,26 @@ const char* modes[] = { "NULL", "STA", "AP", "STA+AP" }; WiFiManager wm; +#include +#include + +char ssid[] = "*************"; // your network SSID (name) +char pass[] = "********"; // your network password + +unsigned int localPort = 2390; // local port to listen for UDP packets + +/* Don't hardwire the IP address or we won't get the benefits of the pool. + * Lookup the IP address for the host name instead */ +//IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server +IPAddress timeServerIP; // time.nist.gov NTP server address +const char* ntpServerName = "time.nist.gov"; +// const char* ntpServerName = "ns1.mtsu.edu"; +const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message +byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// A UDP instance to let us send and receive packets over UDP +WiFiUDP udp; + void setup() { // put your setup code here, to run once: @@ -13,13 +36,20 @@ void setup() { delay(3000); Serial.println("\n Starting"); + Serial.println("Starting UDP"); + udp.begin(localPort); + Serial.print("Local port: "); + Serial.println(udp.localPort()); + // WiFi.mode(WIFI_STA); - // WiFi.printDiag(Serial); + WiFi.printDiag(Serial); // Serial.println(modes[WiFi.getMode()]); //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around // WiFiManager wm; + wm.debugPlatformInfo(); + //Local intialization. Once its business is done, there is no need to keep it around //reset settings - for testing // wm.resetSettings(); @@ -43,17 +73,22 @@ void setup() { // wm.setMenu(menu); + WiFiManagerParameter custom_html("

This Is Custom HTML

"); WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40); WiFiManagerParameter custom_mqtt_port("port", "mqtt port", "", 6); WiFiManagerParameter custom_token("api_token", "api token", "", 16); WiFiManagerParameter custom_tokenb("invalid token", "invalid token", "", 0); //add all your parameters here + wm.addParameter(&custom_html); wm.addParameter(&custom_mqtt_server); wm.addParameter(&custom_mqtt_port); wm.addParameter(&custom_token); wm.addParameter(&custom_tokenb); + custom_html.setValue("test",4); + custom_token.setValue("test",4); + // MENU_WIFI = 0, // MENU_WIFINOSCAN = 1, // MENU_INFO = 2, @@ -83,16 +118,22 @@ void setup() { // wm.setCountry("US"); - // wm.setConfigPortalTimeout(120); + wm.setConfigPortalTimeout(120); // wm.startConfigPortal("AutoConnectAP", "password"); //fetches ssid and pass and tries to connect //if it does not connect it starts an access point with the specified name //here "AutoConnectAP" //and goes into a blocking loop awaiting configuration - if(!wm.autoConnect("AutoConnectAP","123456789")) { + + if(!wm.autoConnect("AutoConnectAP")) { Serial.println("failed to connect and hit timeout"); } + else { + // start configportal always + // wm.setConfigPortalTimeout(60); + // wm.startConfigPortal(); + } pinMode(TRIGGER_PIN, INPUT); } @@ -131,4 +172,88 @@ void loop() { } // put your main code here, to run repeatedly: + getTime(); + delay(10000); } + +// send an NTP request to the time server at the given address +void sendNTPpacket(IPAddress& address) +{ + Serial.println("sending NTP packet..."); + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + udp.beginPacket(address, 123); //NTP requests are to port 123 + udp.write(packetBuffer, NTP_PACKET_SIZE); + udp.endPacket(); +} + +void getTime(){ + //get a random server from the pool + WiFi.hostByName(ntpServerName, timeServerIP); + + sendNTPpacket(timeServerIP); // send an NTP packet to a time server + // wait to see if a reply is available + delay(1000); + + int cb = udp.parsePacket(); + if (!cb) { + Serial.println("no packet yet"); + } + else { + Serial.print("packet received, length="); + Serial.println(cb); + // We've received a packet, read the data from it + udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + //the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, esxtract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + Serial.print("Seconds since Jan 1 1900 = " ); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if ( ((epoch % 3600) / 60) < 10 ) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ( (epoch % 60) < 10 ) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second + } +} \ No newline at end of file From 4cceb95a42e626b8d2f0b96cb27ab67735b984c8 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 10 Aug 2018 11:42:09 -0500 Subject: [PATCH 366/424] debugging --- WiFiManager.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 330721d..fac7af1 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -612,8 +612,10 @@ boolean WiFiManager::stopConfigPortal(){ // @todo what is the proper way to shutdown and free the server up server->stop(); server.reset(); + // dnsServer->stop(); // free heap ? dnsServer.reset(); + if(!configPortalActive) return false; // turn off AP @@ -625,8 +627,9 @@ boolean WiFiManager::stopConfigPortal(){ bool ret = false; ret = WiFi.softAPdisconnect(false); if(!ret)DEBUG_WM(DEBUG_ERROR,F("[ERROR] disconnect configportal - softAPdisconnect FAILED")); - // WiFi_Mode(_usermode); // restore users wifi mode, BUG https://github.com/esp8266/Arduino/issues/4372 - // DEBUG_WM("usermode",_usermode); + delay(1000); + DEBUG_WM("restoring usermode",getModeString(_usermode)); + 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 DEBUG_WM("wifi status:",getWLStatusString(WiFi.status())); DEBUG_WM("wifi mode:",getModeString(WiFi.getMode())); From 5ee1ae78c0fc808ad5eacec398d19a658ec35aa3 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 10 Aug 2018 11:45:25 -0500 Subject: [PATCH 367/424] fix callback order --- WiFiManager.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index fac7af1..90a7970 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -304,6 +304,11 @@ bool WiFiManager::startAP(){ bool ret = true; DEBUG_WM(F("StartAP with SSID: "),_apName); + // do AP callback if set + if ( _apcallback != NULL) { + _apcallback(this); + } + // setup optional soft AP static ip config if (_ap_static_ip) { DEBUG_WM(F("Custom AP IP/GW/Subnet:")); @@ -347,11 +352,6 @@ bool WiFiManager::startAP(){ } #endif - // do AP callback if set - if ( _apcallback != NULL) { - _apcallback(this); - } - return ret; } From 792ed84f4bac9df822294b16097db097d1b1b77d Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 10 Aug 2018 11:51:31 -0500 Subject: [PATCH 368/424] debugging --- WiFiManager.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 90a7970..60631b1 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -308,7 +308,7 @@ bool WiFiManager::startAP(){ if ( _apcallback != NULL) { _apcallback(this); } - + // setup optional soft AP static ip config if (_ap_static_ip) { DEBUG_WM(F("Custom AP IP/GW/Subnet:")); @@ -628,11 +628,14 @@ boolean WiFiManager::stopConfigPortal(){ ret = WiFi.softAPdisconnect(false); if(!ret)DEBUG_WM(DEBUG_ERROR,F("[ERROR] disconnect configportal - softAPdisconnect FAILED")); delay(1000); - DEBUG_WM("restoring usermode",getModeString(_usermode)); + DEBUG_WM(DEBUG_VERBOSE,"restoring usermode",getModeString(_usermode)); 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 - DEBUG_WM("wifi status:",getWLStatusString(WiFi.status())); - DEBUG_WM("wifi mode:",getModeString(WiFi.getMode())); + if(WiFi.status()==WL_IDLE_STATUS){ + WiFi.reconnect(); // restart wifi since we disconnected it in startconfigportal + DEBUG_WM(DEBUG_VERBOSE,"WiFi Reconnect, was idle"); + } + DEBUG_WM(DEBUG_VERBOSE,"wifi status:",getWLStatusString(WiFi.status())); + DEBUG_WM(DEBUG_VERBOSE,"wifi mode:",getModeString(WiFi.getMode())); configPortalActive = false; return ret; } From 915023ccb95054d1f0e126823aff0f9df80b94e7 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 10 Aug 2018 13:49:15 -0500 Subject: [PATCH 369/424] fixes #619 unconfirmed needed --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 60631b1..9f66fcd 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -612,7 +612,7 @@ boolean WiFiManager::stopConfigPortal(){ // @todo what is the proper way to shutdown and free the server up server->stop(); server.reset(); - // dnsServer->stop(); // free heap ? + dnsServer->stop(); // free heap ? dnsServer.reset(); From f1a1f44a086c62af3121aa932f163526ae36e929 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Wed, 15 Aug 2018 19:11:53 -0500 Subject: [PATCH 370/424] #700 --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 9f66fcd..d04c109 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -615,7 +615,6 @@ boolean WiFiManager::stopConfigPortal(){ dnsServer->stop(); // free heap ? dnsServer.reset(); - if(!configPortalActive) return false; // turn off AP @@ -637,6 +636,7 @@ boolean WiFiManager::stopConfigPortal(){ DEBUG_WM(DEBUG_VERBOSE,"wifi status:",getWLStatusString(WiFi.status())); DEBUG_WM(DEBUG_VERBOSE,"wifi mode:",getModeString(WiFi.getMode())); configPortalActive = false; + _end() return ret; } From 1b8ce615220bffa05b15738f5cd07c1c13dbf7bf Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 17 Aug 2018 19:38:53 -0500 Subject: [PATCH 371/424] well shit --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index d04c109..16f85ac 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -636,7 +636,7 @@ boolean WiFiManager::stopConfigPortal(){ DEBUG_WM(DEBUG_VERBOSE,"wifi status:",getWLStatusString(WiFi.status())); DEBUG_WM(DEBUG_VERBOSE,"wifi mode:",getModeString(WiFi.getMode())); configPortalActive = false; - _end() + _end(); return ret; } From 2074d85da740b798e3ac8d4495df2929b62e7059 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 23 Aug 2018 12:54:48 -0500 Subject: [PATCH 372/424] cleanconnect --- WiFiManager.cpp | 2 +- WiFiManager.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 16f85ac..806da56 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -652,7 +652,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) { //@todo catch failures in set_config // make sure sta is on before `begin` so it does not call enablesta->mode while persistent is ON ( which would save WM AP state to eeprom !) - WiFi_Disconnect(); // disconnect before begin, in case anything is hung, this causes a 2 seconds delay for connect + if(cleanConnect) WiFi_Disconnect(); // disconnect before begin, in case anything is hung, this causes a 2 seconds delay for connect // if ssid argument provided connect to that if (ssid != "") { diff --git a/WiFiManager.h b/WiFiManager.h index 49f17fd..bb0de74 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -283,6 +283,7 @@ class WiFiManager int _numNetworks = 0; unsigned long _lastscan = 0; // ms int _cpclosedelay = 2000; // delay before wifisave, prevents captive portal from closing to fast. + bool _cleanConnect = true; // disconnect before connect in connectwifi, increases stability on connects #ifdef ESP32 static uint8_t _lastconxresulttmp; // tmp var for esp32 callback From 8f03b5df10d9bc026d61d8d7d29529053cef1abf Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 23 Aug 2018 13:35:07 -0500 Subject: [PATCH 373/424] testing sta ap modes --- WiFiManager.cpp | 13 +++++++------ WiFiManager.h | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 806da56..085c970 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -328,10 +328,12 @@ bool WiFiManager::startAP(){ // start soft AP with password or anonymous if (_apPassword != "") { - ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str());//password option + if(_channelSync) ret = WiFi.softAxP(_apName.c_str(), _apPassword.c_str(),WiFi.channel()); + else ret = WiFi.softAxP(_apName.c_str(), _apPassword.c_str());//password option } else { DEBUG_WM(DEBUG_VERBOSE,F("AP has anonymous access!")); - ret = WiFi.softAP(_apName.c_str()); + if(_channelSync) ret = WiFi.softAP(_apName.c_str(),"",WiFi.channel()); + else ret = WiFi.softAP(_apName.c_str()); } if(_debugLevel > DEBUG_DEV) debugSoftAPConfig(); @@ -465,11 +467,9 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo if(_apName == "") _apName = _wifissidprefix + "_" + String(WIFI_getChipId()); if(!validApPassword()) return false; - bool disableSTA = false; // debug, always disable sta - // HANDLE issues with STA connections, shutdown sta if not connected, or else this will hang channel scanning and softap will not respond // @todo sometimes still cannot connect to AP for no known reason, no events in log either - if(!WiFi.isConnected() || disableSTA){ + if(_disableSTA || (!WiFi.isConnected() && _disableSTAConn)){ // this fixes most ap problems, however, simply doing mode(WIFI_AP) does not work if sta connection is hanging, must `wifi_station_disconnect` WiFi_Disconnect(); WiFi_enableSTA(false); @@ -652,7 +652,8 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) { //@todo catch failures in set_config // make sure sta is on before `begin` so it does not call enablesta->mode while persistent is ON ( which would save WM AP state to eeprom !) - if(cleanConnect) WiFi_Disconnect(); // disconnect before begin, in case anything is hung, this causes a 2 seconds delay for connect + if(_cleanConnect) WiFi_Disconnect(); // disconnect before begin, in case anything is hung, this causes a 2 seconds delay for connect + // @todo find out what status is when this is needed, can we detect it and handle it, say in between states or idle_status // if ssid argument provided connect to that if (ssid != "") { diff --git a/WiFiManager.h b/WiFiManager.h index bb0de74..d56225d 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -284,6 +284,9 @@ class WiFiManager unsigned long _lastscan = 0; // ms int _cpclosedelay = 2000; // delay before wifisave, prevents captive portal from closing to fast. bool _cleanConnect = true; // disconnect before connect in connectwifi, increases stability on connects + bool _disableSTA = false; // disable sta when starting ap, always + bool _disableSTAConn = true; // disable sta when starting ap, if sta is not connected ( stability ) + bool _channelSync = false; // use wifi channel when starting ap #ifdef ESP32 static uint8_t _lastconxresulttmp; // tmp var for esp32 callback From 3123eac5c8572be3bc81ba97baab0dea025a2294 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 23 Aug 2018 13:36:08 -0500 Subject: [PATCH 374/424] typo --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 085c970..3f94fb9 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -328,8 +328,8 @@ bool WiFiManager::startAP(){ // start soft AP with password or anonymous if (_apPassword != "") { - if(_channelSync) ret = WiFi.softAxP(_apName.c_str(), _apPassword.c_str(),WiFi.channel()); - else ret = WiFi.softAxP(_apName.c_str(), _apPassword.c_str());//password option + if(_channelSync) ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(),WiFi.channel()); + else ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str());//password option } else { DEBUG_WM(DEBUG_VERBOSE,F("AP has anonymous access!")); if(_channelSync) ret = WiFi.softAP(_apName.c_str(),"",WiFi.channel()); From c651ab4b62d2e87c89faaf28008069e23af1307f Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 23 Aug 2018 13:46:13 -0500 Subject: [PATCH 375/424] cleanup --- WiFiManager.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 3f94fb9..2c0d9ac 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -326,20 +326,32 @@ bool WiFiManager::startAP(){ delay(500); // workaround delay #endif + if(_channelSync){ + DEBUG_WM(DEBUG_VERBOSE,"Starting AP on channel:",WiFi.channel()); + } + // start soft AP with password or anonymous if (_apPassword != "") { - if(_channelSync) ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(),WiFi.channel()); - else ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str());//password option + if(_channelSync){ + ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(),WiFi.channel()); + } + else{ + ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str());//password option + } } else { DEBUG_WM(DEBUG_VERBOSE,F("AP has anonymous access!")); - if(_channelSync) ret = WiFi.softAP(_apName.c_str(),"",WiFi.channel()); - else ret = WiFi.softAP(_apName.c_str()); + if(_channelSync){ + ret = WiFi.softAP(_apName.c_str(),"",WiFi.channel()); + } + else{ + ret = WiFi.softAP(_apName.c_str()); + } } if(_debugLevel > DEBUG_DEV) debugSoftAPConfig(); if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] There was a problem starting the AP"); - // @tood add softAP retry here + // @todo add softAP retry here delay(500); // slight delay to make sure we get an AP IP DEBUG_WM(F("AP IP address:"),WiFi.softAPIP()); From 51432d0ef7787db12a15d0788cd32df3caad7496 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 23 Aug 2018 15:04:31 -0500 Subject: [PATCH 376/424] remove tests from example --- WiFiManager.h | 1 + .../AutoConnectWithFSParameters.ino | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/WiFiManager.h b/WiFiManager.h index d56225d..04776a3 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -284,6 +284,7 @@ class WiFiManager unsigned long _lastscan = 0; // ms int _cpclosedelay = 2000; // delay before wifisave, prevents captive portal from closing to fast. bool _cleanConnect = true; // disconnect before connect in connectwifi, increases stability on connects + bool _disableSTA = false; // disable sta when starting ap, always bool _disableSTAConn = true; // disable sta when starting ap, if sta is not connected ( stability ) bool _channelSync = false; // use wifi channel when starting ap diff --git a/examples/AutoConnect/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino b/examples/AutoConnect/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino index 41024da..fea3287 100644 --- a/examples/AutoConnect/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino +++ b/examples/AutoConnect/AutoConnectWithFSParameters/AutoConnectWithFSParameters.ino @@ -126,8 +126,8 @@ void setup() { } // always start configportal for a little while - wm.setConfigPortalTimeout(60); - wm.startConfigPortal("AutoConnectAP","password"); + // wm.setConfigPortalTimeout(60); + // wm.startConfigPortal("AutoConnectAP","password"); //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); From 28cf8eed16e617bf74be58a15b721ac7e17d1e30 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 23 Aug 2018 16:46:17 -0500 Subject: [PATCH 377/424] adding async scannetworks --- WiFiManager.cpp | 40 +++++++++++++++++++++++++++++++++++----- WiFiManager.h | 4 +++- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 2c0d9ac..6d96943 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -627,6 +627,8 @@ boolean WiFiManager::stopConfigPortal(){ dnsServer->stop(); // free heap ? dnsServer.reset(); + WiFi.scanDelete(); // free wifi scan results + if(!configPortalActive) return false; // turn off AP @@ -880,7 +882,7 @@ void WiFiManager::handleRoot() { server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); // server->close(); // testing reliability fix for content length mismatches during mutiple flood hits WiFi_scanNetworks(); // preload wifiscan - if(_preloadwifiscan) WiFi_scanNetworks((unsigned)20000); // preload wifiscan throttled + if(_preloadwifiscan) WiFi_scanNetworks((unsigned)20000,true); // preload wifiscan throttled // @todo buggy, captive portals make a query on every page load, causing this to run every time in addition to the real page load // I dont understand why, when you are already in the captive portal, I guess they want to know that its still up and not done or gone // if we can detect these and ignore them that would be great, since they come from the captive portal redirect maybe there is a refferer @@ -962,18 +964,46 @@ String WiFiManager::getMenuOut(){ return page; } +// // is it possible in softap mode to detect aps without scanning +// bool WiFiManager::WiFi_scanNetworksForAP(bool force){ +// WiFi_scanNetworks(force); +// } + +void WiFiManager::WiFi_scanComplete(int networksFound){ + DEBUG_WM(DEBUG_VERBOSE,F("ASYNC WiFi Scan done")); + _numNetworks = networksFound; + _lastscan = millis(); +} + bool WiFiManager::WiFi_scanNetworks(){ - return WiFi_scanNetworks(false); + return WiFi_scanNetworks(false,false); +} + +bool WiFiManager::WiFi_scanNetworks(unsigned int cachetime,bool async){ + return WiFi_scanNetworks(millis()-_lastscan > cachetime,async); } bool WiFiManager::WiFi_scanNetworks(unsigned int cachetime){ - return WiFi_scanNetworks(millis()-_lastscan > cachetime); + return WiFi_scanNetworks(millis()-_lastscan > cachetime,false); } -bool WiFiManager::WiFi_scanNetworks(bool force){ +bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ // DEBUG_WM("scanNetworks force:",force == true); // DEBUG_WM(_numNetworks,(millis()-_lastscan )); if(force || _numNetworks == 0 || (millis()-_lastscan > 60000)){ unsigned int _scanstart = millis(); - _numNetworks = WiFi.scanNetworks(); + int8_t res; + // if(async) res = WiFi.scanNetworksAsync(&WiFiManager::WiFi_scanComplete); + // else + res = WiFi.scanNetworks(); + if(res == WIFI_SCAN_FAILED) DEBUG_WM(DEBUG_ERROR,"[ERROR] scan failed"); + else if(res == WIFI_SCAN_RUNNING){ + DEBUG_WM(DEBUG_ERROR,"[ERROR] scan waiting"); + while(WiFi.scanComplete() == WIFI_SCAN_RUNNING){ + DEBUG_WM(DEBUG_ERROR,"."); + delay(100); + } + _numNetworks = WiFi.scanComplete(); + } + else if(res >=0 ) _numNetworks = res; _lastscan = millis(); DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan done"), "in "+(String)(_lastscan - _scanstart)+"ms"); return true; diff --git a/WiFiManager.h b/WiFiManager.h index 04776a3..0d243a3 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -383,8 +383,10 @@ class WiFiManager void WiFi_autoReconnect(); String WiFi_SSID(); bool WiFi_scanNetworks(); - bool WiFi_scanNetworks(bool force); + bool WiFi_scanNetworks(bool force,bool async); + bool WiFi_scanNetworks(unsigned int cachetime,bool async); bool WiFi_scanNetworks(unsigned int cachetime); + void WiFi_scanComplete(int networksFound); bool WiFiSetCountry(); #ifdef ESP32 From 34b7d1ea032a5dd3ae1ecf02a574db4ac29111ac Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 24 Aug 2018 12:19:26 -0500 Subject: [PATCH 378/424] scan preload async This changes the preload wifiscan to async and adds async support for wifi scans. preload async occursd on cp stsart and root loads(throttled) --- WiFiManager.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 6d96943..e2871fc 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -337,7 +337,7 @@ bool WiFiManager::startAP(){ } else{ ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str());//password option - } + } } else { DEBUG_WM(DEBUG_VERBOSE,F("AP has anonymous access!")); if(_channelSync){ @@ -454,7 +454,7 @@ void WiFiManager::setupConfigPortal() { server->begin(); // Web server start DEBUG_WM(DEBUG_VERBOSE,F("HTTP server started")); - if(_preloadwifiscan) WiFi_scanNetworks(); // preload wifiscan + if(_preloadwifiscan) WiFi_scanNetworks(true,true); // preload wifiscan } boolean WiFiManager::startConfigPortal() { @@ -896,7 +896,8 @@ void WiFiManager::handleWifi(boolean scan) { handleRequest(); String page = getHTTPHead(FPSTR(S_titlewifi)); // @token titlewifi if (scan) { - WiFi_scanNetworks(server->hasArg(F("refresh"))); //wifiscan, force if arg refresh + DEBUG_WM(DEBUG_DEV,"refresh flag:",server->hasArg(F("refresh"))); + WiFi_scanNetworks(server->hasArg(F("refresh")),false); //wifiscan, force if arg refresh page += getScanItemOut(); } String pitem = ""; @@ -986,20 +987,27 @@ bool WiFiManager::WiFi_scanNetworks(unsigned int cachetime){ return WiFi_scanNetworks(millis()-_lastscan > cachetime,false); } bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ - // DEBUG_WM("scanNetworks force:",force == true); - // DEBUG_WM(_numNetworks,(millis()-_lastscan )); + // DEBUG_WM(DEBUG_DEV,"scanNetworks async:",async == true); + // DEBUG_WM(DEBUG_DEV,_numNetworks,(millis()-_lastscan )); + // DEBUG_WM(DEBUG_DEV,"scanNetworks force:",force == true); if(force || _numNetworks == 0 || (millis()-_lastscan > 60000)){ unsigned int _scanstart = millis(); - int8_t res; - // if(async) res = WiFi.scanNetworksAsync(&WiFiManager::WiFi_scanComplete); - // else - res = WiFi.scanNetworks(); + if(async){ + using namespace std::placeholders; // for `_1` + WiFi.scanNetworksAsync(std::bind(&WiFiManager::WiFi_scanComplete,this,_1)); + DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); + return false; + } + else{ + int8_t res; + res = WiFi.scanNetworks(); + } if(res == WIFI_SCAN_FAILED) DEBUG_WM(DEBUG_ERROR,"[ERROR] scan failed"); else if(res == WIFI_SCAN_RUNNING){ DEBUG_WM(DEBUG_ERROR,"[ERROR] scan waiting"); while(WiFi.scanComplete() == WIFI_SCAN_RUNNING){ DEBUG_WM(DEBUG_ERROR,"."); - delay(100); + delay(100); } _numNetworks = WiFi.scanComplete(); } @@ -1007,7 +1015,7 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ _lastscan = millis(); DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan done"), "in "+(String)(_lastscan - _scanstart)+"ms"); return true; - } else DEBUG_WM(DEBUG_VERBOSE,"Scan is cached",(String)(millis()-_lastscan )+"ago"); + } else DEBUG_WM(DEBUG_VERBOSE,"Scan is cached",(String)(millis()-_lastscan )+"ms ago"); return false; } From f2bbb5f4e24281d6fdacd82c9e5b0f2fe9eeb46c Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 24 Aug 2018 12:21:20 -0500 Subject: [PATCH 379/424] comments --- WiFiManager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index e2871fc..e131fd8 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -454,7 +454,7 @@ void WiFiManager::setupConfigPortal() { server->begin(); // Web server start DEBUG_WM(DEBUG_VERBOSE,F("HTTP server started")); - if(_preloadwifiscan) WiFi_scanNetworks(true,true); // preload wifiscan + if(_preloadwifiscan) WiFi_scanNetworks(true,true); // preload wifiscan , async } boolean WiFiManager::startConfigPortal() { @@ -882,7 +882,7 @@ void WiFiManager::handleRoot() { server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); // server->close(); // testing reliability fix for content length mismatches during mutiple flood hits WiFi_scanNetworks(); // preload wifiscan - if(_preloadwifiscan) WiFi_scanNetworks((unsigned)20000,true); // preload wifiscan throttled + if(_preloadwifiscan) WiFi_scanNetworks((unsigned)20000,true); // preload wifiscan throttled, async // @todo buggy, captive portals make a query on every page load, causing this to run every time in addition to the real page load // I dont understand why, when you are already in the captive portal, I guess they want to know that its still up and not done or gone // if we can detect these and ignore them that would be great, since they come from the captive portal redirect maybe there is a refferer @@ -896,7 +896,7 @@ void WiFiManager::handleWifi(boolean scan) { handleRequest(); String page = getHTTPHead(FPSTR(S_titlewifi)); // @token titlewifi if (scan) { - DEBUG_WM(DEBUG_DEV,"refresh flag:",server->hasArg(F("refresh"))); + // DEBUG_WM(DEBUG_DEV,"refresh flag:",server->hasArg(F("refresh"))); WiFi_scanNetworks(server->hasArg(F("refresh")),false); //wifiscan, force if arg refresh page += getScanItemOut(); } From 4f5e21647ff29c91e8044f42628562ffcc140598 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 24 Aug 2018 13:02:34 -0500 Subject: [PATCH 380/424] fix res error --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index e131fd8..4632adb 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -991,6 +991,7 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ // DEBUG_WM(DEBUG_DEV,_numNetworks,(millis()-_lastscan )); // DEBUG_WM(DEBUG_DEV,"scanNetworks force:",force == true); if(force || _numNetworks == 0 || (millis()-_lastscan > 60000)){ + int8_t res; unsigned int _scanstart = millis(); if(async){ using namespace std::placeholders; // for `_1` @@ -999,7 +1000,6 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ return false; } else{ - int8_t res; res = WiFi.scanNetworks(); } if(res == WIFI_SCAN_FAILED) DEBUG_WM(DEBUG_ERROR,"[ERROR] scan failed"); From 1bf3fc04eacc79ac1aed6090e4f37cce6fc7aea8 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 24 Aug 2018 13:37:15 -0500 Subject: [PATCH 381/424] fixes #707 --- WiFiManager.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 4632adb..f473450 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -201,7 +201,7 @@ void WiFiManager::_end(){ // AUTOCONNECT boolean WiFiManager::autoConnect() { - String ssid = _wifissidprefix + "_" + String(WIFI_getChipId()); + String ssid = _wifissidprefix + "_" + String(WIFI_getChipId(),HEX); return autoConnect(ssid.c_str(), NULL); } @@ -458,7 +458,7 @@ void WiFiManager::setupConfigPortal() { } boolean WiFiManager::startConfigPortal() { - String ssid = _wifissidprefix + "_" + String(WIFI_getChipId()); + String ssid = _wifissidprefix + "_" + String(WIFI_getChipId(),HEX); return startConfigPortal(ssid.c_str(), NULL); } @@ -476,7 +476,7 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo _apName = apName; // @todo check valid apname ? _apPassword = apPassword; - if(_apName == "") _apName = _wifissidprefix + "_" + String(WIFI_getChipId()); + if(_apName == "") _apName = _wifissidprefix + "_" + String(WIFI_getChipId(),HEX); if(!validApPassword()) return false; // HANDLE issues with STA connections, shutdown sta if not connected, or else this will hang channel scanning and softap will not respond @@ -1425,7 +1425,7 @@ String WiFiManager::getInfoData(String id){ } else if(id==F("chipid")){ p = FPSTR(HTTP_INFO_chipid); - p.replace(FPSTR(T_1),(String)WIFI_getChipId()); + p.replace(FPSTR(T_1),String(WIFI_getChipId(),HEX)); } #ifdef ESP32 else if(id==F("chiprev")){ @@ -1817,6 +1817,7 @@ bool WiFiManager::erase(bool opt){ /** * [resetSettings description] + * ERASES STA CREDENTIALS * @access public */ void WiFiManager::resetSettings() { From b963e7f95a544c84172951485858fbf70b34eda1 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Sat, 25 Aug 2018 14:55:51 -0500 Subject: [PATCH 382/424] fix esp32 fatal, disabled async --- WiFiManager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index f473450..a2fcde3 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -994,10 +994,14 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ int8_t res; unsigned int _scanstart = millis(); if(async){ + #ifdef ESP8266 using namespace std::placeholders; // for `_1` WiFi.scanNetworksAsync(std::bind(&WiFiManager::WiFi_scanComplete,this,_1)); DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); return false; + #else + res = WiFi.scanNetworks(); + #endif } else{ res = WiFi.scanNetworks(); From 16c37e5389923c8d5232884f0c0ef27482bb6a27 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 27 Aug 2018 12:16:14 -0500 Subject: [PATCH 383/424] remove npt example, not esp32 compat --- .../OnDemandConfigPortal.ino | 107 +----------------- 1 file changed, 1 insertion(+), 106 deletions(-) diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index b66f1e7..e72c921 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -8,26 +8,9 @@ const char* modes[] = { "NULL", "STA", "AP", "STA+AP" }; WiFiManager wm; -#include -#include - char ssid[] = "*************"; // your network SSID (name) char pass[] = "********"; // your network password -unsigned int localPort = 2390; // local port to listen for UDP packets - -/* Don't hardwire the IP address or we won't get the benefits of the pool. - * Lookup the IP address for the host name instead */ -//IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server -IPAddress timeServerIP; // time.nist.gov NTP server address -const char* ntpServerName = "time.nist.gov"; -// const char* ntpServerName = "ns1.mtsu.edu"; -const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message -byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets - -// A UDP instance to let us send and receive packets over UDP -WiFiUDP udp; - void setup() { // put your setup code here, to run once: @@ -36,13 +19,8 @@ void setup() { delay(3000); Serial.println("\n Starting"); - Serial.println("Starting UDP"); - udp.begin(localPort); - Serial.print("Local port: "); - Serial.println(udp.localPort()); - // WiFi.mode(WIFI_STA); - WiFi.printDiag(Serial); + // WiFi.printDiag(Serial); // Serial.println(modes[WiFi.getMode()]); //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around @@ -172,88 +150,5 @@ void loop() { } // put your main code here, to run repeatedly: - getTime(); delay(10000); } - -// send an NTP request to the time server at the given address -void sendNTPpacket(IPAddress& address) -{ - Serial.println("sending NTP packet..."); - // set all bytes in the buffer to 0 - memset(packetBuffer, 0, NTP_PACKET_SIZE); - // Initialize values needed to form NTP request - // (see URL above for details on the packets) - packetBuffer[0] = 0b11100011; // LI, Version, Mode - packetBuffer[1] = 0; // Stratum, or type of clock - packetBuffer[2] = 6; // Polling Interval - packetBuffer[3] = 0xEC; // Peer Clock Precision - // 8 bytes of zero for Root Delay & Root Dispersion - packetBuffer[12] = 49; - packetBuffer[13] = 0x4E; - packetBuffer[14] = 49; - packetBuffer[15] = 52; - - // all NTP fields have been given values, now - // you can send a packet requesting a timestamp: - udp.beginPacket(address, 123); //NTP requests are to port 123 - udp.write(packetBuffer, NTP_PACKET_SIZE); - udp.endPacket(); -} - -void getTime(){ - //get a random server from the pool - WiFi.hostByName(ntpServerName, timeServerIP); - - sendNTPpacket(timeServerIP); // send an NTP packet to a time server - // wait to see if a reply is available - delay(1000); - - int cb = udp.parsePacket(); - if (!cb) { - Serial.println("no packet yet"); - } - else { - Serial.print("packet received, length="); - Serial.println(cb); - // We've received a packet, read the data from it - udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer - - //the timestamp starts at byte 40 of the received packet and is four bytes, - // or two words, long. First, esxtract the two words: - - unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); - unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); - // combine the four bytes (two words) into a long integer - // this is NTP time (seconds since Jan 1 1900): - unsigned long secsSince1900 = highWord << 16 | lowWord; - Serial.print("Seconds since Jan 1 1900 = " ); - Serial.println(secsSince1900); - - // now convert NTP time into everyday time: - Serial.print("Unix time = "); - // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: - const unsigned long seventyYears = 2208988800UL; - // subtract seventy years: - unsigned long epoch = secsSince1900 - seventyYears; - // print Unix time: - Serial.println(epoch); - - - // print the hour, minute and second: - Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) - Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) - Serial.print(':'); - if ( ((epoch % 3600) / 60) < 10 ) { - // In the first 10 minutes of each hour, we'll want a leading '0' - Serial.print('0'); - } - Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) - Serial.print(':'); - if ( (epoch % 60) < 10 ) { - // In the first 10 seconds of each minute, we'll want a leading '0' - Serial.print('0'); - } - Serial.println(epoch % 60); // print the second - } -} \ No newline at end of file From 85d7f2a549890bcf2c06cd0cd2bf7a38fc3fc8b9 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 27 Aug 2018 12:17:37 -0500 Subject: [PATCH 384/424] esp32 fix event cb to std::bind, adds async preload esp32 does not have scan cb, must use event system and oncomplete to get scan count --- WiFiManager.cpp | 32 ++++++++++++++++++-------------- WiFiManager.h | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index a2fcde3..4d4687a 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -971,8 +971,8 @@ String WiFiManager::getMenuOut(){ // } void WiFiManager::WiFi_scanComplete(int networksFound){ - DEBUG_WM(DEBUG_VERBOSE,F("ASYNC WiFi Scan done")); _numNetworks = networksFound; + DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC completed, found:"),_numNetworks); _lastscan = millis(); } @@ -994,14 +994,14 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ int8_t res; unsigned int _scanstart = millis(); if(async){ + DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); #ifdef ESP8266 using namespace std::placeholders; // for `_1` WiFi.scanNetworksAsync(std::bind(&WiFiManager::WiFi_scanComplete,this,_1)); - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); - return false; #else - res = WiFi.scanNetworks(); + res = WiFi.scanNetworks(true); #endif + return false; } else{ res = WiFi.scanNetworks(); @@ -1017,9 +1017,9 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ } else if(res >=0 ) _numNetworks = res; _lastscan = millis(); - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan done"), "in "+(String)(_lastscan - _scanstart)+"ms"); + DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan done"), "in "+(String)(_lastscan - _scanstart)+" ms"); return true; - } else DEBUG_WM(DEBUG_VERBOSE,"Scan is cached",(String)(millis()-_lastscan )+"ms ago"); + } else DEBUG_WM(DEBUG_VERBOSE,"Scan is cached",(String)(millis()-_lastscan )+" ms ago"); return false; } @@ -2536,19 +2536,22 @@ String WiFiManager::WiFi_SSID(){ #ifdef ESP32 void WiFiManager::WiFiEvent(WiFiEvent_t event,system_event_info_t info){ - // WiFiManager _WiFiManager; - // Serial.print("WM: EVENT: ");Serial.println(event); + DEBUG_WM(DEBUG_VERBOSE,"[EVENT]",event); if(event == SYSTEM_EVENT_STA_DISCONNECTED){ - // Serial.print("WM: EVENT: WIFI_REASON: ");Serial.println(info.disconnected.reason); + DEBUG_WM(DEBUG_VERBOSE,"[EVENT] WIFI_REASON:",info.disconnected.reason); if(info.disconnected.reason == WIFI_REASON_AUTH_EXPIRE || info.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(); - // if(info.disconnected.reason == WIFI_REASON_NO_AP_FOUND) Serial.println("*WM: EVENT: WIFI_REASON: NO_AP_FOUND"); - // Serial.println("*WM: Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); + if(info.disconnected.reason == WIFI_REASON_NO_AP_FOUND) DEBUG_WM(DEBUG_VERBOSE,"[EVENT] WIFI_REASON: NO_AP_FOUND"); #ifdef esp32autoreconnect + DEBUG_WM(DEBUG_VERBOSE,"[Event] SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); WiFi.reconnect(); #endif } + else if(event == SYSTEM_EVENT_SCAN_DONE){ + uint16_t scans = WiFi.scanComplete(); + WiFi_scanComplete(scans); + } } #endif @@ -2556,9 +2559,10 @@ void WiFiManager::WiFi_autoReconnect(){ #ifdef ESP8266 WiFi.setAutoReconnect(_wifiAutoReconnect); #elif defined(ESP32) - if(_wifiAutoReconnect){ + // if(_wifiAutoReconnect){ DEBUG_WM(DEBUG_VERBOSE,"ESP32 event handler enabled"); - WiFi.onEvent(WiFiEvent); - } + using namespace std::placeholders; + WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2)); + // } #endif } diff --git a/WiFiManager.h b/WiFiManager.h index 0d243a3..c70ae27 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -390,7 +390,7 @@ class WiFiManager bool WiFiSetCountry(); #ifdef ESP32 - static void WiFiEvent(WiFiEvent_t event, system_event_info_t info); + void WiFiEvent(WiFiEvent_t event, system_event_info_t info); #endif // output helpers From c78b76ba2e3d00328becc0db185a47838f59231a Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 27 Aug 2018 12:30:28 -0500 Subject: [PATCH 385/424] scan timing debugging --- WiFiManager.cpp | 9 +++++---- WiFiManager.h | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 4d4687a..3c80bc2 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -971,9 +971,10 @@ String WiFiManager::getMenuOut(){ // } void WiFiManager::WiFi_scanComplete(int networksFound){ - _numNetworks = networksFound; - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC completed, found:"),_numNetworks); _lastscan = millis(); + _numNetworks = networksFound; + DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan completed"), "in "+(String)(_lastscan - _startscan)+" ms"); + DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan found:"),_numNetworks); } bool WiFiManager::WiFi_scanNetworks(){ @@ -992,7 +993,7 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ // DEBUG_WM(DEBUG_DEV,"scanNetworks force:",force == true); if(force || _numNetworks == 0 || (millis()-_lastscan > 60000)){ int8_t res; - unsigned int _scanstart = millis(); + _startscan = millis(); if(async){ DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); #ifdef ESP8266 @@ -1017,7 +1018,7 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ } else if(res >=0 ) _numNetworks = res; _lastscan = millis(); - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan done"), "in "+(String)(_lastscan - _scanstart)+" ms"); + DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan completed"), "in "+(String)(_lastscan - _startscan)+" ms"); return true; } else DEBUG_WM(DEBUG_VERBOSE,"Scan is cached",(String)(millis()-_lastscan )+" ms ago"); return false; diff --git a/WiFiManager.h b/WiFiManager.h index c70ae27..787c987 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -281,7 +281,8 @@ class WiFiManager String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid uint8_t _lastconxresult = WL_IDLE_STATUS; int _numNetworks = 0; - unsigned long _lastscan = 0; // ms + unsigned long _lastscan = 0; // ms for timing wifi scans + unsigned long _startscan = 0; // ms for timing wifi scans int _cpclosedelay = 2000; // delay before wifisave, prevents captive portal from closing to fast. bool _cleanConnect = true; // disconnect before connect in connectwifi, increases stability on connects From 247aecb2fcc60882adfa3f3f6a3b417aa9ade0fc Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 28 Aug 2018 09:00:24 -0500 Subject: [PATCH 386/424] update requirements esp8266 2.4.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 55469f8..1f355a2 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are You can either install through the Arduino Library Manager or checkout the latest changes or a release from github #### Install through Library Manager -__Currently version 0.8+ works with release 2.0.0 or newer of the [ESP8266 core for Arduino](https://github.com/esp8266/Arduino)__ +__Currently version 0.8+ works with release 2.4.0 or newer of the [ESP8266 core for Arduino](https://github.com/esp8266/Arduino)__ - in Arduino IDE got to Sketch/Include Library/Manage Libraries ![Manage Libraries](http://i.imgur.com/9BkEBkR.png) @@ -87,7 +87,7 @@ __Currently version 0.8+ works with release 2.0.0 or newer of the [ESP8266 core - click Install and start [using it](#using) #### Checkout from github -__Github version works with release 2.0.0 or newer of the [ESP8266 core for Arduino](https://github.com/esp8266/Arduino)__ +__Github version works with release 2.4.0 or newer of the [ESP8266 core for Arduino](https://github.com/esp8266/Arduino)__ - Checkout library to your Arduino libraries folder ### Using From 8b579bb8a7e05b0e9f36b05525724132ec96e970 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 29 Aug 2018 11:22:05 -0500 Subject: [PATCH 387/424] debug --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 3c80bc2..be2bcaa 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -973,8 +973,8 @@ String WiFiManager::getMenuOut(){ void WiFiManager::WiFi_scanComplete(int networksFound){ _lastscan = millis(); _numNetworks = networksFound; - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan completed"), "in "+(String)(_lastscan - _startscan)+" ms"); - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan found:"),_numNetworks); + DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC completed"), "in "+(String)(_lastscan - _startscan)+" ms"); + DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC found:"),_numNetworks); } bool WiFiManager::WiFi_scanNetworks(){ From c1f018ca7c548bbf634630e5bc575a9f4edff099 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Mon, 3 Sep 2018 08:49:13 -0500 Subject: [PATCH 388/424] tentative fix for #720 --- WiFiManager.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index be2bcaa..30bda4c 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -272,7 +272,15 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { // if already connected, or try stored connect // @note @todo ESP32 has no autoconnect, so connectwifi will always be called unless user called begin etc before - if (WiFi.status() == WL_CONNECTED || connectWifi("", "") == WL_CONNECTED) { + // @todo check if correct ssid == saved ssid when already connected + bool connected = false; + if (WiFi.status() == WL_CONNECTED){ + connected = true; + DEBUG_WM(F("AutoConnect: ESP Already Connected")); + setSTAConfig(); + } + + if(connected || connectWifi("", "") == WL_CONNECTED){ //connected DEBUG_WM(F("AutoConnect: SUCCESS")); DEBUG_WM(F("STA IP Address:"),WiFi.localIP()); From b17c328f0fc06e8c4fa415aa0218de9aa6890668 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Mon, 3 Sep 2018 17:19:25 -0500 Subject: [PATCH 389/424] more debugging --- WiFiManager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 30bda4c..8660c43 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -771,6 +771,8 @@ bool WiFiManager::setSTAConfig(){ if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi config failed"); else DEBUG_WM(F("STA IP set:"),WiFi.localIP()); + } else { + DEBUG_WM(DEBUG_VERBOSE,F("setSTAConfig static ip not set")); } return ret; } From 42241d6e363a5e76faf5afb66e7bc815d8f9f99d Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 4 Sep 2018 08:13:30 -0500 Subject: [PATCH 390/424] fix nvs erase log --- WiFiManager.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index be2bcaa..663fc0d 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1807,13 +1807,14 @@ bool WiFiManager::erase(bool opt){ if(opt){ DEBUG_WM("Erasing NVS"); int err; + esp_err_t err; err = nvs_flash_init(); - DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_init: ",err==ESP_OK ? (String)err : "Success"); + DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_init: ",err!=ESP_OK ? (String)err : "Success"); err = nvs_flash_erase(); - DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_erase: ", err==ESP_OK ? (String)err : "Success"); + DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_erase: ", err!=ESP_OK ? (String)err : "Success"); return err == ESP_OK; } - #else + #else (void)opt; #endif From 3a0723cf667c9f7037db9d57237768fb43e94c20 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 4 Sep 2018 16:36:47 -0500 Subject: [PATCH 391/424] skip connect if wifi empty --- WiFiManager.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 6449371..c38ab2f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -574,11 +574,11 @@ uint8_t WiFiManager::processConfigPortal(){ DEBUG_WM(DEBUG_VERBOSE,F("process connect")); if(_enableCaptivePortal) delay(_cpclosedelay); // keeps the captiveportal from closing to fast. - // @todo skip wifi if no ssid - // if(_ssid == ""){ - // DEBUG_WM(DEBUG_VERBOSE,F("No ssid, skipping wifi")); - // } - // else{ + // skip wifi if no ssid + if(_ssid == ""){ + DEBUG_WM(DEBUG_VERBOSE,F("No ssid, skipping wifi")); + } + else{ // attempt sta connection to submitted _ssid, _pass if (connectWifi(_ssid, _pass) == WL_CONNECTED) { From 7ab5f6d5b2b39a3e3ad2dd42377fc307d8c58620 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 4 Sep 2018 16:36:58 -0500 Subject: [PATCH 392/424] clear wifi strings --- WiFiManager.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index c38ab2f..7080e58 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -606,6 +606,9 @@ uint8_t WiFiManager::processConfigPortal(){ return WL_CONNECT_FAILED; // CONNECT FAIL } else{ + // clear save strings + _ssid = ""; + _pass = ""; // if connect fails, turn sta off to stabilize AP WiFi_Disconnect(); WiFi_enableSTA(false); From 43051f9f51fa51a58bb2d993ce5e284f77230414 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 4 Sep 2018 16:37:14 -0500 Subject: [PATCH 393/424] fix --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 7080e58..634cd7b 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -593,8 +593,8 @@ uint8_t WiFiManager::processConfigPortal(){ return WL_CONNECTED; // CONNECT SUCCESS } DEBUG_WM(DEBUG_ERROR,F("[ERROR] Connect to new AP Failed")); - // } - + } + if (_shouldBreakAfterConfig) { // do save callback // @todo this is more of an exiting callback than a save, clarify when this should actually occur From 338544bc6a6d0af4fff7407797d09a4bdeef492d Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 4 Sep 2018 16:39:00 -0500 Subject: [PATCH 394/424] do savecallback on parmsave fo rnow #714 --- WiFiManager.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 634cd7b..a6092ff 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1307,6 +1307,11 @@ void WiFiManager::handleParamSave() { handleRequest(); doParamSave(); + // @todo use new callback for paramsaves + if ( _savecallback != NULL) { + _savecallback(); + } + String page = getHTTPHead(FPSTR(S_titleparamsaved)); // @token titleparamsaved page += FPSTR(HTTP_PARAMSAVED); page += FPSTR(HTTP_END); From 8871bdd311f1598f1201db7f4301fc3c4eb495c3 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 4 Sep 2018 16:39:16 -0500 Subject: [PATCH 395/424] logging --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index a6092ff..ebd5c14 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1297,7 +1297,7 @@ void WiFiManager::handleWifiSave() { DEBUG_WM(DEBUG_DEV,F("Sent wifi save page")); - connect = true; //signal ready to connect/reset + connect = true; //signal ready to connect/reset process in processConfigPortal } void WiFiManager::handleParamSave() { From 5827c2f8cb170c82ee5321d0e70bc8b8c77c19fe Mon Sep 17 00:00:00 2001 From: Rodrigo Jose Carbajales Date: Thu, 6 Sep 2018 12:11:38 +0200 Subject: [PATCH 396/424] Swapping enableAP and softAPConfig Swapping enableAP and softAPConfig for static IP STA --- WiFiManager.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index ebd5c14..a5c3f52 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -317,14 +317,6 @@ bool WiFiManager::startAP(){ _apcallback(this); } - // setup optional soft AP static ip config - if (_ap_static_ip) { - DEBUG_WM(F("Custom AP IP/GW/Subnet:")); - if(!WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn)){ - DEBUG_WM(DEBUG_ERROR,"[ERROR] softAPConfig failed!"); - } - } - #ifdef ESP8266 // @bug workaround for bug #4372 https://github.com/esp8266/Arduino/issues/4372 if(!WiFi.enableAP(true)) { @@ -334,6 +326,15 @@ bool WiFiManager::startAP(){ delay(500); // workaround delay #endif + // setup optional soft AP static ip config + if (_ap_static_ip) { + DEBUG_WM(F("Custom AP IP/GW/Subnet:")); + if(!WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn)){ + DEBUG_WM(DEBUG_ERROR,"[ERROR] softAPConfig failed!"); + } + } + + if(_channelSync){ DEBUG_WM(DEBUG_VERBOSE,"Starting AP on channel:",WiFi.channel()); } From 0d8b96ebf382e373f688e616b1a6da80b9769999 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 6 Sep 2018 20:45:38 -0500 Subject: [PATCH 397/424] update docblock to reflect setConfigPortalBlocking ignored configportaltimeout --- WiFiManager.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/WiFiManager.h b/WiFiManager.h index 787c987..4a9cf45 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -162,7 +162,7 @@ class WiFiManager //sets timeout before AP,webserver loop ends and exits even if there has been no setup. //useful for devices that failed to connect at some point and got stuck in a webserver loop - //in seconds setConfigPortalTimeout is a new name for setTimeout + //in seconds setConfigPortalTimeout is a new name for setTimeout, ! not used if setConfigPortalBlocking void setConfigPortalTimeout(unsigned long seconds); void setTimeout(unsigned long seconds); // @deprecated, alias @@ -188,7 +188,9 @@ class WiFiManager bool addParameter(WiFiManagerParameter *p); //if this is set, it will exit after config, even if connection is unsuccessful. void setBreakAfterConfig(boolean shouldBreak); - //if this is set, portal will be blocking and wait until save or exit, is false user must manually `process()` to handle config portal + // if this is set, portal will be blocking and wait until save or exit, + // is false user must manually `process()` to handle config portal, + // setConfigPortalTimeout is ignored in this mode, user is responsible for closing configportal void setConfigPortalBlocking(boolean shouldBlock); //if this is set, customise style void setCustomHeadElement(const char* element); From 04552e40d842a564fadfbf25fe108f1b054f7274 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 7 Sep 2018 14:51:27 -0500 Subject: [PATCH 398/424] some testing --- .../OnDemandConfigPortal.ino | 63 +++++++++++++++---- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index e72c921..b7f495f 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -11,17 +11,50 @@ WiFiManager wm; char ssid[] = "*************"; // your network SSID (name) char pass[] = "********"; // your network password +void debugchipid(){ + // WiFi.mode(WIFI_STA); + // WiFi.printDiag(Serial); + // Serial.println(modes[WiFi.getMode()]); + + // ESP.eraseConfig(); + // wm.resetSettings(); + // wm.erase(true); + WiFi.mode(WIFI_AP); + // WiFi.softAP(); + WiFi.enableAP(true); + delay(500); + // esp_wifi_start(); + delay(1000); + WiFi.printDiag(Serial); + delay(60000); + ESP.restart(); + + // AP esp_267751 + // 507726A4AE30 + // ESP32 Chip ID = 507726A4AE30 +} + +void saveCallback(){ + Serial.println("saveCallback fired"); +} + + +//gets called when WiFiManager enters configuration mode +void configModeCallback (WiFiManager *myWiFiManager) { + Serial.println("configModeCallback fired"); + // myWiFiManager->setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); + // Serial.println(WiFi.softAPIP()); + //if you used auto generated SSID, print it + // Serial.println(myWiFiManager->getConfigPortalSSID()); +} void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial.setDebugOutput(true); - delay(3000); + // delay(3000); Serial.println("\n Starting"); - // WiFi.mode(WIFI_STA); - // WiFi.printDiag(Serial); - // Serial.println(modes[WiFi.getMode()]); //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around // WiFiManager wm; @@ -31,14 +64,16 @@ void setup() { //Local intialization. Once its business is done, there is no need to keep it around //reset settings - for testing // wm.resetSettings(); - // + // wm.erase(); + wm.setClass("invert"); + wm.setAPCallback(configModeCallback); //sets timeout until configuration portal gets turned off //useful to make it all retry or go to sleep //in seconds // wm.setConfigPortalTimeout(600); - wm.setConnectTimeout(10); + // wm.setConnectTimeout(5); // wm.setShowStaticFields(true); // uint8_t menu[] = {wm.MENU_WIFI,wm.MENU_INFO,wm.MENU_PARAM,wm.MENU_CLOSE}; @@ -57,6 +92,9 @@ void setup() { WiFiManagerParameter custom_token("api_token", "api token", "", 16); WiFiManagerParameter custom_tokenb("invalid token", "invalid token", "", 0); + // callbacks + wm.setSaveConfigCallback(saveCallback); + //add all your parameters here wm.addParameter(&custom_html); wm.addParameter(&custom_mqtt_server); @@ -83,11 +121,15 @@ void setup() { std::vector menu = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"}; wm.setMenu(menu); - //set static ip + // set static sta ip // wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); // wm.setShowStaticFields(false); // wm.setShowDnsFields(false); + // set static ip + // wm.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); + // wm.setAPStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); + // WiFi.mode(WIFI_STA); // const wifi_country_t COUNTRY_US{"US",1,11,WIFI_COUNTRY_POLICY_AUTO}; // const wifi_country_t COUNTRY_CN{"CN",1,13,WIFI_COUNTRY_POLICY_AUTO}; @@ -116,18 +158,17 @@ void setup() { pinMode(TRIGGER_PIN, INPUT); } - void loop() { // is configuration portal requested? if ( digitalRead(TRIGGER_PIN) == LOW ) { + Serial.println("BUTTON PRESSED"); //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around //reset settings - for testing //wm.resetSettings(); //sets timeout until configuration portal gets turned off - //useful to make it all retry or go to sleep - //in seconds + //useful to make it all retry or go to sleep, in seconds wm.setConfigPortalTimeout(120); //it starts an access point with the specified name @@ -150,5 +191,5 @@ void loop() { } // put your main code here, to run repeatedly: - delay(10000); + delay(5000); } From 97e7d30c660cee98a616bcfe20e29042b5513518 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 7 Sep 2018 14:53:08 -0500 Subject: [PATCH 399/424] esp8266 2.3.0 compatability restored #576 asyncscannetworks not available in esp8266 2.3.0, adjusted server on to take cstr for backwards compatability --- WiFiManager.cpp | 28 ++++++++++++++++------------ WiFiManager.h | 6 ++++++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index ebd5c14..c7303e3 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -445,18 +445,18 @@ void WiFiManager::setupConfigPortal() { dnsServer->start(DNS_PORT, F("*"), WiFi.softAPIP()); /* Setup httpd callbacks, web pages: root, wifi config pages, SO captive portal detectors and not found. */ - server->on((String)FPSTR(R_root), std::bind(&WiFiManager::handleRoot, this)); - server->on((String)FPSTR(R_wifi), std::bind(&WiFiManager::handleWifi, this, true)); - server->on((String)FPSTR(R_wifinoscan), std::bind(&WiFiManager::handleWifi, this, false)); - server->on((String)FPSTR(R_wifisave), std::bind(&WiFiManager::handleWifiSave, this)); - server->on((String)FPSTR(R_info), std::bind(&WiFiManager::handleInfo, this)); - server->on((String)FPSTR(R_param), std::bind(&WiFiManager::handleParam, this)); - server->on((String)FPSTR(R_paramsave), std::bind(&WiFiManager::handleParamSave, this)); - server->on((String)FPSTR(R_restart), std::bind(&WiFiManager::handleReset, this)); - server->on((String)FPSTR(R_exit), std::bind(&WiFiManager::handleExit, this)); - server->on((String)FPSTR(R_close), std::bind(&WiFiManager::handleClose, this)); - server->on((String)FPSTR(R_erase), std::bind(&WiFiManager::handleErase, this, false)); - server->on((String)FPSTR(R_status), std::bind(&WiFiManager::handleWiFiStatus, this)); + server->on(String(FPSTR(R_wifi)).c_str(), std::bind(&WiFiManager::handleWifi, this, true)); + server->on(String(FPSTR(R_root)).c_str(), std::bind(&WiFiManager::handleRoot, this)); + server->on(String(FPSTR(R_wifinoscan)).c_str(), std::bind(&WiFiManager::handleWifi, this, false)); + server->on(String(FPSTR(R_wifisave)).c_str(), std::bind(&WiFiManager::handleWifiSave, this)); + server->on(String(FPSTR(R_info)).c_str(), std::bind(&WiFiManager::handleInfo, this)); + server->on(String(FPSTR(R_param)).c_str(), std::bind(&WiFiManager::handleParam, this)); + server->on(String(FPSTR(R_paramsave)).c_str(), std::bind(&WiFiManager::handleParamSave, this)); + server->on(String(FPSTR(R_restart)).c_str(), std::bind(&WiFiManager::handleReset, this)); + server->on(String(FPSTR(R_exit)).c_str(), std::bind(&WiFiManager::handleExit, this)); + server->on(String(FPSTR(R_close)).c_str(), std::bind(&WiFiManager::handleClose, this)); + server->on(String(FPSTR(R_erase)).c_str(), std::bind(&WiFiManager::handleErase, this, false)); + server->on(String(FPSTR(R_status)).c_str(), std::bind(&WiFiManager::handleWiFiStatus, this)); server->onNotFound (std::bind(&WiFiManager::handleNotFound, this)); server->begin(); // Web server start @@ -1010,9 +1010,13 @@ bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ if(async){ DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); #ifdef ESP8266 + #ifndef WM_NOASYNC // no async available < 2.4.0 using namespace std::placeholders; // for `_1` WiFi.scanNetworksAsync(std::bind(&WiFiManager::WiFi_scanComplete,this,_1)); #else + res = WiFi.scanNetworks(); + #endif + #else res = WiFi.scanNetworks(true); #endif return false; diff --git a/WiFiManager.h b/WiFiManager.h index 787c987..0619fa7 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -13,6 +13,7 @@ #ifndef WiFiManager_h #define WiFiManager_h +#include #include // #define WM_MDNS // also set MDNS with sethostname @@ -20,6 +21,11 @@ // #define WM_ERASE_NVS // esp32 erase(true) will erase NVS // #define WM_RTC // esp32 info page will include reset reasons +#ifdef ARDUINO_ESP8266_RELEASE_2_3_0 +#warning "ARDUINO_ESP8266_RELEASE_2_3_0, some WM features disabled" +#define WM_NOASYNC // esp8266 no async scan wifi +#endif + // #include "soc/efuse_reg.h" // include to add efuse chip rev to info, getChipRevision() is almost always the same though, so not sure why it matters. // #define esp32autoreconnect // implement esp32 autoreconnect event listener kludge From c52186079a45216966f135bcf62896fc95731aa0 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 7 Sep 2018 15:43:21 -0500 Subject: [PATCH 400/424] stopconfigportal public --- WiFiManager.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WiFiManager.h b/WiFiManager.h index 12c3a09..fa18c1c 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -145,6 +145,9 @@ class WiFiManager //manually start the config portal, autoconnect does this automatically on connect failure boolean startConfigPortal(); // auto generates apname boolean startConfigPortal(char const *apName, char const *apPassword = NULL); + + //manually stop the config portal if started manually + boolean stopConfigPortal(); //manually start the web portal, autoconnect does this automatically on connect failure void startWebPortal(); @@ -376,7 +379,6 @@ class WiFiManager boolean captivePortal(); boolean configPortalHasTimeout(); - boolean stopConfigPortal(); uint8_t processConfigPortal(); void stopCaptivePortal(); From ed80635e32728b467cddaf565bf6d8313fe7500b Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 7 Sep 2018 15:43:43 -0500 Subject: [PATCH 401/424] non blocking examples --- WiFiManager.cpp | 2 +- .../OnDemandConfigPortal.ino | 3 +- .../AutoConnectNonBlocking.ino | 0 .../onDemandNonBlocking.ino | 61 +++++++++++++++++++ .../OnDemandConfigPortal.ino | 3 +- .../OnDemandWebPortal/OnDemandWebPortal.ino | 43 ------------- 6 files changed, 65 insertions(+), 47 deletions(-) rename examples/{AutoConnect => NonBlocking}/AutoConnectNonBlocking/AutoConnectNonBlocking.ino (100%) create mode 100644 examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino delete mode 100644 examples/OnDemandWebPortal/OnDemandWebPortal.ino diff --git a/WiFiManager.cpp b/WiFiManager.cpp index c7303e3..e92c1ee 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -445,8 +445,8 @@ void WiFiManager::setupConfigPortal() { dnsServer->start(DNS_PORT, F("*"), WiFi.softAPIP()); /* Setup httpd callbacks, web pages: root, wifi config pages, SO captive portal detectors and not found. */ - server->on(String(FPSTR(R_wifi)).c_str(), std::bind(&WiFiManager::handleWifi, this, true)); server->on(String(FPSTR(R_root)).c_str(), std::bind(&WiFiManager::handleRoot, this)); + server->on(String(FPSTR(R_wifi)).c_str(), std::bind(&WiFiManager::handleWifi, this, true)); server->on(String(FPSTR(R_wifinoscan)).c_str(), std::bind(&WiFiManager::handleWifi, this, false)); server->on(String(FPSTR(R_wifisave)).c_str(), std::bind(&WiFiManager::handleWifiSave, this)); server->on(String(FPSTR(R_info)).c_str(), std::bind(&WiFiManager::handleInfo, this)); diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index b7f495f..d209f31 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -54,7 +54,8 @@ void setup() { Serial.setDebugOutput(true); // delay(3000); Serial.println("\n Starting"); - + WiFi.setSleepMode(WIFI_NONE_SLEEP); + //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around // WiFiManager wm; diff --git a/examples/AutoConnect/AutoConnectNonBlocking/AutoConnectNonBlocking.ino b/examples/NonBlocking/AutoConnectNonBlocking/AutoConnectNonBlocking.ino similarity index 100% rename from examples/AutoConnect/AutoConnectNonBlocking/AutoConnectNonBlocking.ino rename to examples/NonBlocking/AutoConnectNonBlocking/AutoConnectNonBlocking.ino diff --git a/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino b/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino new file mode 100644 index 0000000..c250038 --- /dev/null +++ b/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino @@ -0,0 +1,61 @@ +/** + * OnDemandWebPortal.ino + * example of running the webportal or configportal manually and no blocking + * trigger pin will start a webportal for 120 seconds then turn it off. + * startCP = true will start the configportal AP and webportal + */ +#include // https://github.com/tzapu/WiFiManager + +// select which pin will trigger the configuration portal when set to LOW +#define TRIGGER_PIN 0 + +WiFiManager wm; + +unsigned int timeout = 120; // seconds to run for +unsigned int startTime = millis(); +bool portalRunning = false; +bool startCP = false; // start AP and webserver if true, else start only webserver + +void setup() { + // put your setup code here, to run once + Serial.begin(115200); + Serial.println("\n Starting"); + pinMode(TRIGGER_PIN, INPUT_PULLUP); +} + +void loop() { + doWiFiManager(); + // put your main code here, to run repeatedly: +} + +void doWiFiManager(){ + // is auto timeout portal running + if(portalRunning){ + wm.process(); + if((millis()-startTime) > (timeout*1000)){ + Serial.println("portaltimeout"); + portalRunning = false; + if(startCP){ + wm.stopConfigPortal(); + } + else{ + wm.stopWebPortal(); + } + } + } + + // is configuration portal requested? + if(digitalRead(TRIGGER_PIN) == LOW && (!portalRunning)) { + Serial.println("Button Pressed, Starting Portal"); + if(startCP){ + wm.startConfigPortal(); + } + else{ + wm.startWebPortal(); + } + portalRunning = true; + startTime = millis(); + } +} + + diff --git a/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino index 357276b..e9252c3 100644 --- a/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -9,8 +9,7 @@ // select which pin will trigger the configuration portal when set to LOW #define TRIGGER_PIN 0 -int timeout = 120; // seconds to run for -bool webportalrunning = false; +int timeout = 120; // seconds to run for void setup() { // put your setup code here, to run once: diff --git a/examples/OnDemandWebPortal/OnDemandWebPortal.ino b/examples/OnDemandWebPortal/OnDemandWebPortal.ino deleted file mode 100644 index 07f61e9..0000000 --- a/examples/OnDemandWebPortal/OnDemandWebPortal.ino +++ /dev/null @@ -1,43 +0,0 @@ -/** - * OnDemandWebPortal.ino - * example of running the webportal manually, independantly from the captiveportal - * trigger pin will start a webportal for 120 seconds then turn it off. - * - */ -#include // https://github.com/tzapu/WiFiManager - -// select which pin will trigger the configuration portal when set to LOW -#define TRIGGER_PIN 0 - -WiFiManager wm; - -int timeout = 120; // seconds to run for -bool webportalrunning = false; -int start = millis(); - -void setup() { - // put your setup code here, to run once: - Serial.begin(115200); - Serial.println("\n Starting"); - pinMode(TRIGGER_PIN, INPUT_PULLUP); -} - - -void loop() { - if(webportalrunning){ - wm.process(); - if(millis()-start > timeout*1000){ - Serial.println("webportaltimeout"); - webportalrunning = false; - wm.stopWebPortal(); // auto off - } - } - // is configuration portal requested? - if ( digitalRead(TRIGGER_PIN) == LOW && !webportalrunning) { - wm.startWebPortal(); - // wm.startWebPortal(); - webportalrunning = true; - start = millis(); - } - // put your main code here, to run repeatedly: -} From 2610dcb2c5d7dd87ad431106d560476d5968752f Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 7 Sep 2018 15:52:52 -0500 Subject: [PATCH 402/424] change simple to basic clean up --- examples/Basic/Basic.ino | 37 +++++++++++++++++++++++++++++++++++++ examples/Simple/Simple.ino | 31 ------------------------------- 2 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 examples/Basic/Basic.ino delete mode 100644 examples/Simple/Simple.ino diff --git a/examples/Basic/Basic.ino b/examples/Basic/Basic.ino new file mode 100644 index 0000000..26ec6d4 --- /dev/null +++ b/examples/Basic/Basic.ino @@ -0,0 +1,37 @@ +#include // https://github.com/tzapu/WiFiManager + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + + //WiFiManager, Local intialization. Once its business is done, there is no need to keep it around + WiFiManager wm; + + //reset settings - wipe credentials for testing + //wm.resetSettings(); + + // Automatically connect using saved credentials, + // if connection fails, it starts an access point with the specified name ( "AutoConnectAP"), + // if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect()) + // then goes into a blocking loop awaiting configuration and will return success result + + bool res; + // res = wm.autoConnect(); // auto generated AP name from chipid + // res = wm.autoConnect("AutoConnectAP"); // anonymous ap + res = wm.autoConnect("AutoConnectAP","password"); // password protected ap + + if(!res) { + Serial.println("Failed to connect"); + // ESP.restart(); + } + else { + //if you get here you have connected to the WiFi + Serial.println("connected...yeey :)"); + } + +} + +void loop() { + // put your main code here, to run repeatedly: + +} diff --git a/examples/Simple/Simple.ino b/examples/Simple/Simple.ino deleted file mode 100644 index e244fde..0000000 --- a/examples/Simple/Simple.ino +++ /dev/null @@ -1,31 +0,0 @@ -#include // https://github.com/tzapu/WiFiManager - -void setup() { - // put your setup code here, to run once: - Serial.begin(115200); - - //WiFiManager, Local intialization. Once its business is done, there is no need to keep it around - WiFiManager wm; - - //reset settings - wipe credentials for testing - //wm.resetSettings(); - - //set custom ip for portal - //wm.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); - - //automatically connect using saved credentials if they exist - //If connection fails it starts an access point with the specified name - //here "AutoConnectAP" if empty will auto generate basedcon chipid, if password is blank it will be anonymous - //and goes into a blocking loop awaiting configuration - wm.autoConnect("AutoConnectAP"); - //or use this for auto generated name ESP + ChipID - //wm.autoConnect(); - - //if you get here you have connected to the WiFi - Serial.println("connected...yeey :)"); -} - -void loop() { - // put your main code here, to run repeatedly: - -} From 1e10ffa49a0b3009eb76fac7c49fc7fb2c67f2aa Mon Sep 17 00:00:00 2001 From: Shawn A Date: Fri, 7 Sep 2018 16:16:44 -0500 Subject: [PATCH 403/424] reworkgin examples --- examples/Advanced/Advanced.ino | 44 +++++++++------- .../onDemandNonBlocking.ino | 9 ++-- .../OnDemandConfigPortal.ino | 0 .../OnDemandWebPortal/onDemandWebPortal.ino | 50 +++++++++++++++++++ 4 files changed, 80 insertions(+), 23 deletions(-) rename examples/{ => OnDemand}/OnDemandConfigPortal/OnDemandConfigPortal.ino (100%) create mode 100644 examples/OnDemand/OnDemandWebPortal/onDemandWebPortal.ino diff --git a/examples/Advanced/Advanced.ino b/examples/Advanced/Advanced.ino index 7bc3795..700ab6c 100644 --- a/examples/Advanced/Advanced.ino +++ b/examples/Advanced/Advanced.ino @@ -58,6 +58,7 @@ void setup() { if(!res) { Serial.println("Failed to connect or hit timeout"); + // ESP.restart(); } else { //if you get here you have connected to the WiFi @@ -65,33 +66,38 @@ void setup() { } } -void loop() { +void checkButton(){ // check for button press if ( digitalRead(TRIGGER_PIN) == LOW ) { - // poor mans debounce, not recommended for production code + // poor mans debounce/press-hold, not recommended for production code delay(50); if( digitalRead(TRIGGER_PIN) == LOW ){ - delay(3000); // reset timer - if( digitalRead(TRIGGER_PIN) == LOW ){ - Serial.println("Erasing Config"); // holding button 3000 ms, reset settings - wm.resetSettings(); - ESP.restart(); - } - - Serial.println("Starting config portal"); - wm.setConfigPortalTimeout(120); - - if (!wm.startConfigPortal("OnDemandAP")) { - Serial.println("failed to connect or hit timeout"); - delay(3000); - } else { - //if you get here you have connected to the WiFi - Serial.println("connected...yeey :)"); + delay(3000); // reset delay hold + if( digitalRead(TRIGGER_PIN) == LOW ){ + Serial.println("Erasing Config"); + wm.resetSettings(); + ESP.restart(); + } + + // start portal w delay + Serial.println("Starting config portal"); + wm.setConfigPortalTimeout(120); + + if (!wm.startConfigPortal("OnDemandAP")) { + Serial.println("failed to connect or hit timeout"); + delay(3000); + // ESP.restart(); + } else { + //if you get here you have connected to the WiFi + Serial.println("connected...yeey :)"); + } } } - } +} +void loop() { + checkButton(); // put your main code here, to run repeatedly: } diff --git a/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino b/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino index c250038..9d283ec 100644 --- a/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino +++ b/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino @@ -1,8 +1,8 @@ /** - * OnDemandWebPortal.ino - * example of running the webportal or configportal manually and no blocking + * OnDemandNonBlocking.ino + * example of running the webportal or configportal manually and non blocking * trigger pin will start a webportal for 120 seconds then turn it off. - * startCP = true will start the configportal AP and webportal + * startCP = true will start both the configportal AP and webportal */ #include // https://github.com/tzapu/WiFiManager @@ -46,11 +46,12 @@ void doWiFiManager(){ // is configuration portal requested? if(digitalRead(TRIGGER_PIN) == LOW && (!portalRunning)) { - Serial.println("Button Pressed, Starting Portal"); if(startCP){ + Serial.println("Button Pressed, Starting Config Portal"); wm.startConfigPortal(); } else{ + Serial.println("Button Pressed, Starting Web Portal"); wm.startWebPortal(); } portalRunning = true; diff --git a/examples/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/OnDemand/OnDemandConfigPortal/OnDemandConfigPortal.ino similarity index 100% rename from examples/OnDemandConfigPortal/OnDemandConfigPortal.ino rename to examples/OnDemand/OnDemandConfigPortal/OnDemandConfigPortal.ino diff --git a/examples/OnDemand/OnDemandWebPortal/onDemandWebPortal.ino b/examples/OnDemand/OnDemandWebPortal/onDemandWebPortal.ino new file mode 100644 index 0000000..5850e40 --- /dev/null +++ b/examples/OnDemand/OnDemandWebPortal/onDemandWebPortal.ino @@ -0,0 +1,50 @@ +/** + * OnDemandWebPortal.ino + * example of running the webportal (always NON blocking) + */ +#include // https://github.com/tzapu/WiFiManager + +// select which pin will trigger the configuration portal when set to LOW +#define TRIGGER_PIN 0 + +WiFiManager wm; + +bool portalRunning = false; + +void setup() { + // put your setup code here, to run once + Serial.begin(115200); + Serial.println("\n Starting"); + pinMode(TRIGGER_PIN, INPUT_PULLUP); +} + +void loop() { + checkButton(); + // put your main code here, to run repeatedly: +} + +void checkButton(){ + // is auto timeout portal running + if(portalRunning){ + wm.process(); + } + + // is configuration portal requested? + if(digitalRead(TRIGGER_PIN) == LOW) { + delay(50) + if(digitalRead(TRIGGER_PIN) == LOW) { + if(!portalRunning){ + Serial.println("Button Pressed, Starting Portal"); + wm.startWebPortal(); + portalRunning = true; + } + else{ + Serial.println("Button Pressed, Stopping Portal"); + wm.startWebPortal(); + portalRunning = false; + } + } + } +} + + From 393e7e45dffc4b07e0aff74fcb75c17ce4f4cb98 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 12 Sep 2018 09:56:20 -0500 Subject: [PATCH 404/424] bug fixes #726 --- WiFiManager.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/WiFiManager.h b/WiFiManager.h index fa18c1c..262189f 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -13,7 +13,10 @@ #ifndef WiFiManager_h #define WiFiManager_h +#ifdef ESP8266 #include +#endif + #include // #define WM_MDNS // also set MDNS with sethostname From 9ce498c5b6ef82808fa42189ffd000604fd30fb6 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 12 Sep 2018 10:55:04 -0500 Subject: [PATCH 405/424] remove sleep mode --- examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index d209f31..2677711 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -54,7 +54,7 @@ void setup() { Serial.setDebugOutput(true); // delay(3000); Serial.println("\n Starting"); - WiFi.setSleepMode(WIFI_NONE_SLEEP); + // WiFi.setSleepMode(WIFI_NONE_SLEEP); //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around From 4f0a87a0a5ae3b4e738662eaf7c994fe68cb5f59 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 12 Sep 2018 13:19:53 -0500 Subject: [PATCH 406/424] adds esp32 core temp, not enabled the core temp sensors are not calibrated in production atm, they are large offsets form chip to chip and are useful for relative temp swings only. Until the IDF comes up with a new temp sense, this is commented out. --- WiFiManager.cpp | 9 +++++++++ strings_en.h | 1 + 2 files changed, 10 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index e92c1ee..2cb5dd4 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1408,6 +1408,7 @@ void WiFiManager::handleInfo() { F("cpufreq"), F("freeheap"), F("lastreset"), + // F("temp"), F("wifihead"), F("apip"), F("apmac"), @@ -1617,6 +1618,14 @@ String WiFiManager::getInfoData(String id){ p.replace(FPSTR(T_1),WiFi.getAutoConnect() ? FPSTR(S_enable) : FPSTR(S_disable)); } #endif + #ifdef ESP32 + else if(id==F("temp")){ + // 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)); + } + #endif return p; } diff --git a/strings_en.h b/strings_en.h index edbc84e..21f3f2b 100644 --- a/strings_en.h +++ b/strings_en.h @@ -166,6 +166,7 @@ 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_temp[] PROGMEM = "
Temperature
{1} C° / {2} F°
"; // Strings const char S_y[] PROGMEM = "Yes"; From d9c27b98d41069150b45ddc9c3d8d8f39eee8a18 Mon Sep 17 00:00:00 2001 From: ayeah Date: Mon, 17 Sep 2018 01:10:37 +0700 Subject: [PATCH 407/424] add listener setPreSaveConfigCallback this listener required for action before save process behind wifi or params. --- WiFiManager.cpp | 2669 ++++++++++++++++++++++++++++------------------- WiFiManager.h | 3 + 2 files changed, 1571 insertions(+), 1101 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index e92c1ee..9fd7539 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -22,84 +22,103 @@ uint8_t WiFiManager::_lastconxresulttmp = WL_IDLE_STATUS; * -------------------------------------------------------------------------------- **/ -WiFiManagerParameter::WiFiManagerParameter(const char *custom) { - _id = NULL; - _placeholder = NULL; - _length = 1; - _value = NULL; +WiFiManagerParameter::WiFiManagerParameter(const char *custom) +{ + _id = NULL; + _placeholder = NULL; + _length = 1; + _value = NULL; _labelPlacement = WFM_LABEL_BEFORE; - _customHTML = custom; + _customHTML = custom; } -WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder) { +WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder) +{ init(id, placeholder, "", 0, "", WFM_LABEL_BEFORE); } -WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length) { +WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length) +{ init(id, placeholder, defaultValue, length, "", WFM_LABEL_BEFORE); } -WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) { +WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) +{ init(id, placeholder, defaultValue, length, custom, WFM_LABEL_BEFORE); } -WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) { +WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) +{ init(id, placeholder, defaultValue, length, custom, labelPlacement); } -void WiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) { - _id = id; - _placeholder = placeholder; +void WiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) +{ + _id = id; + _placeholder = placeholder; _labelPlacement = labelPlacement; - _customHTML = custom; - setValue(defaultValue,length); + _customHTML = custom; + setValue(defaultValue, length); } -WiFiManagerParameter::~WiFiManagerParameter() { - if (_value != NULL) { +WiFiManagerParameter::~WiFiManagerParameter() +{ + if (_value != NULL) + { delete[] _value; } - _length=0; // setting length 0, ideally the entire parameter should be removed, or added to wifimanager scope so it follows + _length = 0; // setting length 0, ideally the entire parameter should be removed, or added to wifimanager scope so it follows } -void WiFiManagerParameter::setValue(const char *defaultValue, int length) { - if(!_id){ +void WiFiManagerParameter::setValue(const char *defaultValue, int length) +{ + if (!_id) + { // Serial.println("cannot set value of this parameter"); return; } - _length = length; + _length = length; int deflength = strlen(defaultValue); // length actual - // use the defult length if it's longer, + // use the defult length if it's longer, // @todo consider it might be useful to fail, so user knows they were wrong - if(_length < length){ + if (_length < length) + { // Serial.println("defaultValue length mismatch"); _length = deflength; } _value = new char[_length + 1]; - for (int i = 0; i < _length + 1; i++) { + for (int i = 0; i < _length + 1; i++) + { _value[i] = 0; } - if (defaultValue != NULL) { + if (defaultValue != NULL) + { strncpy(_value, defaultValue, _length); _value[_length] = '\0'; // explicit null } } -const char* WiFiManagerParameter::getValue() { +const char *WiFiManagerParameter::getValue() +{ return _value; } -const char* WiFiManagerParameter::getID() { +const char *WiFiManagerParameter::getID() +{ return _id; } -const char* WiFiManagerParameter::getPlaceholder() { +const char *WiFiManagerParameter::getPlaceholder() +{ return _placeholder; } -int WiFiManagerParameter::getValueLength() { +int WiFiManagerParameter::getValueLength() +{ return _length; } -int WiFiManagerParameter::getLabelPlacement() { +int WiFiManagerParameter::getLabelPlacement() +{ return _labelPlacement; } -const char* WiFiManagerParameter::getCustomHTML() { +const char *WiFiManagerParameter::getCustomHTML() +{ return _customHTML; } @@ -108,45 +127,54 @@ const char* WiFiManagerParameter::getCustomHTML() { * @access public * @param {[type]} WiFiManagerParameter *p [description] */ -bool WiFiManager::addParameter(WiFiManagerParameter *p) { +bool WiFiManager::addParameter(WiFiManagerParameter *p) +{ // check param id is valid, unless null - if(p->getID()){ - for (size_t i = 0; i < strlen(p->getID()); i++){ - if(!(isAlphaNumeric(p->getID()[i])) && !(p->getID()[i]=='_')){ - DEBUG_WM(DEBUG_ERROR,"[ERROR] parameter IDs can only contain alpha numeric chars"); + if (p->getID()) + { + for (size_t i = 0; i < strlen(p->getID()); i++) + { + if (!(isAlphaNumeric(p->getID()[i])) && !(p->getID()[i] == '_')) + { + DEBUG_WM(DEBUG_ERROR, "[ERROR] parameter IDs can only contain alpha numeric chars"); return false; - } + } } } // init params if never malloc - if(_params == NULL){ - DEBUG_WM(DEBUG_DEV,"allocating params bytes:",_max_params * sizeof(WiFiManagerParameter*)); - _params = (WiFiManagerParameter**)malloc(_max_params * sizeof(WiFiManagerParameter*)); + if (_params == NULL) + { + DEBUG_WM(DEBUG_DEV, "allocating params bytes:", _max_params * sizeof(WiFiManagerParameter *)); + _params = (WiFiManagerParameter **)malloc(_max_params * sizeof(WiFiManagerParameter *)); } // resize the params array by increment of WIFI_MANAGER_MAX_PARAMS - if(_paramsCount == _max_params){ + if (_paramsCount == _max_params) + { _max_params += WIFI_MANAGER_MAX_PARAMS; - DEBUG_WM(DEBUG_DEV,F("Updated _max_params:"),_max_params); - DEBUG_WM(DEBUG_DEV,"re-allocating params bytes:",_max_params * sizeof(WiFiManagerParameter*)); - WiFiManagerParameter** new_params = (WiFiManagerParameter**)realloc(_params, _max_params * sizeof(WiFiManagerParameter*)); + DEBUG_WM(DEBUG_DEV, F("Updated _max_params:"), _max_params); + DEBUG_WM(DEBUG_DEV, "re-allocating params bytes:", _max_params * sizeof(WiFiManagerParameter *)); + WiFiManagerParameter **new_params = (WiFiManagerParameter **)realloc(_params, _max_params * sizeof(WiFiManagerParameter *)); // DEBUG_WM(WIFI_MANAGER_MAX_PARAMS); // DEBUG_WM(_paramsCount); // DEBUG_WM(_max_params); - if (new_params != NULL) { + if (new_params != NULL) + { _params = new_params; - } else { - DEBUG_WM(DEBUG_ERROR,"[ERROR] failed to realloc params, size not increased!"); + } + else + { + DEBUG_WM(DEBUG_ERROR, "[ERROR] failed to realloc params, size not increased!"); return false; } } _params[_paramsCount] = p; _paramsCount++; - - DEBUG_WM(DEBUG_VERBOSE,"Added Parameter:",p->getID()); + + DEBUG_WM(DEBUG_VERBOSE, "Added Parameter:", p->getID()); return true; } @@ -157,51 +185,62 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { **/ // constructors -WiFiManager::WiFiManager(Stream& consolePort):_debugPort(consolePort){ +WiFiManager::WiFiManager(Stream &consolePort) : _debugPort(consolePort) +{ WiFiManagerInit(); } -WiFiManager::WiFiManager():WiFiManager(Serial) { +WiFiManager::WiFiManager() : WiFiManager(Serial) +{ } -void WiFiManager::WiFiManagerInit(){ +void WiFiManager::WiFiManagerInit() +{ setMenu(_menuIdsDefault); - if(_debug && _debugLevel > DEBUG_DEV) debugPlatformInfo(); + if (_debug && _debugLevel > DEBUG_DEV) + debugPlatformInfo(); _max_params = WIFI_MANAGER_MAX_PARAMS; } // destructor -WiFiManager::~WiFiManager() { +WiFiManager::~WiFiManager() +{ _end(); // parameters // @todo belongs to wifimanagerparameter - if (_params != NULL){ - DEBUG_WM(DEBUG_DEV,F("freeing allocated params!")); + if (_params != NULL) + { + DEBUG_WM(DEBUG_DEV, F("freeing allocated params!")); free(_params); _params = NULL; } - DEBUG_WM(DEBUG_DEV,F("unloading")); + DEBUG_WM(DEBUG_DEV, F("unloading")); } -void WiFiManager::_begin(){ - if(_hasBegun) return; +void WiFiManager::_begin() +{ + if (_hasBegun) + return; _usermode = WiFi.getMode(); - #ifndef ESP32 +#ifndef ESP32 WiFi.persistent(false); // disable persistent so scannetworks and mode switching do not cause overwrites - #endif +#endif } -void WiFiManager::_end(){ - if(_userpersistent) WiFi.persistent(true); // reenable persistent, there is no getter we rely on _userpersistent +void WiFiManager::_end() +{ + if (_userpersistent) + WiFi.persistent(true); // reenable persistent, there is no getter we rely on _userpersistent // if(_usermode != WIFI_OFF) WiFi.mode(_usermode); } // AUTOCONNECT -boolean WiFiManager::autoConnect() { - String ssid = _wifissidprefix + "_" + String(WIFI_getChipId(),HEX); +boolean WiFiManager::autoConnect() +{ + String ssid = _wifissidprefix + "_" + String(WIFI_getChipId(), HEX); return autoConnect(ssid.c_str(), NULL); } @@ -212,22 +251,25 @@ boolean WiFiManager::autoConnect() { * @param {[type]} char const *apPassword [description] * @return {[type]} [description] */ -boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { +boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) +{ DEBUG_WM(F("AutoConnect")); _begin(); // attempt to connect using saved settings, on fail fallback to AP config portal - if(!WiFi.enableSTA(true)){ + if (!WiFi.enableSTA(true)) + { // handle failure mode Brownout detector etc. - DEBUG_WM(DEBUG_ERROR,"[FATAL] Unable to enable wifi!"); + DEBUG_WM(DEBUG_ERROR, "[FATAL] Unable to enable wifi!"); return false; } - + WiFiSetCountry(); - #ifdef ESP32 - if(esp32persistent) WiFi.persistent(false); // disable persistent for esp32 after esp_wifi_start or else saves wont work - #endif +#ifdef ESP32 + if (esp32persistent) + WiFi.persistent(false); // disable persistent for esp32 after esp_wifi_start or else saves wont work +#endif _usermode = WIFI_STA; @@ -237,67 +279,76 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { WiFi_autoReconnect(); // set hostname before stating - if((String)_hostname != ""){ - DEBUG_WM(DEBUG_VERBOSE,"Setting hostname:",_hostname); + if ((String)_hostname != "") + { + DEBUG_WM(DEBUG_VERBOSE, "Setting hostname:", _hostname); bool res = true; - #ifdef ESP8266 - res = WiFi.hostname(_hostname); - #ifdef ESP8266MDNS_H - DEBUG_WM(DEBUG_VERBOSE,"Setting MDNS hostname"); - if(MDNS.begin(_hostname)){ - MDNS.addService("http", "tcp", 80); - } - #endif - #elif defined(ESP32) - // @note hostname must be set after STA_START - delay(200); // do not remove, give time for STA_START - res = WiFi.setHostname(_hostname); - #ifdef ESP32MDNS_H - DEBUG_WM(DEBUG_VERBOSE,"Setting MDNS hostname"); - if(MDNS.begin(_hostname)){ - MDNS.addService("http", "tcp", 80); - } - #endif - #endif - - if(!res)DEBUG_WM(DEBUG_ERROR,F("[ERROR] hostname: set failed!")); - - if(WiFi.status() == WL_CONNECTED){ - DEBUG_WM(DEBUG_VERBOSE,F("reconnecting to set new hostname")); +#ifdef ESP8266 + res = WiFi.hostname(_hostname); +#ifdef ESP8266MDNS_H + DEBUG_WM(DEBUG_VERBOSE, "Setting MDNS hostname"); + if (MDNS.begin(_hostname)) + { + MDNS.addService("http", "tcp", 80); + } +#endif +#elif defined(ESP32) + // @note hostname must be set after STA_START + delay(200); // do not remove, give time for STA_START + res = WiFi.setHostname(_hostname); +#ifdef ESP32MDNS_H + DEBUG_WM(DEBUG_VERBOSE, "Setting MDNS hostname"); + if (MDNS.begin(_hostname)) + { + MDNS.addService("http", "tcp", 80); + } +#endif +#endif + + if (!res) + DEBUG_WM(DEBUG_ERROR, F("[ERROR] hostname: set failed!")); + + if (WiFi.status() == WL_CONNECTED) + { + DEBUG_WM(DEBUG_VERBOSE, F("reconnecting to set new hostname")); // WiFi.reconnect(); // This does not reset dhcp WiFi_Disconnect(); delay(200); // do not remove, need a delay for disconnect to change status() } } - // if already connected, or try stored connect + // if already connected, or try stored connect // @note @todo ESP32 has no autoconnect, so connectwifi will always be called unless user called begin etc before // @todo check if correct ssid == saved ssid when already connected bool connected = false; - if (WiFi.status() == WL_CONNECTED){ + if (WiFi.status() == WL_CONNECTED) + { connected = true; DEBUG_WM(F("AutoConnect: ESP Already Connected")); setSTAConfig(); } - if(connected || connectWifi("", "") == WL_CONNECTED){ + if (connected || connectWifi("", "") == WL_CONNECTED) + { //connected DEBUG_WM(F("AutoConnect: SUCCESS")); - DEBUG_WM(F("STA IP Address:"),WiFi.localIP()); + DEBUG_WM(F("STA IP Address:"), WiFi.localIP()); _lastconxresult = WL_CONNECTED; - if((String)_hostname != ""){ - #ifdef ESP8266 - DEBUG_WM(DEBUG_DEV,"hostname: STA",WiFi.hostname()); - #elif defined(ESP32) - DEBUG_WM(DEBUG_DEV,"hostname: STA",WiFi.getHostname()); - #endif + if ((String)_hostname != "") + { +#ifdef ESP8266 + DEBUG_WM(DEBUG_DEV, "hostname: STA", WiFi.hostname()); +#elif defined(ESP32) + DEBUG_WM(DEBUG_DEV, "hostname: STA", WiFi.getHostname()); +#endif } return true; } // possibly skip the config portal - if (!_enableConfigPortal) { + if (!_enableConfigPortal) + { return false; } @@ -308,71 +359,88 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { } // CONFIG PORTAL -bool WiFiManager::startAP(){ +bool WiFiManager::startAP() +{ bool ret = true; - DEBUG_WM(F("StartAP with SSID: "),_apName); + DEBUG_WM(F("StartAP with SSID: "), _apName); // do AP callback if set - if ( _apcallback != NULL) { + if (_apcallback != NULL) + { _apcallback(this); } // setup optional soft AP static ip config - if (_ap_static_ip) { + if (_ap_static_ip) + { DEBUG_WM(F("Custom AP IP/GW/Subnet:")); - if(!WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn)){ - DEBUG_WM(DEBUG_ERROR,"[ERROR] softAPConfig failed!"); + if (!WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn)) + { + DEBUG_WM(DEBUG_ERROR, "[ERROR] softAPConfig failed!"); } } - #ifdef ESP8266 - // @bug workaround for bug #4372 https://github.com/esp8266/Arduino/issues/4372 - if(!WiFi.enableAP(true)) { - DEBUG_WM(DEBUG_ERROR,"[ERROR] enableAP failed!"); - return false; - } - delay(500); // workaround delay - #endif +#ifdef ESP8266 + // @bug workaround for bug #4372 https://github.com/esp8266/Arduino/issues/4372 + if (!WiFi.enableAP(true)) + { + DEBUG_WM(DEBUG_ERROR, "[ERROR] enableAP failed!"); + return false; + } + delay(500); // workaround delay +#endif - if(_channelSync){ - DEBUG_WM(DEBUG_VERBOSE,"Starting AP on channel:",WiFi.channel()); - } + if (_channelSync) + { + DEBUG_WM(DEBUG_VERBOSE, "Starting AP on channel:", WiFi.channel()); + } // start soft AP with password or anonymous - if (_apPassword != "") { - if(_channelSync){ - ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(),WiFi.channel()); - } - else{ - ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str());//password option + if (_apPassword != "") + { + if (_channelSync) + { + ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(), WiFi.channel()); } - } else { - DEBUG_WM(DEBUG_VERBOSE,F("AP has anonymous access!")); - if(_channelSync){ - ret = WiFi.softAP(_apName.c_str(),"",WiFi.channel()); - } - else{ + else + { + ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str()); //password option + } + } + else + { + DEBUG_WM(DEBUG_VERBOSE, F("AP has anonymous access!")); + if (_channelSync) + { + ret = WiFi.softAP(_apName.c_str(), "", WiFi.channel()); + } + else + { ret = WiFi.softAP(_apName.c_str()); - } + } } - if(_debugLevel > DEBUG_DEV) debugSoftAPConfig(); + if (_debugLevel > DEBUG_DEV) + debugSoftAPConfig(); - if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] There was a problem starting the AP"); + if (!ret) + DEBUG_WM(DEBUG_ERROR, "[ERROR] There was a problem starting the AP"); // @todo add softAP retry here - - delay(500); // slight delay to make sure we get an AP IP - DEBUG_WM(F("AP IP address:"),WiFi.softAPIP()); - // set ap hostname - #ifdef ESP32 - if(ret && (String)_hostname != ""){ - DEBUG_WM(DEBUG_VERBOSE,"setting softAP Hostname:",_hostname); - bool res = WiFi.softAPsetHostname(_hostname); - if(!res)DEBUG_WM(DEBUG_ERROR,F("[ERROR] hostname: AP set failed!")); - DEBUG_WM(DEBUG_DEV,F("hostname: AP"),WiFi.softAPgetHostname()); - } - #endif + delay(500); // slight delay to make sure we get an AP IP + DEBUG_WM(F("AP IP address:"), WiFi.softAPIP()); + +// set ap hostname +#ifdef ESP32 + if (ret && (String)_hostname != "") + { + DEBUG_WM(DEBUG_VERBOSE, "setting softAP Hostname:", _hostname); + bool res = WiFi.softAPsetHostname(_hostname); + if (!res) + DEBUG_WM(DEBUG_ERROR, F("[ERROR] hostname: AP set failed!")); + DEBUG_WM(DEBUG_DEV, F("hostname: AP"), WiFi.softAPgetHostname()); + } +#endif return ret; } @@ -382,8 +450,10 @@ bool WiFiManager::startAP(){ * @access public * @return {[type]} [description] */ -void WiFiManager::startWebPortal() { - if(configPortalActive || webPortalActive) return; +void WiFiManager::startWebPortal() +{ + if (configPortalActive || webPortalActive) + return; setupConfigPortal(); webPortalActive = true; } @@ -393,44 +463,56 @@ void WiFiManager::startWebPortal() { * @access public * @return {[type]} [description] */ -void WiFiManager::stopWebPortal() { - if(!configPortalActive && !webPortalActive) return; - DEBUG_WM(DEBUG_VERBOSE,F("Stopping Web Portal")); +void WiFiManager::stopWebPortal() +{ + if (!configPortalActive && !webPortalActive) + return; + DEBUG_WM(DEBUG_VERBOSE, F("Stopping Web Portal")); webPortalActive = false; stopConfigPortal(); } -boolean WiFiManager::configPortalHasTimeout(){ +boolean WiFiManager::configPortalHasTimeout() +{ - if(_configPortalTimeout == 0 || (_cpClientCheck && (WiFi_softap_num_stations() > 0))){ - if(millis() - timer > 30000){ - timer = millis(); - DEBUG_WM(DEBUG_VERBOSE,"NUM CLIENTS: " + (String)WiFi_softap_num_stations()); - } - _configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts - return false; + if (_configPortalTimeout == 0 || (_cpClientCheck && (WiFi_softap_num_stations() > 0))) + { + if (millis() - timer > 30000) + { + timer = millis(); + DEBUG_WM(DEBUG_VERBOSE, "NUM CLIENTS: " + (String)WiFi_softap_num_stations()); } - // handle timeout - if(_webClientCheck && (_webPortalAccessed>_configPortalStart)>0) _configPortalStart = _webPortalAccessed; - - if(millis() > _configPortalStart + _configPortalTimeout){ - DEBUG_WM(F("config portal has timed out")); - return true; - } else if(_debugLevel > 0) { - // log timeout - if(_debug){ - uint16_t logintvl = 30000; // how often to emit timeing out counter logging - if((millis() - timer) > logintvl){ - timer = millis(); - DEBUG_WM(DEBUG_VERBOSE,F("Portal Timeout In"),(String)((_configPortalStart + _configPortalTimeout-millis())/1000) + (String)F(" seconds")); - } - } - } - + _configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts return false; + } + // handle timeout + if (_webClientCheck && (_webPortalAccessed > _configPortalStart) > 0) + _configPortalStart = _webPortalAccessed; + + if (millis() > _configPortalStart + _configPortalTimeout) + { + DEBUG_WM(F("config portal has timed out")); + return true; + } + else if (_debugLevel > 0) + { + // log timeout + if (_debug) + { + uint16_t logintvl = 30000; // how often to emit timeing out counter logging + if ((millis() - timer) > logintvl) + { + timer = millis(); + DEBUG_WM(DEBUG_VERBOSE, F("Portal Timeout In"), (String)((_configPortalStart + _configPortalTimeout - millis()) / 1000) + (String)F(" seconds")); + } + } + } + + return false; } -void WiFiManager::setupConfigPortal() { +void WiFiManager::setupConfigPortal() +{ DEBUG_WM(F("Starting Web Portal")); @@ -441,32 +523,34 @@ void WiFiManager::setupConfigPortal() { /* Setup the DNS server redirecting all the domains to the apIP */ dnsServer->setErrorReplyCode(DNSReplyCode::NoError); // DEBUG_WM("dns server started port: ",DNS_PORT); - DEBUG_WM(DEBUG_DEV,"dns server started with ip: ",WiFi.softAPIP()); + DEBUG_WM(DEBUG_DEV, "dns server started with ip: ", WiFi.softAPIP()); dnsServer->start(DNS_PORT, F("*"), WiFi.softAPIP()); /* Setup httpd callbacks, web pages: root, wifi config pages, SO captive portal detectors and not found. */ - server->on(String(FPSTR(R_root)).c_str(), std::bind(&WiFiManager::handleRoot, this)); - server->on(String(FPSTR(R_wifi)).c_str(), std::bind(&WiFiManager::handleWifi, this, true)); + server->on(String(FPSTR(R_root)).c_str(), std::bind(&WiFiManager::handleRoot, this)); + server->on(String(FPSTR(R_wifi)).c_str(), std::bind(&WiFiManager::handleWifi, this, true)); server->on(String(FPSTR(R_wifinoscan)).c_str(), std::bind(&WiFiManager::handleWifi, this, false)); - server->on(String(FPSTR(R_wifisave)).c_str(), std::bind(&WiFiManager::handleWifiSave, this)); - server->on(String(FPSTR(R_info)).c_str(), std::bind(&WiFiManager::handleInfo, this)); - server->on(String(FPSTR(R_param)).c_str(), std::bind(&WiFiManager::handleParam, this)); - server->on(String(FPSTR(R_paramsave)).c_str(), std::bind(&WiFiManager::handleParamSave, this)); - server->on(String(FPSTR(R_restart)).c_str(), std::bind(&WiFiManager::handleReset, this)); - server->on(String(FPSTR(R_exit)).c_str(), std::bind(&WiFiManager::handleExit, this)); - server->on(String(FPSTR(R_close)).c_str(), std::bind(&WiFiManager::handleClose, this)); - server->on(String(FPSTR(R_erase)).c_str(), std::bind(&WiFiManager::handleErase, this, false)); - server->on(String(FPSTR(R_status)).c_str(), std::bind(&WiFiManager::handleWiFiStatus, this)); - server->onNotFound (std::bind(&WiFiManager::handleNotFound, this)); - - server->begin(); // Web server start - DEBUG_WM(DEBUG_VERBOSE,F("HTTP server started")); + server->on(String(FPSTR(R_wifisave)).c_str(), std::bind(&WiFiManager::handleWifiSave, this)); + server->on(String(FPSTR(R_info)).c_str(), std::bind(&WiFiManager::handleInfo, this)); + server->on(String(FPSTR(R_param)).c_str(), std::bind(&WiFiManager::handleParam, this)); + server->on(String(FPSTR(R_paramsave)).c_str(), std::bind(&WiFiManager::handleParamSave, this)); + server->on(String(FPSTR(R_restart)).c_str(), std::bind(&WiFiManager::handleReset, this)); + server->on(String(FPSTR(R_exit)).c_str(), std::bind(&WiFiManager::handleExit, this)); + server->on(String(FPSTR(R_close)).c_str(), std::bind(&WiFiManager::handleClose, this)); + server->on(String(FPSTR(R_erase)).c_str(), std::bind(&WiFiManager::handleErase, this, false)); + server->on(String(FPSTR(R_status)).c_str(), std::bind(&WiFiManager::handleWiFiStatus, this)); + server->onNotFound(std::bind(&WiFiManager::handleNotFound, this)); - if(_preloadwifiscan) WiFi_scanNetworks(true,true); // preload wifiscan , async + server->begin(); // Web server start + DEBUG_WM(DEBUG_VERBOSE, F("HTTP server started")); + + if (_preloadwifiscan) + WiFi_scanNetworks(true, true); // preload wifiscan , async } -boolean WiFiManager::startConfigPortal() { - String ssid = _wifissidprefix + "_" + String(WIFI_getChipId(),HEX); +boolean WiFiManager::startConfigPortal() +{ + String ssid = _wifissidprefix + "_" + String(WIFI_getChipId(), HEX); return startConfigPortal(ssid.c_str(), NULL); } @@ -477,25 +561,30 @@ boolean WiFiManager::startConfigPortal() { * @param {[type]} char const *apPassword [description] * @return {[type]} [description] */ -boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) { +boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) +{ _begin(); //setup AP - _apName = apName; // @todo check valid apname ? + _apName = apName; // @todo check valid apname ? _apPassword = apPassword; - - if(_apName == "") _apName = _wifissidprefix + "_" + String(WIFI_getChipId(),HEX); - if(!validApPassword()) return false; - + + if (_apName == "") + _apName = _wifissidprefix + "_" + String(WIFI_getChipId(), HEX); + if (!validApPassword()) + return false; + // HANDLE issues with STA connections, shutdown sta if not connected, or else this will hang channel scanning and softap will not respond // @todo sometimes still cannot connect to AP for no known reason, no events in log either - if(_disableSTA || (!WiFi.isConnected() && _disableSTAConn)){ - // this fixes most ap problems, however, simply doing mode(WIFI_AP) does not work if sta connection is hanging, must `wifi_station_disconnect` + if (_disableSTA || (!WiFi.isConnected() && _disableSTAConn)) + { + // this fixes most ap problems, however, simply doing mode(WIFI_AP) does not work if sta connection is hanging, must `wifi_station_disconnect` WiFi_Disconnect(); WiFi_enableSTA(false); - DEBUG_WM(DEBUG_VERBOSE,F("Disabling STA")); + DEBUG_WM(DEBUG_VERBOSE, F("Disabling STA")); } - else { + else + { // @todo even if sta is connected, it is possible that softap connections will fail, IOS says "invalid password", windows says "cannot connect to this network" researching WiFi_enableSTA(true); } @@ -508,26 +597,29 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo _configPortalStart = millis(); // start access point - DEBUG_WM(DEBUG_VERBOSE,F("Enabling AP")); + DEBUG_WM(DEBUG_VERBOSE, F("Enabling AP")); startAP(); WiFiSetCountry(); // init configportal - DEBUG_WM(DEBUG_DEV,F("setupConfigPortal")); + DEBUG_WM(DEBUG_DEV, F("setupConfigPortal")); setupConfigPortal(); - if(!_configPortalIsBlocking){ - DEBUG_WM(DEBUG_VERBOSE,F("Config Portal Running, non blocking/processing")); + if (!_configPortalIsBlocking) + { + DEBUG_WM(DEBUG_VERBOSE, F("Config Portal Running, non blocking/processing")); return result; } - DEBUG_WM(DEBUG_VERBOSE,F("Config Portal Running, blocking, waiting for clients...")); + DEBUG_WM(DEBUG_VERBOSE, F("Config Portal Running, blocking, waiting for clients...")); // blocking loop waiting for config - while(1){ + while (1) + { // if timed out or abort, break - if(configPortalHasTimeout() || abort){ - DEBUG_WM(DEBUG_DEV,F("configportal abort")); + if (configPortalHasTimeout() || abort) + { + DEBUG_WM(DEBUG_DEV, F("configportal abort")); stopConfigPortal(); result = abort ? portalAbortResult : portalTimeoutResult; // false, false break; @@ -536,15 +628,16 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo state = processConfigPortal(); // status change, break - if(state != WL_IDLE_STATUS){ - result = (state == WL_CONNECTED); // true if connected - break; + if (state != WL_IDLE_STATUS) + { + result = (state == WL_CONNECTED); // true if connected + break; } yield(); // watchdog } - DEBUG_WM(DEBUG_NOTIFY,F("config portal exiting")); + DEBUG_WM(DEBUG_NOTIFY, F("config portal exiting")); return result; } @@ -553,70 +646,82 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswo * @access public * @return {[type]} [description] */ -boolean WiFiManager::process(){ - if(webPortalActive || (configPortalActive && !_configPortalIsBlocking)){ - uint8_t state = processConfigPortal(); - return state == WL_CONNECTED; - } - return false; +boolean WiFiManager::process() +{ + if (webPortalActive || (configPortalActive && !_configPortalIsBlocking)) + { + uint8_t state = processConfigPortal(); + return state == WL_CONNECTED; + } + return false; } //using esp enums returns for now, should be fine -uint8_t WiFiManager::processConfigPortal(){ - //DNS handler - dnsServer->processNextRequest(); - //HTTP handler - server->handleClient(); +uint8_t WiFiManager::processConfigPortal() +{ + //DNS handler + dnsServer->processNextRequest(); + //HTTP handler + server->handleClient(); - // Waiting for save... - if(connect) { - connect = false; - DEBUG_WM(DEBUG_VERBOSE,F("process connect")); - if(_enableCaptivePortal) delay(_cpclosedelay); // keeps the captiveportal from closing to fast. + // Waiting for save... + if (connect) + { + connect = false; + DEBUG_WM(DEBUG_VERBOSE, F("process connect")); + if (_enableCaptivePortal) + delay(_cpclosedelay); // keeps the captiveportal from closing to fast. - // skip wifi if no ssid - if(_ssid == ""){ - DEBUG_WM(DEBUG_VERBOSE,F("No ssid, skipping wifi")); - } - else{ - // attempt sta connection to submitted _ssid, _pass - if (connectWifi(_ssid, _pass) == WL_CONNECTED) { - - DEBUG_WM(F("Connect to new AP [SUCCESS]")); - DEBUG_WM(F("Got IP Address:")); - DEBUG_WM(WiFi.localIP()); + // skip wifi if no ssid + if (_ssid == "") + { + DEBUG_WM(DEBUG_VERBOSE, F("No ssid, skipping wifi")); + } + else + { + // attempt sta connection to submitted _ssid, _pass + if (connectWifi(_ssid, _pass) == WL_CONNECTED) + { - if ( _savecallback != NULL) { - _savecallback(); - } - stopConfigPortal(); - return WL_CONNECTED; // CONNECT SUCCESS - } - DEBUG_WM(DEBUG_ERROR,F("[ERROR] Connect to new AP Failed")); - } - - if (_shouldBreakAfterConfig) { - // do save callback - // @todo this is more of an exiting callback than a save, clarify when this should actually occur - // confirm or verify data was saved to make this more accurate callback - if ( _savecallback != NULL) { + DEBUG_WM(F("Connect to new AP [SUCCESS]")); + DEBUG_WM(F("Got IP Address:")); + DEBUG_WM(WiFi.localIP()); + + if (_savecallback != NULL) + { _savecallback(); } stopConfigPortal(); - return WL_CONNECT_FAILED; // CONNECT FAIL - } - else{ - // clear save strings - _ssid = ""; - _pass = ""; - // if connect fails, turn sta off to stabilize AP - WiFi_Disconnect(); - WiFi_enableSTA(false); - DEBUG_WM(DEBUG_VERBOSE,F("Disabling STA")); + return WL_CONNECTED; // CONNECT SUCCESS } + DEBUG_WM(DEBUG_ERROR, F("[ERROR] Connect to new AP Failed")); } - return WL_IDLE_STATUS; + if (_shouldBreakAfterConfig) + { + // do save callback + // @todo this is more of an exiting callback than a save, clarify when this should actually occur + // confirm or verify data was saved to make this more accurate callback + if (_savecallback != NULL) + { + _savecallback(); + } + stopConfigPortal(); + return WL_CONNECT_FAILED; // CONNECT FAIL + } + else + { + // clear save strings + _ssid = ""; + _pass = ""; + // if connect fails, turn sta off to stabilize AP + WiFi_Disconnect(); + WiFi_enableSTA(false); + DEBUG_WM(DEBUG_VERBOSE, F("Disabling STA")); + } + } + + return WL_IDLE_STATUS; } /** @@ -624,8 +729,10 @@ uint8_t WiFiManager::processConfigPortal(){ * @access public * @return {[type]} [description] */ -boolean WiFiManager::stopConfigPortal(){ - if(webPortalActive) return false; +boolean WiFiManager::stopConfigPortal() +{ + if (webPortalActive) + return false; //DNS handler dnsServer->processNextRequest(); @@ -640,26 +747,29 @@ boolean WiFiManager::stopConfigPortal(){ WiFi.scanDelete(); // free wifi scan results - if(!configPortalActive) return false; + if (!configPortalActive) + return false; // turn off AP // @todo bug workaround // https://github.com/esp8266/Arduino/issues/3793 // [APdisconnect] set_config failed! *WM: disconnect configportal - softAPdisconnect failed // still no way to reproduce reliably - DEBUG_WM(DEBUG_VERBOSE,F("disconnect configportal")); + DEBUG_WM(DEBUG_VERBOSE, F("disconnect configportal")); bool ret = false; ret = WiFi.softAPdisconnect(false); - if(!ret)DEBUG_WM(DEBUG_ERROR,F("[ERROR] disconnect configportal - softAPdisconnect FAILED")); + if (!ret) + DEBUG_WM(DEBUG_ERROR, F("[ERROR] disconnect configportal - softAPdisconnect FAILED")); delay(1000); - DEBUG_WM(DEBUG_VERBOSE,"restoring usermode",getModeString(_usermode)); + DEBUG_WM(DEBUG_VERBOSE, "restoring usermode", getModeString(_usermode)); WiFi_Mode(_usermode); // restore users wifi mode, BUG https://github.com/esp8266/Arduino/issues/4372 - if(WiFi.status()==WL_IDLE_STATUS){ + if (WiFi.status() == WL_IDLE_STATUS) + { WiFi.reconnect(); // restart wifi since we disconnected it in startconfigportal - DEBUG_WM(DEBUG_VERBOSE,"WiFi Reconnect, was idle"); + DEBUG_WM(DEBUG_VERBOSE, "WiFi Reconnect, was idle"); } - DEBUG_WM(DEBUG_VERBOSE,"wifi status:",getWLStatusString(WiFi.status())); - DEBUG_WM(DEBUG_VERBOSE,"wifi mode:",getModeString(WiFi.getMode())); + DEBUG_WM(DEBUG_VERBOSE, "wifi status:", getWLStatusString(WiFi.status())); + DEBUG_WM(DEBUG_VERBOSE, "wifi mode:", getModeString(WiFi.getMode())); configPortalActive = false; _end(); return ret; @@ -668,53 +778,63 @@ boolean WiFiManager::stopConfigPortal(){ // @todo refactor this up into seperate functions // one for connecting to flash , one for new client // clean up, flow is convoluted, and causes bugs -uint8_t WiFiManager::connectWifi(String ssid, String pass) { - DEBUG_WM(DEBUG_VERBOSE,F("Connecting as wifi client...")); - +uint8_t WiFiManager::connectWifi(String ssid, String pass) +{ + DEBUG_WM(DEBUG_VERBOSE, F("Connecting as wifi client...")); + uint8_t connRes = (uint8_t)WL_NO_SSID_AVAIL; setSTAConfig(); //@todo catch failures in set_config - + // make sure sta is on before `begin` so it does not call enablesta->mode while persistent is ON ( which would save WM AP state to eeprom !) - if(_cleanConnect) WiFi_Disconnect(); // disconnect before begin, in case anything is hung, this causes a 2 seconds delay for connect + if (_cleanConnect) + WiFi_Disconnect(); // disconnect before begin, in case anything is hung, this causes a 2 seconds delay for connect // @todo find out what status is when this is needed, can we detect it and handle it, say in between states or idle_status // if ssid argument provided connect to that - if (ssid != "") { - wifiConnectNew(ssid,pass); - if(_saveTimeout > 0){ + if (ssid != "") + { + wifiConnectNew(ssid, pass); + if (_saveTimeout > 0) + { connRes = waitForConnectResult(_saveTimeout); // use default save timeout for saves to prevent bugs in esp->waitforconnectresult loop - } - else { - connRes = waitForConnectResult(0); + } + else + { + connRes = waitForConnectResult(0); } } - else { + else + { // connect using saved ssid if there is one - if (WiFi_hasAutoConnect()) { + if (WiFi_hasAutoConnect()) + { wifiConnectDefault(); connRes = waitForConnectResult(); } - else { + else + { DEBUG_WM(F("No saved credentials, skipping wifi")); } } - DEBUG_WM(DEBUG_VERBOSE,F("Connection result:"),getWLStatusString(connRes)); + DEBUG_WM(DEBUG_VERBOSE, F("Connection result:"), getWLStatusString(connRes)); // WPS enabled? https://github.com/esp8266/Arduino/pull/4889 #ifdef NO_EXTRA_4K_HEAP // do WPS, if WPS options enabled and not connected and no password was supplied // @todo this seems like wrong place for this, is it a fallback or option? - if (_tryWPS && connRes != WL_CONNECTED && pass == "") { + if (_tryWPS && connRes != WL_CONNECTED && pass == "") + { startWPS(); // should be connected at the end of WPS connRes = waitForConnectResult(); } #endif - if(connRes != WL_SCAN_COMPLETED){ + if (connRes != WL_SCAN_COMPLETED) + { updateConxResult(connRes); } @@ -728,14 +848,16 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) { * @param String pass * @return bool success */ -bool WiFiManager::wifiConnectNew(String ssid, String pass){ +bool WiFiManager::wifiConnectNew(String ssid, String pass) +{ bool ret = false; - DEBUG_WM(F("Connecting to new AP:"),ssid); - WiFi_enableSTA(true,storeSTAmode); // storeSTAmode will also toggle STA on in default opmode (persistent) if true (default) + DEBUG_WM(F("Connecting to new AP:"), ssid); + 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()); WiFi.persistent(false); - if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi begin failed"); + if (!ret) + DEBUG_WM(DEBUG_ERROR, "[ERROR] wifi begin failed"); return ret; } @@ -744,68 +866,84 @@ bool WiFiManager::wifiConnectNew(String ssid, String pass){ * @since dev * @return bool success */ -bool WiFiManager::wifiConnectDefault(){ +bool WiFiManager::wifiConnectDefault() +{ bool ret = false; - DEBUG_WM(F("Connecting to saved AP:"),WiFi_SSID()); - ret = WiFi_enableSTA(true,storeSTAmode); - if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi enableSta failed"); + DEBUG_WM(F("Connecting to saved AP:"), WiFi_SSID()); + ret = WiFi_enableSTA(true, storeSTAmode); + if (!ret) + DEBUG_WM(DEBUG_ERROR, "[ERROR] wifi enableSta failed"); ret = WiFi.begin(); - if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi begin failed"); + if (!ret) + DEBUG_WM(DEBUG_ERROR, "[ERROR] wifi begin failed"); return ret; } - /** * set sta config if set * @since $dev * @return bool success */ -bool WiFiManager::setSTAConfig(){ +bool WiFiManager::setSTAConfig() +{ bool ret = true; - if (_sta_static_ip) { - if(_sta_static_dns) { - DEBUG_WM(DEBUG_VERBOSE,F("Custom STA IP/GW/Subnet/DNS")); + if (_sta_static_ip) + { + if (_sta_static_dns) + { + DEBUG_WM(DEBUG_VERBOSE, F("Custom STA IP/GW/Subnet/DNS")); ret = WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn, _sta_static_dns); } - else { - DEBUG_WM(DEBUG_VERBOSE,F("Custom STA IP/GW/Subnet")); + else + { + DEBUG_WM(DEBUG_VERBOSE, F("Custom STA IP/GW/Subnet")); ret = WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn); } - if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi config failed"); - else DEBUG_WM(F("STA IP set:"),WiFi.localIP()); - } else { - DEBUG_WM(DEBUG_VERBOSE,F("setSTAConfig static ip not set")); + if (!ret) + DEBUG_WM(DEBUG_ERROR, "[ERROR] wifi config failed"); + else + DEBUG_WM(F("STA IP set:"), WiFi.localIP()); + } + else + { + DEBUG_WM(DEBUG_VERBOSE, F("setSTAConfig static ip not set")); } return ret; } // @todo change to getLastFailureReason and do not touch conxresult -void WiFiManager::updateConxResult(uint8_t status){ +void WiFiManager::updateConxResult(uint8_t status) +{ // hack in wrong password detection _lastconxresult = status; - #ifdef ESP8266 - if(_lastconxresult == WL_CONNECT_FAILED){ - if(wifi_station_get_connect_status() == STATION_WRONG_PASSWORD){ - _lastconxresult = WL_STATION_WRONG_PASSWORD; - } - } - #elif defined(ESP32) - // if(_lastconxresult == WL_CONNECT_FAILED){ - if(_lastconxresult == WL_CONNECT_FAILED || _lastconxresult == WL_DISCONNECTED){ - DEBUG_WM(DEBUG_DEV,"lastconxresulttmp:",getWLStatusString(_lastconxresulttmp)); - if(_lastconxresulttmp != WL_IDLE_STATUS){ - _lastconxresult = _lastconxresulttmp; - // _lastconxresulttmp = WL_IDLE_STATUS; - } - } - #endif - DEBUG_WM(DEBUG_DEV,"lastconxresult:",getWLStatusString(_lastconxresult)); +#ifdef ESP8266 + if (_lastconxresult == WL_CONNECT_FAILED) + { + if (wifi_station_get_connect_status() == STATION_WRONG_PASSWORD) + { + _lastconxresult = WL_STATION_WRONG_PASSWORD; + } + } +#elif defined(ESP32) + // if(_lastconxresult == WL_CONNECT_FAILED){ + if (_lastconxresult == WL_CONNECT_FAILED || _lastconxresult == WL_DISCONNECTED) + { + DEBUG_WM(DEBUG_DEV, "lastconxresulttmp:", getWLStatusString(_lastconxresulttmp)); + if (_lastconxresulttmp != WL_IDLE_STATUS) + { + _lastconxresult = _lastconxresulttmp; + // _lastconxresulttmp = WL_IDLE_STATUS; + } + } +#endif + DEBUG_WM(DEBUG_DEV, "lastconxresult:", getWLStatusString(_lastconxresult)); } - -uint8_t WiFiManager::waitForConnectResult() { - if(_connectTimeout > 0) DEBUG_WM(DEBUG_VERBOSE,_connectTimeout,F("ms connectTimeout set")); +uint8_t WiFiManager::waitForConnectResult() +{ + if (_connectTimeout > 0) + DEBUG_WM(DEBUG_VERBOSE, _connectTimeout, F("ms connectTimeout set")); return waitForConnectResult(_connectTimeout); } @@ -814,23 +952,27 @@ uint8_t WiFiManager::waitForConnectResult() { * @param uint16_t timeout in seconds * @return uint8_t WL Status */ -uint8_t WiFiManager::waitForConnectResult(uint16_t timeout) { - if (timeout == 0){ +uint8_t WiFiManager::waitForConnectResult(uint16_t timeout) +{ + if (timeout == 0) + { DEBUG_WM(F("connectTimeout not set, ESP waitForConnectResult...")); return WiFi.waitForConnectResult(); } unsigned long timeoutmillis = millis() + timeout; - DEBUG_WM(DEBUG_VERBOSE,timeout,F("ms timeout, waiting for connect...")); + DEBUG_WM(DEBUG_VERBOSE, timeout, F("ms timeout, waiting for connect...")); uint8_t status = WiFi.status(); - - while(millis() < timeoutmillis) { + + while (millis() < timeoutmillis) + { status = WiFi.status(); // @todo detect additional states, connect happens, then dhcp then get ip, there is some delay here, make sure not to timeout if waiting on IP - if (status == WL_CONNECTED || status == WL_CONNECT_FAILED) { + if (status == WL_CONNECTED || status == WL_CONNECT_FAILED) + { return status; } - DEBUG_WM (DEBUG_VERBOSE,F(".")); + DEBUG_WM(DEBUG_VERBOSE, F(".")); delay(100); } return status; @@ -838,18 +980,20 @@ uint8_t WiFiManager::waitForConnectResult(uint16_t timeout) { // WPS enabled? https://github.com/esp8266/Arduino/pull/4889 #ifdef NO_EXTRA_4K_HEAP -void WiFiManager::startWPS() { +void WiFiManager::startWPS() +{ DEBUG_WM(F("START WPS")); - #ifdef ESP8266 - WiFi.beginWPSConfig(); - #else - // @todo - #endif +#ifdef ESP8266 + WiFi.beginWPSConfig(); +#else + // @todo +#endif DEBUG_WM(F("END WPS")); } #endif -String WiFiManager::getHTTPHead(String title){ +String WiFiManager::getHTTPHead(String title) +{ String page; page += FPSTR(HTTP_HEAD_START); page.replace(FPSTR(T_v), title); @@ -857,14 +1001,16 @@ String WiFiManager::getHTTPHead(String title){ page += FPSTR(HTTP_STYLE); page += _customHeadElement; - if(_bodyClass != ""){ + if (_bodyClass != "") + { String p = FPSTR(HTTP_HEAD_END); p.replace(FPSTR(T_c), _bodyClass); // add class str page += p; } - else { + else + { page += FPSTR(HTTP_HEAD_END); - } + } return page; } @@ -872,20 +1018,23 @@ String WiFiManager::getHTTPHead(String title){ /** * HTTPD handler for page requests */ -void WiFiManager::handleRequest() { +void WiFiManager::handleRequest() +{ _webPortalAccessed = millis(); } /** * HTTPD CALLBACK root or redirect to captive portal */ -void WiFiManager::handleRoot() { - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Root")); - if (captivePortal()) return; // If captive portal redirect instead of displaying the page +void WiFiManager::handleRoot() +{ + DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP Root")); + if (captivePortal()) + return; // If captive portal redirect instead of displaying the page handleRequest(); String page = getHTTPHead(FPSTR(S_options)); // @token options - String str = FPSTR(HTTP_ROOT_MAIN); - str.replace(FPSTR(T_v),configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading + String str = FPSTR(HTTP_ROOT_MAIN); + str.replace(FPSTR(T_v), configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading page += str; page += FPSTR(HTTP_PORTAL_OPTIONS); page += getMenuOut(); @@ -894,8 +1043,9 @@ void WiFiManager::handleRoot() { server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); - // server->close(); // testing reliability fix for content length mismatches during mutiple flood hits WiFi_scanNetworks(); // preload wifiscan - if(_preloadwifiscan) WiFi_scanNetworks((unsigned)20000,true); // preload wifiscan throttled, async + // server->close(); // testing reliability fix for content length mismatches during mutiple flood hits WiFi_scanNetworks(); // preload wifiscan + if (_preloadwifiscan) + WiFi_scanNetworks((unsigned)20000, true); // preload wifiscan throttled, async // @todo buggy, captive portals make a query on every page load, causing this to run every time in addition to the real page load // I dont understand why, when you are already in the captive portal, I guess they want to know that its still up and not done or gone // if we can detect these and ignore them that would be great, since they come from the captive portal redirect maybe there is a refferer @@ -904,13 +1054,15 @@ void WiFiManager::handleRoot() { /** * HTTPD CALLBACK Wifi config page handler */ -void WiFiManager::handleWifi(boolean scan) { - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Wifi")); +void WiFiManager::handleWifi(boolean scan) +{ + DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP Wifi")); handleRequest(); String page = getHTTPHead(FPSTR(S_titlewifi)); // @token titlewifi - if (scan) { + if (scan) + { // DEBUG_WM(DEBUG_DEV,"refresh flag:",server->hasArg(F("refresh"))); - WiFi_scanNetworks(server->hasArg(F("refresh")),false); //wifiscan, force if arg refresh + WiFi_scanNetworks(server->hasArg(F("refresh")), false); //wifiscan, force if arg refresh page += getScanItemOut(); } String pitem = ""; @@ -925,7 +1077,8 @@ void WiFiManager::handleWifi(boolean scan) { page += getStaticOut(); page += FPSTR(HTTP_FORM_WIFI_END); - if(_paramsInWifi && _paramsCount>0){ + if (_paramsInWifi && _paramsCount > 0) + { page += FPSTR(HTTP_FORM_PARAM_HEAD); page += getParamOut(); } @@ -938,14 +1091,15 @@ void WiFiManager::handleWifi(boolean scan) { server->send(200, FPSTR(HTTP_HEAD_CT), page); // server->close(); // testing reliability fix for content length mismatches during mutiple flood hits - DEBUG_WM(DEBUG_DEV,F("Sent config page")); + DEBUG_WM(DEBUG_DEV, F("Sent config page")); } /** * HTTPD CALLBACK Wifi param page handler */ -void WiFiManager::handleParam(){ - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Param")); +void WiFiManager::handleParam() +{ + DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP Param")); handleRequest(); String page = getHTTPHead(FPSTR(S_titleparam)); // @token titlewifi @@ -963,15 +1117,17 @@ void WiFiManager::handleParam(){ server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); - DEBUG_WM(DEBUG_DEV,F("Sent param page")); + DEBUG_WM(DEBUG_DEV, F("Sent param page")); } +String WiFiManager::getMenuOut() +{ + String page; -String WiFiManager::getMenuOut(){ - String page; - - for(auto menuId :_menuIds ){ - if(((String)menuId == "param") && (_paramsCount == 0)) continue; // no params set, omit params + for (auto menuId : _menuIds) + { + if (((String)menuId == "param") && (_paramsCount == 0)) + continue; // no params set, omit params page += HTTP_PORTAL_MENU[menuId]; } @@ -983,207 +1139,253 @@ String WiFiManager::getMenuOut(){ // WiFi_scanNetworks(force); // } -void WiFiManager::WiFi_scanComplete(int networksFound){ +void WiFiManager::WiFi_scanComplete(int networksFound) +{ _lastscan = millis(); _numNetworks = networksFound; - 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(DEBUG_VERBOSE, F("WiFi Scan ASYNC completed"), "in " + (String)(_lastscan - _startscan) + " ms"); + DEBUG_WM(DEBUG_VERBOSE, F("WiFi Scan ASYNC found:"), _numNetworks); } -bool WiFiManager::WiFi_scanNetworks(){ - return WiFi_scanNetworks(false,false); +bool WiFiManager::WiFi_scanNetworks() +{ + return WiFi_scanNetworks(false, false); } -bool WiFiManager::WiFi_scanNetworks(unsigned int cachetime,bool async){ - return WiFi_scanNetworks(millis()-_lastscan > cachetime,async); +bool WiFiManager::WiFi_scanNetworks(unsigned int cachetime, bool async) +{ + return WiFi_scanNetworks(millis() - _lastscan > cachetime, async); } -bool WiFiManager::WiFi_scanNetworks(unsigned int cachetime){ - return WiFi_scanNetworks(millis()-_lastscan > cachetime,false); +bool WiFiManager::WiFi_scanNetworks(unsigned int cachetime) +{ + return WiFi_scanNetworks(millis() - _lastscan > cachetime, false); } -bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ - // DEBUG_WM(DEBUG_DEV,"scanNetworks async:",async == true); - // DEBUG_WM(DEBUG_DEV,_numNetworks,(millis()-_lastscan )); - // DEBUG_WM(DEBUG_DEV,"scanNetworks force:",force == true); - if(force || _numNetworks == 0 || (millis()-_lastscan > 60000)){ - int8_t res; - _startscan = millis(); - if(async){ - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); - #ifdef ESP8266 - #ifndef WM_NOASYNC // no async available < 2.4.0 - using namespace std::placeholders; // for `_1` - WiFi.scanNetworksAsync(std::bind(&WiFiManager::WiFi_scanComplete,this,_1)); - #else - res = WiFi.scanNetworks(); - #endif - #else - res = WiFi.scanNetworks(true); - #endif - return false; +bool WiFiManager::WiFi_scanNetworks(bool force, bool async) +{ + // DEBUG_WM(DEBUG_DEV,"scanNetworks async:",async == true); + // DEBUG_WM(DEBUG_DEV,_numNetworks,(millis()-_lastscan )); + // DEBUG_WM(DEBUG_DEV,"scanNetworks force:",force == true); + if (force || _numNetworks == 0 || (millis() - _lastscan > 60000)) + { + int8_t res; + _startscan = millis(); + if (async) + { + DEBUG_WM(DEBUG_VERBOSE, F("WiFi Scan ASYNC started")); +#ifdef ESP8266 +#ifndef WM_NOASYNC // no async available < 2.4.0 + using namespace std::placeholders; // for `_1` + WiFi.scanNetworksAsync(std::bind(&WiFiManager::WiFi_scanComplete, this, _1)); +#else + res = WiFi.scanNetworks(); +#endif +#else + res = WiFi.scanNetworks(true); +#endif + return false; + } + else + { + res = WiFi.scanNetworks(); + } + if (res == WIFI_SCAN_FAILED) + DEBUG_WM(DEBUG_ERROR, "[ERROR] scan failed"); + else if (res == WIFI_SCAN_RUNNING) + { + DEBUG_WM(DEBUG_ERROR, "[ERROR] scan waiting"); + while (WiFi.scanComplete() == WIFI_SCAN_RUNNING) + { + DEBUG_WM(DEBUG_ERROR, "."); + delay(100); } - else{ - res = WiFi.scanNetworks(); - } - if(res == WIFI_SCAN_FAILED) DEBUG_WM(DEBUG_ERROR,"[ERROR] scan failed"); - else if(res == WIFI_SCAN_RUNNING){ - DEBUG_WM(DEBUG_ERROR,"[ERROR] scan waiting"); - while(WiFi.scanComplete() == WIFI_SCAN_RUNNING){ - DEBUG_WM(DEBUG_ERROR,"."); - delay(100); - } - _numNetworks = WiFi.scanComplete(); - } - else if(res >=0 ) _numNetworks = res; - _lastscan = millis(); - DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan completed"), "in "+(String)(_lastscan - _startscan)+" ms"); - return true; - } else DEBUG_WM(DEBUG_VERBOSE,"Scan is cached",(String)(millis()-_lastscan )+" ms ago"); - return false; + _numNetworks = WiFi.scanComplete(); + } + else if (res >= 0) + _numNetworks = res; + _lastscan = millis(); + DEBUG_WM(DEBUG_VERBOSE, F("WiFi Scan completed"), "in " + (String)(_lastscan - _startscan) + " ms"); + return true; + } + else + DEBUG_WM(DEBUG_VERBOSE, "Scan is cached", (String)(millis() - _lastscan) + " ms ago"); + return false; } -String WiFiManager::WiFiManager::getScanItemOut(){ - String page; +String WiFiManager::WiFiManager::getScanItemOut() +{ + String page; - if(!_numNetworks) WiFi_scanNetworks(); // scan in case this gets called before any scans + if (!_numNetworks) + WiFi_scanNetworks(); // scan in case this gets called before any scans - int n = _numNetworks; - if (n == 0) { - DEBUG_WM(F("No networks found")); - page += FPSTR(S_nonetworks); // @token nonetworks - } - else { - DEBUG_WM(n,F("networks found")); - //sort networks - int indices[n]; - for (int i = 0; i < n; i++) { - indices[i] = i; - } + int n = _numNetworks; + if (n == 0) + { + DEBUG_WM(F("No networks found")); + page += FPSTR(S_nonetworks); // @token nonetworks + } + else + { + DEBUG_WM(n, F("networks found")); + //sort networks + int indices[n]; + for (int i = 0; i < n; i++) + { + indices[i] = i; + } - // RSSI SORT - for (int i = 0; i < n; i++) { - for (int j = i + 1; j < n; j++) { - if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) { - std::swap(indices[i], indices[j]); - } + // RSSI SORT + for (int i = 0; i < n; i++) + { + for (int j = i + 1; j < n; j++) + { + if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) + { + std::swap(indices[i], indices[j]); } } + } - /* test std:sort + /* test std:sort std::sort(indices, indices + n, [](const int & a, const int & b) -> bool { return WiFi.RSSI(a) > WiFi.RSSI(b); }); */ - // remove duplicates ( must be RSSI sorted ) - if (_removeDuplicateAPs) { - String cssid; - for (int i = 0; i < n; i++) { - if (indices[i] == -1) continue; - cssid = WiFi.SSID(indices[i]); - for (int j = i + 1; j < n; j++) { - if (cssid == WiFi.SSID(indices[j])) { - DEBUG_WM(DEBUG_VERBOSE,F("DUP AP:"),WiFi.SSID(indices[j])); - indices[j] = -1; // set dup aps to index -1 - } + // remove duplicates ( must be RSSI sorted ) + if (_removeDuplicateAPs) + { + String cssid; + for (int i = 0; i < n; i++) + { + if (indices[i] == -1) + continue; + cssid = WiFi.SSID(indices[i]); + for (int j = i + 1; j < n; j++) + { + if (cssid == WiFi.SSID(indices[j])) + { + DEBUG_WM(DEBUG_VERBOSE, F("DUP AP:"), WiFi.SSID(indices[j])); + indices[j] = -1; // set dup aps to index -1 } } } - - // token precheck, to speed up replacements on large ap lists - String HTTP_ITEM_STR = FPSTR(HTTP_ITEM); - - // toggle icons with percentage - HTTP_ITEM_STR.replace("{qp}", FPSTR(HTTP_ITEM_QP)); - HTTP_ITEM_STR.replace("{h}",_scanDispOptions ? "" : "h"); - HTTP_ITEM_STR.replace("{qi}", FPSTR(HTTP_ITEM_QI)); - HTTP_ITEM_STR.replace("{h}",_scanDispOptions ? "h" : ""); - - // set token precheck flags - bool tok_r = HTTP_ITEM_STR.indexOf(FPSTR(T_r)) > 0; - bool tok_R = HTTP_ITEM_STR.indexOf(FPSTR(T_R)) > 0; - bool tok_e = HTTP_ITEM_STR.indexOf(FPSTR(T_e)) > 0; - bool tok_q = HTTP_ITEM_STR.indexOf(FPSTR(T_q)) > 0; - bool tok_i = HTTP_ITEM_STR.indexOf(FPSTR(T_i)) > 0; - - //display networks in page - for (int i = 0; i < n; i++) { - if (indices[i] == -1) continue; // skip dups - - DEBUG_WM(DEBUG_VERBOSE,F("AP: "),(String)WiFi.RSSI(indices[i]) + " " + (String)WiFi.SSID(indices[i])); - - int rssiperc = getRSSIasQuality(WiFi.RSSI(indices[i])); - uint8_t enc_type = WiFi.encryptionType(indices[i]); - - if (_minimumQuality == -1 || _minimumQuality < rssiperc) { - String item = HTTP_ITEM_STR; - item.replace(FPSTR(T_v), htmlEntities(WiFi.SSID(indices[i]))); // ssid no encoding - if(tok_e) item.replace(FPSTR(T_e), encryptionTypeStr(enc_type)); - if(tok_r) item.replace(FPSTR(T_r), (String)rssiperc); // rssi percentage 0-100 - if(tok_R) item.replace(FPSTR(T_R), (String)WiFi.RSSI(indices[i])); // rssi db - if(tok_q) item.replace(FPSTR(T_q), (String)round(map(rssiperc,0,100,1,4))); //quality icon 1-4 - if(tok_i){ - if (enc_type != WM_WIFIOPEN) { - item.replace(FPSTR(T_i), F("l")); - } else { - item.replace(FPSTR(T_i), ""); - } - } - //DEBUG_WM(item); - page += item; - delay(0); - } else { - DEBUG_WM(DEBUG_VERBOSE,F("Skipping , does not meet _minimumQuality")); - } - - } - page += FPSTR(HTTP_BR); } - return page; -} + // token precheck, to speed up replacements on large ap lists + String HTTP_ITEM_STR = FPSTR(HTTP_ITEM); -String WiFiManager::getIpForm(String id, String title, String value){ - String item = FPSTR(HTTP_FORM_LABEL); - item += FPSTR(HTTP_FORM_PARAM); - item.replace(FPSTR(T_i), id); - item.replace(FPSTR(T_n), id); - item.replace(FPSTR(T_p), FPSTR(T_t)); - // item.replace(FPSTR(T_p), default); - item.replace(FPSTR(T_t), title); - item.replace(FPSTR(T_l), F("15")); - item.replace(FPSTR(T_v), value); - item.replace(FPSTR(T_c), ""); - return item; -} + // toggle icons with percentage + HTTP_ITEM_STR.replace("{qp}", FPSTR(HTTP_ITEM_QP)); + HTTP_ITEM_STR.replace("{h}", _scanDispOptions ? "" : "h"); + HTTP_ITEM_STR.replace("{qi}", FPSTR(HTTP_ITEM_QI)); + HTTP_ITEM_STR.replace("{h}", _scanDispOptions ? "h" : ""); -String WiFiManager::getStaticOut(){ - String page; - if ((_staShowStaticFields || _sta_static_ip) && _staShowStaticFields>=0) { - DEBUG_WM(DEBUG_DEV,"_staShowStaticFields"); - 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 - page += getIpForm(FPSTR(S_ip),FPSTR(S_staticip),(_sta_static_ip ? _sta_static_ip.toString() : "")); // @token staticip - // WiFi.localIP().toString(); - page += getIpForm(FPSTR(S_gw),FPSTR(S_staticgw),(_sta_static_gw ? _sta_static_gw.toString() : "")); // @token staticgw - // WiFi.gatewayIP().toString(); - page += getIpForm(FPSTR(S_sn),FPSTR(S_subnet),(_sta_static_sn ? _sta_static_sn.toString() : "")); // @token subnet - // WiFi.subnetMask().toString(); + // set token precheck flags + bool tok_r = HTTP_ITEM_STR.indexOf(FPSTR(T_r)) > 0; + bool tok_R = HTTP_ITEM_STR.indexOf(FPSTR(T_R)) > 0; + bool tok_e = HTTP_ITEM_STR.indexOf(FPSTR(T_e)) > 0; + bool tok_q = HTTP_ITEM_STR.indexOf(FPSTR(T_q)) > 0; + bool tok_i = HTTP_ITEM_STR.indexOf(FPSTR(T_i)) > 0; + + //display networks in page + for (int i = 0; i < n; i++) + { + if (indices[i] == -1) + continue; // skip dups + + DEBUG_WM(DEBUG_VERBOSE, F("AP: "), (String)WiFi.RSSI(indices[i]) + " " + (String)WiFi.SSID(indices[i])); + + int rssiperc = getRSSIasQuality(WiFi.RSSI(indices[i])); + uint8_t enc_type = WiFi.encryptionType(indices[i]); + + if (_minimumQuality == -1 || _minimumQuality < rssiperc) + { + String item = HTTP_ITEM_STR; + item.replace(FPSTR(T_v), htmlEntities(WiFi.SSID(indices[i]))); // ssid no encoding + if (tok_e) + item.replace(FPSTR(T_e), encryptionTypeStr(enc_type)); + if (tok_r) + item.replace(FPSTR(T_r), (String)rssiperc); // rssi percentage 0-100 + if (tok_R) + item.replace(FPSTR(T_R), (String)WiFi.RSSI(indices[i])); // rssi db + if (tok_q) + item.replace(FPSTR(T_q), (String)round(map(rssiperc, 0, 100, 1, 4))); //quality icon 1-4 + if (tok_i) + { + if (enc_type != WM_WIFIOPEN) + { + item.replace(FPSTR(T_i), F("l")); + } + else + { + item.replace(FPSTR(T_i), ""); + } + } + //DEBUG_WM(item); + page += item; + delay(0); + } + else + { + DEBUG_WM(DEBUG_VERBOSE, F("Skipping , does not meet _minimumQuality")); + } + } + page += FPSTR(HTTP_BR); } - if((_staShowDns || _sta_static_dns) && _staShowDns>=0){ - page += getIpForm(FPSTR(S_dns),FPSTR(S_staticdns),(_sta_static_dns ? _sta_static_dns.toString() : "")); // @token dns - } - - if(page!="") page += FPSTR(HTTP_BR); // @todo remove these, use css - return page; } -String WiFiManager::getParamOut(){ +String WiFiManager::getIpForm(String id, String title, String value) +{ + String item = FPSTR(HTTP_FORM_LABEL); + item += FPSTR(HTTP_FORM_PARAM); + item.replace(FPSTR(T_i), id); + item.replace(FPSTR(T_n), id); + item.replace(FPSTR(T_p), FPSTR(T_t)); + // item.replace(FPSTR(T_p), default); + item.replace(FPSTR(T_t), title); + item.replace(FPSTR(T_l), F("15")); + item.replace(FPSTR(T_v), value); + item.replace(FPSTR(T_c), ""); + return item; +} + +String WiFiManager::getStaticOut() +{ + String page; + if ((_staShowStaticFields || _sta_static_ip) && _staShowStaticFields >= 0) + { + DEBUG_WM(DEBUG_DEV, "_staShowStaticFields"); + 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 + page += getIpForm(FPSTR(S_ip), FPSTR(S_staticip), (_sta_static_ip ? _sta_static_ip.toString() : "")); // @token staticip + // WiFi.localIP().toString(); + page += getIpForm(FPSTR(S_gw), FPSTR(S_staticgw), (_sta_static_gw ? _sta_static_gw.toString() : "")); // @token staticgw + // WiFi.gatewayIP().toString(); + page += getIpForm(FPSTR(S_sn), FPSTR(S_subnet), (_sta_static_sn ? _sta_static_sn.toString() : "")); // @token subnet + // WiFi.subnetMask().toString(); + } + + if ((_staShowDns || _sta_static_dns) && _staShowDns >= 0) + { + page += getIpForm(FPSTR(S_dns), FPSTR(S_staticdns), (_sta_static_dns ? _sta_static_dns.toString() : "")); // @token dns + } + + if (page != "") + page += FPSTR(HTTP_BR); // @todo remove these, use css + + return page; +} + +String WiFiManager::getParamOut() +{ String page; - if(_paramsCount > 0){ + if (_paramsCount > 0) + { String HTTP_PARAM_temp = FPSTR(HTTP_FORM_LABEL); HTTP_PARAM_temp += FPSTR(HTTP_FORM_PARAM); @@ -1198,41 +1400,55 @@ String WiFiManager::getParamOut(){ char parLength[5]; // add the extra parameters to the form - for (int i = 0; i < _paramsCount; i++) { - if (_params[i] == NULL || _params[i]->_length == 0) { - DEBUG_WM(DEBUG_ERROR,"[ERROR] WiFiManagerParameter is out of scope"); + for (int i = 0; i < _paramsCount; i++) + { + if (_params[i] == NULL || _params[i]->_length == 0) + { + DEBUG_WM(DEBUG_ERROR, "[ERROR] WiFiManagerParameter is out of scope"); break; } - // label before or after, this could probably be done via floats however - String pitem; - switch (_params[i]->getLabelPlacement()) { - case WFM_LABEL_BEFORE: - pitem = FPSTR(HTTP_FORM_LABEL); - pitem += FPSTR(HTTP_FORM_PARAM); - break; - case WFM_LABEL_AFTER: - pitem = FPSTR(HTTP_FORM_PARAM); - pitem += FPSTR(HTTP_FORM_LABEL); - break; - default: - // WFM_NO_LABEL - pitem = FPSTR(HTTP_FORM_PARAM); - break; + // label before or after, this could probably be done via floats however + String pitem; + switch (_params[i]->getLabelPlacement()) + { + case WFM_LABEL_BEFORE: + pitem = FPSTR(HTTP_FORM_LABEL); + pitem += FPSTR(HTTP_FORM_PARAM); + break; + case WFM_LABEL_AFTER: + pitem = FPSTR(HTTP_FORM_PARAM); + pitem += FPSTR(HTTP_FORM_LABEL); + break; + default: + // WFM_NO_LABEL + pitem = FPSTR(HTTP_FORM_PARAM); + break; } // if no ID use customhtml for item, else generate from param string - if (_params[i]->getID() != NULL) { - if(tok_I)pitem.replace(FPSTR(T_I), (String)FPSTR(S_parampre)+(String)i); - if(tok_i)pitem.replace(FPSTR(T_i), _params[i]->getID()); - if(tok_n)pitem.replace(FPSTR(T_n), _params[i]->getID()); - if(tok_p)pitem.replace(FPSTR(T_p), FPSTR(T_t)); - if(tok_t)pitem.replace(FPSTR(T_t), _params[i]->getPlaceholder()); + if (_params[i]->getID() != NULL) + { + if (tok_I) + pitem.replace(FPSTR(T_I), (String)FPSTR(S_parampre) + (String)i); + if (tok_i) + pitem.replace(FPSTR(T_i), _params[i]->getID()); + if (tok_n) + pitem.replace(FPSTR(T_n), _params[i]->getID()); + if (tok_p) + pitem.replace(FPSTR(T_p), FPSTR(T_t)); + if (tok_t) + pitem.replace(FPSTR(T_t), _params[i]->getPlaceholder()); snprintf(parLength, 5, "%d", _params[i]->getValueLength()); - if(tok_l)pitem.replace(FPSTR(T_l), parLength); - if(tok_v)pitem.replace(FPSTR(T_v), _params[i]->getValue()); - if(tok_c)pitem.replace(FPSTR(T_c), _params[i]->getCustomHTML()); // meant for additional attributes, not html - } else { + if (tok_l) + pitem.replace(FPSTR(T_l), parLength); + if (tok_v) + pitem.replace(FPSTR(T_v), _params[i]->getValue()); + if (tok_c) + pitem.replace(FPSTR(T_c), _params[i]->getCustomHTML()); // meant for additional attributes, not html + } + else + { pitem = _params[i]->getCustomHTML(); } @@ -1243,14 +1459,15 @@ String WiFiManager::getParamOut(){ return page; } -void WiFiManager::handleWiFiStatus(){ - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP WiFi status ")); +void WiFiManager::handleWiFiStatus() +{ + DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP WiFi status ")); handleRequest(); String page; - // String page = "{\"result\":true,\"count\":1}"; - #ifdef JSTEST - page = FPSTR(HTTP_JS); - #endif +// String page = "{\"result\":true,\"count\":1}"; +#ifdef JSTEST + page = FPSTR(HTTP_JS); +#endif server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); } @@ -1258,37 +1475,49 @@ void WiFiManager::handleWiFiStatus(){ /** * HTTPD CALLBACK save form and redirect to WLAN config page again */ -void WiFiManager::handleWifiSave() { - 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)); +void WiFiManager::handleWifiSave() +{ + 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)); handleRequest(); + // @todo use new callback for pre saves + if (_presavecallback != NULL) + { + _presavecallback(); + } + //SAVE/connect here _ssid = server->arg(F("s")).c_str(); _pass = server->arg(F("p")).c_str(); - if(_paramsInWifi) doParamSave(); + if (_paramsInWifi) + doParamSave(); - if (server->arg(FPSTR(S_ip)) != "") { + if (server->arg(FPSTR(S_ip)) != "") + { //_sta_static_ip.fromString(server->arg(FPSTR(S_ip)); String ip = server->arg(FPSTR(S_ip)); optionalIPFromString(&_sta_static_ip, ip.c_str()); - DEBUG_WM(DEBUG_DEV,F("static ip:"),ip); + DEBUG_WM(DEBUG_DEV, F("static ip:"), ip); } - if (server->arg(FPSTR(S_gw)) != "") { + if (server->arg(FPSTR(S_gw)) != "") + { String gw = server->arg(FPSTR(S_gw)); optionalIPFromString(&_sta_static_gw, gw.c_str()); - DEBUG_WM(DEBUG_DEV,F("static gateway:"),gw); + DEBUG_WM(DEBUG_DEV, F("static gateway:"), gw); } - if (server->arg(FPSTR(S_sn)) != "") { + if (server->arg(FPSTR(S_sn)) != "") + { String sn = server->arg(FPSTR(S_sn)); optionalIPFromString(&_sta_static_sn, sn.c_str()); - DEBUG_WM(DEBUG_DEV,F("static netmask:"),sn); + DEBUG_WM(DEBUG_DEV, F("static netmask:"), sn); } - if (server->arg(FPSTR(S_dns)) != "") { + if (server->arg(FPSTR(S_dns)) != "") + { String dns = server->arg(FPSTR(S_dns)); optionalIPFromString(&_sta_static_dns, dns.c_str()); - DEBUG_WM(DEBUG_DEV,F("static DNS:"),dns); + DEBUG_WM(DEBUG_DEV, F("static DNS:"), dns); } String page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved @@ -1299,20 +1528,28 @@ void WiFiManager::handleWifiSave() { server->sendHeader(FPSTR(HTTP_HEAD_CORS), FPSTR(HTTP_HEAD_CORS_ALLOW_ALL)); server->send(200, FPSTR(HTTP_HEAD_CT), page); - DEBUG_WM(DEBUG_DEV,F("Sent wifi save page")); + DEBUG_WM(DEBUG_DEV, F("Sent wifi save page")); connect = true; //signal ready to connect/reset process in processConfigPortal } -void WiFiManager::handleParamSave() { - - 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)); +void WiFiManager::handleParamSave() +{ + 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)); handleRequest(); + + // @todo use new callback for pre saves + if (_presavecallback != NULL) + { + _presavecallback(); + } + doParamSave(); // @todo use new callback for paramsaves - if ( _savecallback != NULL) { + if (_savecallback != NULL) + { _savecallback(); } @@ -1323,50 +1560,58 @@ void WiFiManager::handleParamSave() { server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); - DEBUG_WM(DEBUG_DEV,F("Sent param save page")); + DEBUG_WM(DEBUG_DEV, F("Sent param save page")); } -void WiFiManager::doParamSave(){ +void WiFiManager::doParamSave() +{ //parameters - if(_paramsCount > 0){ - DEBUG_WM(DEBUG_VERBOSE,F("Parameters")); - DEBUG_WM(DEBUG_VERBOSE,FPSTR(D_HR)); - for (int i = 0; i < _paramsCount; i++) { - if (_params[i] == NULL) { + if (_paramsCount > 0) + { + DEBUG_WM(DEBUG_VERBOSE, F("Parameters")); + DEBUG_WM(DEBUG_VERBOSE, FPSTR(D_HR)); + for (int i = 0; i < _paramsCount; i++) + { + if (_params[i] == NULL) + { break; } //read parameter from server - String name = (String)FPSTR(S_parampre)+(String)i; + String name = (String)FPSTR(S_parampre) + (String)i; String value; - if(server->hasArg(name)) { + if (server->hasArg(name)) + { value = server->arg(name); - } else { + } + else + { value = server->arg(_params[i]->getID()); } //store it in params array - value.toCharArray(_params[i]->_value, _params[i]->_length+1); // length+1 null terminated - DEBUG_WM(DEBUG_VERBOSE,(String)_params[i]->getID() + ":",value); + value.toCharArray(_params[i]->_value, _params[i]->_length + 1); // length+1 null terminated + DEBUG_WM(DEBUG_VERBOSE, (String)_params[i]->getID() + ":", value); } - DEBUG_WM(DEBUG_VERBOSE,FPSTR(D_HR)); + DEBUG_WM(DEBUG_VERBOSE, FPSTR(D_HR)); } } /** * HTTPD CALLBACK info page */ -void WiFiManager::handleInfo() { - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Info")); +void WiFiManager::handleInfo() +{ + DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP Info")); handleRequest(); String page = getHTTPHead(FPSTR(S_titleinfo)); // @token titleinfo reportStatus(page); uint16_t infos = 0; - //@todo convert to enum or refactor to strings - #ifdef ESP8266 - infos = 27; - String infoids[] = { +//@todo convert to enum or refactor to strings +#ifdef ESP8266 + infos = 27; + String infoids[] = { F("esphead"), F("uptime"), F("chipid"), @@ -1393,12 +1638,11 @@ void WiFiManager::handleInfo() { F("host"), F("stamac"), F("conx"), - F("autoconx") - }; + F("autoconx")}; - #elif defined(ESP32) - infos = 22; - String infoids[] = { +#elif defined(ESP32) + infos = 22; + String infoids[] = { F("esphead"), F("uptime"), F("chipid"), @@ -1420,214 +1664,279 @@ void WiFiManager::handleInfo() { F("dnss"), F("host"), F("stamac"), - F("conx") - }; - #endif + F("conx")}; +#endif - for(size_t i=0; i"); - if(_showInfoErase) page += FPSTR(HTTP_ERASEBTN); + if (_showInfoErase) + page += FPSTR(HTTP_ERASEBTN); page += FPSTR(HTTP_HELP); page += FPSTR(HTTP_END); server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); - DEBUG_WM(DEBUG_DEV,F("Sent info page")); + DEBUG_WM(DEBUG_DEV, F("Sent info page")); } -String WiFiManager::getInfoData(String id){ +String WiFiManager::getInfoData(String id) +{ String p; // @todo add versioning - if(id==F("esphead"))p = FPSTR(HTTP_INFO_esphead); - else if(id==F("wifihead"))p = FPSTR(HTTP_INFO_wifihead); - else if(id==F("uptime")){ + if (id == F("esphead")) + p = FPSTR(HTTP_INFO_esphead); + else if (id == F("wifihead")) + p = FPSTR(HTTP_INFO_wifihead); + else if (id == F("uptime")) + { // subject to rollover! p = FPSTR(HTTP_INFO_uptime); - p.replace(FPSTR(T_1),(String)(millis() / 1000 / 60)); - p.replace(FPSTR(T_2),(String)((millis() / 1000) % 60)); + p.replace(FPSTR(T_1), (String)(millis() / 1000 / 60)); + p.replace(FPSTR(T_2), (String)((millis() / 1000) % 60)); } - else if(id==F("chipid")){ + else if (id == F("chipid")) + { p = FPSTR(HTTP_INFO_chipid); - p.replace(FPSTR(T_1),String(WIFI_getChipId(),HEX)); + p.replace(FPSTR(T_1), String(WIFI_getChipId(), HEX)); } - #ifdef ESP32 - else if(id==F("chiprev")){ - p = FPSTR(HTTP_INFO_chiprev); - String rev = (String)ESP.getChipRevision(); - #ifdef _SOC_EFUSE_REG_H_ - String revb = (String)(REG_READ(EFUSE_BLK0_RDATA3_REG) >> (EFUSE_RD_CHIP_VER_RESERVE_S)&&EFUSE_RD_CHIP_VER_RESERVE_V); - p.replace(FPSTR(T_1),rev+"
"+revb); - #else - p.replace(FPSTR(T_1),rev); - #endif +#ifdef ESP32 + else if (id == F("chiprev")) + { + p = FPSTR(HTTP_INFO_chiprev); + String rev = (String)ESP.getChipRevision(); +#ifdef _SOC_EFUSE_REG_H_ + String revb = (String)(REG_READ(EFUSE_BLK0_RDATA3_REG) >> (EFUSE_RD_CHIP_VER_RESERVE_S) && EFUSE_RD_CHIP_VER_RESERVE_V); + p.replace(FPSTR(T_1), rev + "
" + revb); +#else + p.replace(FPSTR(T_1), rev); +#endif } - #endif - #ifdef ESP8266 - else if(id==F("fchipid")){ - p = FPSTR(HTTP_INFO_fchipid); - p.replace(FPSTR(T_1),(String)ESP.getFlashChipId()); +#endif +#ifdef ESP8266 + else if (id == F("fchipid")) + { + p = FPSTR(HTTP_INFO_fchipid); + p.replace(FPSTR(T_1), (String)ESP.getFlashChipId()); } - #endif - else if(id==F("idesize")){ +#endif + else if (id == F("idesize")) + { p = FPSTR(HTTP_INFO_idesize); - p.replace(FPSTR(T_1),(String)ESP.getFlashChipSize()); + p.replace(FPSTR(T_1), (String)ESP.getFlashChipSize()); } - else if(id==F("flashsize")){ - #ifdef ESP8266 - p = FPSTR(HTTP_INFO_flashsize); - p.replace(FPSTR(T_1),(String)ESP.getFlashChipRealSize()); - #endif + else if (id == F("flashsize")) + { +#ifdef ESP8266 + p = FPSTR(HTTP_INFO_flashsize); + p.replace(FPSTR(T_1), (String)ESP.getFlashChipRealSize()); +#endif } - else if(id==F("sdkver")){ + else if (id == F("sdkver")) + { p = FPSTR(HTTP_INFO_sdkver); - #ifdef ESP32 - p.replace(FPSTR(T_1),(String)esp_get_idf_version()); - #else - p.replace(FPSTR(T_1),(String)system_get_sdk_version()); - #endif +#ifdef ESP32 + p.replace(FPSTR(T_1), (String)esp_get_idf_version()); +#else + p.replace(FPSTR(T_1), (String)system_get_sdk_version()); +#endif } - else if(id==F("corever")){ - #ifdef ESP8266 - p = FPSTR(HTTP_INFO_corever); - p.replace(FPSTR(T_1),(String)ESP.getCoreVersion()); - #endif + else if (id == F("corever")) + { +#ifdef ESP8266 + p = FPSTR(HTTP_INFO_corever); + p.replace(FPSTR(T_1), (String)ESP.getCoreVersion()); +#endif } - #ifdef ESP8266 - else if(id==F("bootver")){ - p = FPSTR(HTTP_INFO_bootver); - p.replace(FPSTR(T_1),(String)system_get_boot_version()); +#ifdef ESP8266 + else if (id == F("bootver")) + { + p = FPSTR(HTTP_INFO_bootver); + p.replace(FPSTR(T_1), (String)system_get_boot_version()); } - #endif - else if(id==F("cpufreq")){ +#endif + else if (id == F("cpufreq")) + { p = FPSTR(HTTP_INFO_cpufreq); - p.replace(FPSTR(T_1),(String)ESP.getCpuFreqMHz()); + p.replace(FPSTR(T_1), (String)ESP.getCpuFreqMHz()); } - else if(id==F("freeheap")){ + else if (id == F("freeheap")) + { p = FPSTR(HTTP_INFO_freeheap); - p.replace(FPSTR(T_1),(String)ESP.getFreeHeap()); + p.replace(FPSTR(T_1), (String)ESP.getFreeHeap()); } - #ifdef ESP8266 - else if(id==F("memsketch")){ +#ifdef ESP8266 + else if (id == F("memsketch")) + { p = FPSTR(HTTP_INFO_memsketch); - p.replace(FPSTR(T_1),(String)(ESP.getSketchSize())); - p.replace(FPSTR(T_2),(String)(ESP.getSketchSize()+ESP.getFreeSketchSpace())); + p.replace(FPSTR(T_1), (String)(ESP.getSketchSize())); + p.replace(FPSTR(T_2), (String)(ESP.getSketchSize() + ESP.getFreeSketchSpace())); } - #endif - #ifdef ESP8266 - else if(id==F("memsmeter")){ +#endif +#ifdef ESP8266 + else if (id == F("memsmeter")) + { p = FPSTR(HTTP_INFO_memsmeter); - p.replace(FPSTR(T_1),(String)(ESP.getSketchSize())); - p.replace(FPSTR(T_2),(String)(ESP.getSketchSize()+ESP.getFreeSketchSpace())); + p.replace(FPSTR(T_1), (String)(ESP.getSketchSize())); + p.replace(FPSTR(T_2), (String)(ESP.getSketchSize() + ESP.getFreeSketchSpace())); } - #endif - else if(id==F("lastreset")){ - #ifdef ESP8266 - p = FPSTR(HTTP_INFO_lastreset); - p.replace(FPSTR(T_1),(String)ESP.getResetReason()); - #elif defined(ESP32) && defined(_ROM_RTC_H_) - // requires #include - p = FPSTR(HTTP_INFO_lastreset); - for(int i=0;i<2;i++){ - int reason = rtc_get_reset_reason(i); - String tok = (String)T_ss+(String)(i+1)+(String)T_es; - switch (reason) - { - //@todo move to array - case 1 : p.replace(tok,F("Vbat power on reset"));break; - case 3 : p.replace(tok,F("Software reset digital core"));break; - case 4 : p.replace(tok,F("Legacy watch dog reset digital core"));break; - case 5 : p.replace(tok,F("Deep Sleep reset digital core"));break; - case 6 : p.replace(tok,F("Reset by SLC module, reset digital core"));break; - case 7 : p.replace(tok,F("Timer Group0 Watch dog reset digital core"));break; - case 8 : p.replace(tok,F("Timer Group1 Watch dog reset digital core"));break; - case 9 : p.replace(tok,F("RTC Watch dog Reset digital core"));break; - case 10 : p.replace(tok,F("Instrusion tested to reset CPU"));break; - case 11 : p.replace(tok,F("Time Group reset CPU"));break; - case 12 : p.replace(tok,F("Software reset CPU"));break; - case 13 : p.replace(tok,F("RTC Watch dog Reset CPU"));break; - case 14 : p.replace(tok,F("for APP CPU, reseted by PRO CPU"));break; - case 15 : p.replace(tok,F("Reset when the vdd voltage is not stable"));break; - case 16 : p.replace(tok,F("RTC Watch dog reset digital core and rtc module"));break; - default : p.replace(tok,F("NO_MEAN")); - } +#endif + else if (id == F("lastreset")) + { +#ifdef ESP8266 + p = FPSTR(HTTP_INFO_lastreset); + p.replace(FPSTR(T_1), (String)ESP.getResetReason()); +#elif defined(ESP32) && defined(_ROM_RTC_H_) + // requires #include + p = FPSTR(HTTP_INFO_lastreset); + for (int i = 0; i < 2; i++) + { + int reason = rtc_get_reset_reason(i); + String tok = (String)T_ss + (String)(i + 1) + (String)T_es; + switch (reason) + { + //@todo move to array + case 1: + p.replace(tok, F("Vbat power on reset")); + break; + case 3: + p.replace(tok, F("Software reset digital core")); + break; + case 4: + p.replace(tok, F("Legacy watch dog reset digital core")); + break; + case 5: + p.replace(tok, F("Deep Sleep reset digital core")); + break; + case 6: + p.replace(tok, F("Reset by SLC module, reset digital core")); + break; + case 7: + p.replace(tok, F("Timer Group0 Watch dog reset digital core")); + break; + case 8: + p.replace(tok, F("Timer Group1 Watch dog reset digital core")); + break; + case 9: + p.replace(tok, F("RTC Watch dog Reset digital core")); + break; + case 10: + p.replace(tok, F("Instrusion tested to reset CPU")); + break; + case 11: + p.replace(tok, F("Time Group reset CPU")); + break; + case 12: + p.replace(tok, F("Software reset CPU")); + break; + case 13: + p.replace(tok, F("RTC Watch dog Reset CPU")); + break; + case 14: + p.replace(tok, F("for APP CPU, reseted by PRO CPU")); + break; + case 15: + p.replace(tok, F("Reset when the vdd voltage is not stable")); + break; + case 16: + p.replace(tok, F("RTC Watch dog reset digital core and rtc module")); + break; + default: + p.replace(tok, F("NO_MEAN")); } - #endif + } +#endif } - else if(id==F("apip")){ + else if (id == F("apip")) + { p = FPSTR(HTTP_INFO_apip); - p.replace(FPSTR(T_1),WiFi.softAPIP().toString()); + p.replace(FPSTR(T_1), WiFi.softAPIP().toString()); } - else if(id==F("apmac")){ + else if (id == F("apmac")) + { p = FPSTR(HTTP_INFO_apmac); - p.replace(FPSTR(T_1),(String)WiFi.softAPmacAddress()); + p.replace(FPSTR(T_1), (String)WiFi.softAPmacAddress()); } - #ifdef ESP32 - else if(id==F("aphost")){ - p = FPSTR(HTTP_INFO_aphost); - p.replace(FPSTR(T_1),WiFi.softAPgetHostname()); +#ifdef ESP32 + else if (id == F("aphost")) + { + p = FPSTR(HTTP_INFO_aphost); + p.replace(FPSTR(T_1), WiFi.softAPgetHostname()); } - #endif - else if(id==F("apssid")){ +#endif + else if (id == F("apssid")) + { p = FPSTR(HTTP_INFO_apssid); - p.replace(FPSTR(T_1),htmlEntities((String)WiFi_SSID())); + p.replace(FPSTR(T_1), htmlEntities((String)WiFi_SSID())); } - else if(id==F("apbssid")){ + else if (id == F("apbssid")) + { p = FPSTR(HTTP_INFO_apbssid); - p.replace(FPSTR(T_1),(String)WiFi.BSSIDstr()); + p.replace(FPSTR(T_1), (String)WiFi.BSSIDstr()); } - else if(id==F("staip")){ + else if (id == F("staip")) + { p = FPSTR(HTTP_INFO_staip); - p.replace(FPSTR(T_1),WiFi.localIP().toString()); + p.replace(FPSTR(T_1), WiFi.localIP().toString()); } - else if(id==F("stagw")){ + else if (id == F("stagw")) + { p = FPSTR(HTTP_INFO_stagw); - p.replace(FPSTR(T_1),WiFi.gatewayIP().toString()); + p.replace(FPSTR(T_1), WiFi.gatewayIP().toString()); } - else if(id==F("stasub")){ + else if (id == F("stasub")) + { p = FPSTR(HTTP_INFO_stasub); - p.replace(FPSTR(T_1),WiFi.subnetMask().toString()); + p.replace(FPSTR(T_1), WiFi.subnetMask().toString()); } - else if(id==F("dnss")){ + else if (id == F("dnss")) + { p = FPSTR(HTTP_INFO_dnss); - p.replace(FPSTR(T_1),WiFi.dnsIP().toString()); + p.replace(FPSTR(T_1), WiFi.dnsIP().toString()); } - else if(id==F("host")){ + else if (id == F("host")) + { p = FPSTR(HTTP_INFO_host); - #ifdef ESP32 - p.replace(FPSTR(T_1),WiFi.getHostname()); - #else - p.replace(FPSTR(T_1),WiFi.hostname()); - #endif +#ifdef ESP32 + p.replace(FPSTR(T_1), WiFi.getHostname()); +#else + p.replace(FPSTR(T_1), WiFi.hostname()); +#endif } - else if(id==F("stamac")){ + else if (id == F("stamac")) + { p = FPSTR(HTTP_INFO_stamac); - p.replace(FPSTR(T_1),WiFi.macAddress()); + p.replace(FPSTR(T_1), WiFi.macAddress()); } - else if(id==F("conx")){ + else if (id == F("conx")) + { p = FPSTR(HTTP_INFO_conx); - p.replace(FPSTR(T_1),WiFi.isConnected() ? FPSTR(S_y) : FPSTR(S_n)); + p.replace(FPSTR(T_1), WiFi.isConnected() ? FPSTR(S_y) : FPSTR(S_n)); } - #ifdef ESP8266 - else if(id==F("autoconx")){ +#ifdef ESP8266 + else if (id == F("autoconx")) + { p = FPSTR(HTTP_INFO_autoconx); - p.replace(FPSTR(T_1),WiFi.getAutoConnect() ? FPSTR(S_enable) : FPSTR(S_disable)); + p.replace(FPSTR(T_1), WiFi.getAutoConnect() ? FPSTR(S_enable) : FPSTR(S_disable)); } - #endif +#endif return p; } /** * HTTPD CALLBACK root or redirect to captive portal */ -void WiFiManager::handleExit() { - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Exit")); +void WiFiManager::handleExit() +{ + DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP Exit")); handleRequest(); String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit - page += FPSTR(S_exiting); // @token exiting + page += FPSTR(S_exiting); // @token exiting server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); abort = true; @@ -1636,11 +1945,12 @@ void WiFiManager::handleExit() { /** * HTTPD CALLBACK reset page */ -void WiFiManager::handleReset() { - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Reset")); +void WiFiManager::handleReset() +{ + DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP Reset")); handleRequest(); String page = getHTTPHead(FPSTR(S_titlereset)); //@token titlereset - page += FPSTR(S_resetting); //@token resetting + page += FPSTR(S_resetting); //@token resetting page += FPSTR(HTTP_END); server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); @@ -1658,53 +1968,60 @@ void WiFiManager::handleReset() { // void WiFiManager::handleErase() { // handleErase(false); // } -void WiFiManager::handleErase(boolean opt) { - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Erase")); +void WiFiManager::handleErase(boolean opt) +{ + DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP Erase")); handleRequest(); String page = getHTTPHead(FPSTR(S_titleerase)); // @token titleerase bool ret = erase(opt); - if(ret) page += FPSTR(S_resetting); // @token resetting - else { + if (ret) + page += FPSTR(S_resetting); // @token resetting + else + { page += FPSTR(S_error); // @token erroroccur - DEBUG_WM(DEBUG_ERROR,F("[ERROR] WiFi EraseConfig failed")); + DEBUG_WM(DEBUG_ERROR, F("[ERROR] WiFi EraseConfig failed")); } page += FPSTR(HTTP_END); server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); - if(ret){ + if (ret) + { delay(2000); - DEBUG_WM(F("RESETTING ESP")); - reboot(); - } + DEBUG_WM(F("RESETTING ESP")); + reboot(); + } } /** * HTTPD CALLBACK 404 */ -void WiFiManager::handleNotFound() { - if (captivePortal()) return; // If captive portal redirect instead of displaying the page +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 += 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 += (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"; + 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")); server->sendHeader(F("Pragma"), F("no-cache")); server->sendHeader(F("Expires"), F("-1")); server->sendHeader(FPSTR(HTTP_HEAD_CL), String(message.length())); - server->send ( 404, FPSTR(HTTP_HEAD_CT2), message ); + server->send(404, FPSTR(HTTP_HEAD_CT2), message); } /** @@ -1712,70 +2029,84 @@ void WiFiManager::handleNotFound() { * Redirect to captive portal if we got a request for another domain. * Return true in that case so the page handler do not try to handle the request again. */ -boolean WiFiManager::captivePortal() { - DEBUG_WM(DEBUG_DEV,"-> " + server->hostHeader()); - - if(!_enableCaptivePortal) return false; // skip redirections +boolean WiFiManager::captivePortal() +{ + DEBUG_WM(DEBUG_DEV, "-> " + server->hostHeader()); - if (!isIp(server->hostHeader())) { - DEBUG_WM(DEBUG_VERBOSE,F("<- Request redirected to captive portal")); + if (!_enableCaptivePortal) + return false; // skip redirections + + if (!isIp(server->hostHeader())) + { + DEBUG_WM(DEBUG_VERBOSE, F("<- Request redirected to captive portal")); server->sendHeader(F("Location"), (String)F("http://") + toStringIp(server->client().localIP()), true); - server->send ( 302, FPSTR(HTTP_HEAD_CT2), ""); // Empty content inhibits Content-length header so we have to close the socket ourselves. - server->client().stop(); // Stop is needed because we sent no content length + server->send(302, FPSTR(HTTP_HEAD_CT2), ""); // Empty content inhibits Content-length header so we have to close the socket ourselves. + server->client().stop(); // Stop is needed because we sent no content length return true; } return false; } -void WiFiManager::stopCaptivePortal(){ - _enableCaptivePortal= false; +void WiFiManager::stopCaptivePortal() +{ + _enableCaptivePortal = false; // @todo maybe disable configportaltimeout(optional), or just provide callback for user } -void WiFiManager::handleClose(){ +void WiFiManager::handleClose() +{ stopCaptivePortal(); - DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP close")); + DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP close")); handleRequest(); String page = getHTTPHead(FPSTR(S_titleclose)); // @token titleclose - page += FPSTR(S_closing); // @token closing + page += FPSTR(S_closing); // @token closing server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); } -void WiFiManager::reportStatus(String &page){ +void WiFiManager::reportStatus(String &page) +{ updateConxResult(WiFi.status()); String str; - if (WiFi_SSID() != ""){ - if (WiFi.status()==WL_CONNECTED){ + if (WiFi_SSID() != "") + { + if (WiFi.status() == WL_CONNECTED) + { str = FPSTR(HTTP_STATUS_ON); - str.replace(FPSTR(T_i),WiFi.localIP().toString()); - str.replace(FPSTR(T_v),htmlEntities(WiFi_SSID())); + str.replace(FPSTR(T_i), WiFi.localIP().toString()); + str.replace(FPSTR(T_v), htmlEntities(WiFi_SSID())); } - else { + else + { str = FPSTR(HTTP_STATUS_OFF); - str.replace(FPSTR(T_v),htmlEntities(WiFi_SSID())); - if(_lastconxresult == WL_STATION_WRONG_PASSWORD){ + str.replace(FPSTR(T_v), htmlEntities(WiFi_SSID())); + if (_lastconxresult == WL_STATION_WRONG_PASSWORD) + { // wrong password - str.replace(FPSTR(T_c),"D"); // class - str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_OFFPW)); + str.replace(FPSTR(T_c), "D"); // class + str.replace(FPSTR(T_r), FPSTR(HTTP_STATUS_OFFPW)); } - else if(_lastconxresult == WL_NO_SSID_AVAIL){ + else if (_lastconxresult == WL_NO_SSID_AVAIL) + { // connect failed, or ap not found - str.replace(FPSTR(T_c),"D"); - str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_OFFNOAP)); + str.replace(FPSTR(T_c), "D"); + str.replace(FPSTR(T_r), FPSTR(HTTP_STATUS_OFFNOAP)); } - else if(_lastconxresult == WL_CONNECT_FAILED){ + else if (_lastconxresult == WL_CONNECT_FAILED) + { // connect failed - str.replace(FPSTR(T_c),"D"); - str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_OFFFAIL)); + str.replace(FPSTR(T_c), "D"); + str.replace(FPSTR(T_r), FPSTR(HTTP_STATUS_OFFFAIL)); + } + else + { + str.replace(FPSTR(T_c), ""); + str.replace(FPSTR(T_r), ""); } - else{ - str.replace(FPSTR(T_c),""); - str.replace(FPSTR(T_r),""); - } } } - else { + else + { str = FPSTR(HTTP_STATUS_NONE); } page += str; @@ -1795,11 +2126,13 @@ void WiFiManager::reportStatus(String &page){ * @since $dev * @return bool success */ -bool WiFiManager::disconnect(){ - if(WiFi.status() != WL_CONNECTED){ - DEBUG_WM(DEBUG_VERBOSE,"Disconnecting: Not connected"); +bool WiFiManager::disconnect() +{ + if (WiFi.status() != WL_CONNECTED) + { + DEBUG_WM(DEBUG_VERBOSE, "Disconnecting: Not connected"); return false; - } + } DEBUG_WM("Disconnecting"); return WiFi_Disconnect(); } @@ -1808,7 +2141,8 @@ bool WiFiManager::disconnect(){ * reboot the device * @access public */ -void WiFiManager::reboot(){ +void WiFiManager::reboot() +{ DEBUG_WM("Restarting"); ESP.restart(); } @@ -1817,28 +2151,31 @@ void WiFiManager::reboot(){ * reboot the device * @access public */ -bool WiFiManager::erase(){ +bool WiFiManager::erase() +{ return erase(false); } -bool WiFiManager::erase(bool opt){ +bool WiFiManager::erase(bool opt) +{ DEBUG_WM("Erasing"); - #if defined(ESP32) && ((defined(WM_ERASE_NVS) || defined(nvs_flash_h))) - // if opt true, do nvs erase - if(opt){ - DEBUG_WM("Erasing NVS"); - int err; - esp_err_t err; - err = nvs_flash_init(); - DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_init: ",err!=ESP_OK ? (String)err : "Success"); - err = nvs_flash_erase(); - DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_erase: ", err!=ESP_OK ? (String)err : "Success"); - return err == ESP_OK; - } - #else - (void)opt; - #endif +#if defined(ESP32) && ((defined(WM_ERASE_NVS) || defined(nvs_flash_h))) + // if opt true, do nvs erase + if (opt) + { + DEBUG_WM("Erasing NVS"); + int err; + esp_err_t err; + err = nvs_flash_init(); + DEBUG_WM(DEBUG_VERBOSE, "nvs_flash_init: ", err != ESP_OK ? (String)err : "Success"); + err = nvs_flash_erase(); + DEBUG_WM(DEBUG_VERBOSE, "nvs_flash_erase: ", err != ESP_OK ? (String)err : "Success"); + return err == ESP_OK; + } +#else + (void)opt; +#endif return WiFi_eraseConfig(); } @@ -1848,17 +2185,18 @@ bool WiFiManager::erase(bool opt){ * ERASES STA CREDENTIALS * @access public */ -void WiFiManager::resetSettings() { +void WiFiManager::resetSettings() +{ DEBUG_WM(F("SETTINGS ERASED")); - WiFi_enableSTA(true,true); // must be sta to disconnect erase - - #ifdef ESP32 - WiFi.disconnect(true,true); - #else - WiFi.persistent(true); - WiFi.disconnect(true); - WiFi.persistent(false); - #endif + WiFi_enableSTA(true, true); // must be sta to disconnect erase + +#ifdef ESP32 + WiFi.disconnect(true, true); +#else + WiFi.persistent(true); + WiFi.disconnect(true); + WiFi.persistent(false); +#endif } // SETTERS @@ -1868,7 +2206,8 @@ void WiFiManager::resetSettings() { * @access public * @param {[type]} unsigned long seconds [description] */ -void WiFiManager::setTimeout(unsigned long seconds) { +void WiFiManager::setTimeout(unsigned long seconds) +{ setConfigPortalTimeout(seconds); } @@ -1877,7 +2216,8 @@ void WiFiManager::setTimeout(unsigned long seconds) { * @access public * @param {[type]} unsigned long seconds [description] */ -void WiFiManager::setConfigPortalTimeout(unsigned long seconds) { +void WiFiManager::setConfigPortalTimeout(unsigned long seconds) +{ _configPortalTimeout = seconds * 1000; } @@ -1886,7 +2226,8 @@ void WiFiManager::setConfigPortalTimeout(unsigned long seconds) { * @access public * @param {[type]} unsigned long seconds [description] */ -void WiFiManager::setConnectTimeout(unsigned long seconds) { +void WiFiManager::setConnectTimeout(unsigned long seconds) +{ _connectTimeout = seconds * 1000; } @@ -1895,7 +2236,8 @@ void WiFiManager::setConnectTimeout(unsigned long seconds) { * @access public * @param {[type]} unsigned long seconds [description] */ -void WiFiManager::setSaveConnectTimeout(unsigned long seconds) { +void WiFiManager::setSaveConnectTimeout(unsigned long seconds) +{ _saveTimeout = seconds * 1000; } @@ -1904,7 +2246,8 @@ void WiFiManager::setSaveConnectTimeout(unsigned long seconds) { * @access public * @param {[type]} boolean debug [description] */ -void WiFiManager::setDebugOutput(boolean debug) { +void WiFiManager::setDebugOutput(boolean debug) +{ _debug = debug; } @@ -1915,7 +2258,8 @@ void WiFiManager::setDebugOutput(boolean debug) { * @param {[type]} IPAddress gw [description] * @param {[type]} IPAddress sn [description] */ -void WiFiManager::setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) { +void WiFiManager::setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) +{ _ap_static_ip = ip; _ap_static_gw = gw; _ap_static_sn = sn; @@ -1928,7 +2272,8 @@ void WiFiManager::setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) * @param {[type]} IPAddress gw [description] * @param {[type]} IPAddress sn [description] */ -void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) { +void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) +{ _sta_static_ip = ip; _sta_static_gw = gw; _sta_static_sn = sn; @@ -1943,8 +2288,9 @@ void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) * @param {[type]} IPAddress sn [description] * @param {[type]} IPAddress dns [description] */ -void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn, IPAddress dns) { - setSTAStaticIPConfig(ip,gw,sn); +void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn, IPAddress dns) +{ + setSTAStaticIPConfig(ip, gw, sn); _sta_static_dns = dns; } @@ -1953,7 +2299,8 @@ void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn, * @access public * @param {[type]} int quality [description] */ -void WiFiManager::setMinimumSignalQuality(int quality) { +void WiFiManager::setMinimumSignalQuality(int quality) +{ _minimumQuality = quality; } @@ -1962,7 +2309,8 @@ void WiFiManager::setMinimumSignalQuality(int quality) { * @access public * @param {[type]} boolean shouldBreak [description] */ -void WiFiManager::setBreakAfterConfig(boolean shouldBreak) { +void WiFiManager::setBreakAfterConfig(boolean shouldBreak) +{ _shouldBreakAfterConfig = shouldBreak; } @@ -1971,27 +2319,41 @@ void WiFiManager::setBreakAfterConfig(boolean shouldBreak) { * @access public * @param {[type]} void (*func)(WiFiManager* myWiFiManager) [description] */ -void WiFiManager::setAPCallback( std::function func ) { +void WiFiManager::setAPCallback(std::function func) +{ _apcallback = func; } - + /** * setSaveConfigCallback, set a save config callback after closing configportal * @todo only calls if configportal stopped * @access public * @param {[type]} void (*func)(void) [description] */ -void WiFiManager::setSaveConfigCallback( std::function func ) { +void WiFiManager::setSaveConfigCallback(std::function func) +{ _savecallback = func; } +/** + * setSaveConfigCallback, set a save config callback after closing configportal + * @todo only calls if configportal stopped + * @access public + * @param {[type]} void (*func)(void) [description] + */ +void WiFiManager::setPreSaveConfigCallback(std::function func) +{ + _presavecallback = func; +} + /** * set custom head html * custom element will be added to head, eg. new style tag etc. * @access public * @param char element */ -void WiFiManager::setCustomHeadElement(const char* element) { +void WiFiManager::setCustomHeadElement(const char *element) +{ _customHeadElement = element; } @@ -2002,7 +2364,8 @@ void WiFiManager::setCustomHeadElement(const char* element) { * @access public * @param boolean removeDuplicates [true] */ -void WiFiManager::setRemoveDuplicateAPs(boolean removeDuplicates) { +void WiFiManager::setRemoveDuplicateAPs(boolean removeDuplicates) +{ _removeDuplicateAPs = removeDuplicates; } @@ -2014,7 +2377,8 @@ void WiFiManager::setRemoveDuplicateAPs(boolean removeDuplicates) { * @access public * @param boolean shoudlBlock [false] */ -void WiFiManager::setConfigPortalBlocking(boolean shoudlBlock) { +void WiFiManager::setConfigPortalBlocking(boolean shoudlBlock) +{ _configPortalIsBlocking = shoudlBlock; } @@ -2026,9 +2390,11 @@ void WiFiManager::setConfigPortalBlocking(boolean shoudlBlock) { * @access public * @param boolean persistent [true] */ -void WiFiManager::setRestorePersistent(boolean persistent) { +void WiFiManager::setRestorePersistent(boolean persistent) +{ _userpersistent = persistent; - if(!persistent) DEBUG_WM(F("persistent is off")); + if (!persistent) + DEBUG_WM(F("persistent is off")); } /** @@ -2038,9 +2404,12 @@ void WiFiManager::setRestorePersistent(boolean persistent) { * @access public * @param boolean alwaysShow [false] */ -void WiFiManager::setShowStaticFields(boolean alwaysShow){ - if(_disableIpFields) _staShowStaticFields = alwaysShow ? 1 : -1; - else _staShowStaticFields = alwaysShow ? 1 : 0; +void WiFiManager::setShowStaticFields(boolean alwaysShow) +{ + if (_disableIpFields) + _staShowStaticFields = alwaysShow ? 1 : -1; + else + _staShowStaticFields = alwaysShow ? 1 : 0; } /** @@ -2050,8 +2419,10 @@ void WiFiManager::setShowStaticFields(boolean alwaysShow){ * @access public * @param boolean alwaysShow [false] */ -void WiFiManager::setShowDnsFields(boolean alwaysShow){ - if(_disableIpFields) _staShowDns = alwaysShow ? 1 : -1; +void WiFiManager::setShowDnsFields(boolean alwaysShow) +{ + if (_disableIpFields) + _staShowDns = alwaysShow ? 1 : -1; _staShowDns = alwaysShow ? 1 : 0; } @@ -2063,7 +2434,8 @@ void WiFiManager::setShowDnsFields(boolean alwaysShow){ * @access public * @param boolean enabled [true] */ -void WiFiManager::setCaptivePortalEnable(boolean enabled){ +void WiFiManager::setCaptivePortalEnable(boolean enabled) +{ _enableCaptivePortal = enabled; } @@ -2076,7 +2448,8 @@ void WiFiManager::setCaptivePortalEnable(boolean enabled){ * @access public * @param boolean enabled [true] */ -void WiFiManager::setWiFiAutoReconnect(boolean enabled){ +void WiFiManager::setWiFiAutoReconnect(boolean enabled) +{ _wifiAutoReconnect = enabled; } @@ -2088,7 +2461,8 @@ void WiFiManager::setWiFiAutoReconnect(boolean enabled){ * @access public * @param boolean enabled [false] */ -void WiFiManager::setCaptivePortalClientCheck(boolean enabled){ +void WiFiManager::setCaptivePortalClientCheck(boolean enabled) +{ _cpClientCheck = enabled; } @@ -2099,7 +2473,8 @@ void WiFiManager::setCaptivePortalClientCheck(boolean enabled){ * @access public * @param boolean enabled [true] */ -void WiFiManager::setWebPortalClientCheck(boolean enabled){ +void WiFiManager::setWebPortalClientCheck(boolean enabled) +{ _webClientCheck = enabled; } @@ -2109,7 +2484,8 @@ void WiFiManager::setWebPortalClientCheck(boolean enabled){ * @access public * @param boolean enabled [false] */ -void WiFiManager::setScanDispPerc(boolean enabled){ +void WiFiManager::setScanDispPerc(boolean enabled) +{ _scanDispOptions = enabled; } @@ -2122,10 +2498,9 @@ void WiFiManager::setScanDispPerc(boolean enabled){ */ void WiFiManager::setEnableConfigPortal(boolean enable) { - _enableConfigPortal = enable; + _enableConfigPortal = enable; } - /** * set the hostname (dhcp client id) * @since $dev @@ -2133,7 +2508,8 @@ void WiFiManager::setEnableConfigPortal(boolean enable) * @param char* hostname 32 character hostname to use for sta+ap in esp32, sta in esp8266 * @return bool false if hostname is not valid */ -bool WiFiManager::setHostname(const char * hostname){ +bool WiFiManager::setHostname(const char *hostname) +{ //@todo max length 32 _hostname = hostname; return true; @@ -2143,7 +2519,8 @@ bool WiFiManager::setHostname(const char * hostname){ * toggle showing erase wifi config button on info page * @param boolean enabled */ -void WiFiManager::setShowInfoErase(boolean enabled){ +void WiFiManager::setShowInfoErase(boolean enabled) +{ _showInfoErase = enabled; } @@ -2156,13 +2533,18 @@ void WiFiManager::setShowInfoErase(boolean enabled){ * @since $dev * @param uint8_t menu[] array of menu ids */ -void WiFiManager::setMenu(const char * menu[], uint8_t size){ +void WiFiManager::setMenu(const char *menu[], uint8_t size) +{ // DEBUG_WM(DEBUG_VERBOSE,"setmenu array"); _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] == "param") _paramsInWifi = false; // param auto flag + 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] == "param") + _paramsInWifi = false; // param auto flag _menuIds.push_back(j); } } @@ -2179,13 +2561,18 @@ void WiFiManager::setMenu(const char * menu[], uint8_t size){ * @shiftIncrement $dev * @param {[type]} std::vector& menu [description] */ -void WiFiManager::setMenu(std::vector& menu){ +void WiFiManager::setMenu(std::vector &menu) +{ // DEBUG_WM(DEBUG_VERBOSE,"setmenu vector"); _menuIds.clear(); - for(auto menuitem : menu ){ - for(size_t j = 0; j < _nummenutokens; j++){ - if(menuitem == _menutokens[j]){ - if((String)menuitem == "param") _paramsInWifi = false; // param auto flag + for (auto menuitem : menu) + { + for (size_t j = 0; j < _nummenutokens; j++) + { + if (menuitem == _menutokens[j]) + { + if ((String)menuitem == "param") + _paramsInWifi = false; // param auto flag _menuIds.push_back(j); } } @@ -2193,7 +2580,6 @@ void WiFiManager::setMenu(std::vector& menu){ // DEBUG_WM(getMenuOut()); } - // GETTERS /** @@ -2202,7 +2588,8 @@ void WiFiManager::setMenu(std::vector& menu){ * @access public * @return String the configportal ap name */ -String WiFiManager::getConfigPortalSSID() { +String WiFiManager::getConfigPortalSSID() +{ return _apName; } @@ -2214,7 +2601,8 @@ String WiFiManager::getConfigPortalSSID() { * @access public * @return bool return wl_status codes */ -uint8_t WiFiManager::getLastConxResult(){ +uint8_t WiFiManager::getLastConxResult() +{ return _lastconxresult; } @@ -2224,7 +2612,8 @@ uint8_t WiFiManager::getLastConxResult(){ * @access public * @return bool true if a saved ap config exists */ -bool WiFiManager::getWiFiIsSaved(){ +bool WiFiManager::getWiFiIsSaved() +{ return WiFi_hasAutoConnect(); } @@ -2233,7 +2622,8 @@ bool WiFiManager::getWiFiIsSaved(){ * @since $dev * @param String cc country code, must be defined in WiFiSetCountry, US, JP, CN */ -void WiFiManager::setCountry(String cc){ +void WiFiManager::setCountry(String cc) +{ _wificountry = cc; } @@ -2241,41 +2631,51 @@ void WiFiManager::setCountry(String cc){ * setClass * @param String str body class string */ -void WiFiManager::setClass(String str){ +void WiFiManager::setClass(String str) +{ _bodyClass = str; } - + // HELPERS // DEBUG // @todo fix DEBUG_WM(0,0); template -void WiFiManager::DEBUG_WM(Generic text) { - DEBUG_WM(DEBUG_NOTIFY,text,""); +void WiFiManager::DEBUG_WM(Generic text) +{ + DEBUG_WM(DEBUG_NOTIFY, text, ""); } template -void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text) { - if(_debugLevel >= level) DEBUG_WM(level,text,""); +void WiFiManager::DEBUG_WM(wm_debuglevel_t level, Generic text) +{ + if (_debugLevel >= level) + DEBUG_WM(level, text, ""); } template -void WiFiManager::DEBUG_WM(Generic text,Genericb textb) { - DEBUG_WM(DEBUG_NOTIFY,text,textb); +void WiFiManager::DEBUG_WM(Generic text, Genericb textb) +{ + DEBUG_WM(DEBUG_NOTIFY, text, textb); } template -void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { - if(!_debug || _debugLevel < level) return; +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) + { _debugPort.print("MEM: "); _debugPort.println((String)ESP.getFreeHeap()); } _debugPort.print("*WM: "); - if(_debugLevel == DEBUG_DEV) _debugPort.print("["+(String)level+"] "); + if (_debugLevel == DEBUG_DEV) + _debugPort.print("[" + (String)level + "] "); _debugPort.print(text); - if(textb){ + if (textb) + { _debugPort.print(" "); _debugPort.print(textb); } @@ -2287,27 +2687,28 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { * @access public * @return {[type]} [description] */ -void WiFiManager::debugSoftAPConfig(){ - #ifdef ESP8266 - softap_config config; - wifi_softap_get_config(&config); - #elif defined(ESP32) - wifi_config_t conf_config; - esp_wifi_get_config(WIFI_IF_AP, &conf_config); // == ESP_OK - wifi_ap_config_t config = conf_config.ap; - #endif +void WiFiManager::debugSoftAPConfig() +{ +#ifdef ESP8266 + softap_config config; + wifi_softap_get_config(&config); +#elif defined(ESP32) + wifi_config_t conf_config; + esp_wifi_get_config(WIFI_IF_AP, &conf_config); // == ESP_OK + wifi_ap_config_t config = conf_config.ap; +#endif - DEBUG_WM(F("SoftAP Configuration")); - DEBUG_WM(FPSTR(D_HR)); - DEBUG_WM(F("ssid: "),(char *) config.ssid); - DEBUG_WM(F("password: "),(char *) config.password); - DEBUG_WM(F("ssid_len: "),config.ssid_len); - DEBUG_WM(F("channel: "),config.channel); - DEBUG_WM(F("authmode: "),config.authmode); - DEBUG_WM(F("ssid_hidden: "),config.ssid_hidden); - DEBUG_WM(F("max_connection: "),config.max_connection); - DEBUG_WM(F("beacon_interval: "),(String)config.beacon_interval + "(ms)"); - DEBUG_WM(FPSTR(D_HR)); + DEBUG_WM(F("SoftAP Configuration")); + DEBUG_WM(FPSTR(D_HR)); + DEBUG_WM(F("ssid: "), (char *)config.ssid); + DEBUG_WM(F("password: "), (char *)config.password); + DEBUG_WM(F("ssid_len: "), config.ssid_len); + DEBUG_WM(F("channel: "), config.channel); + DEBUG_WM(F("authmode: "), config.authmode); + DEBUG_WM(F("ssid_hidden: "), config.ssid_hidden); + DEBUG_WM(F("max_connection: "), config.max_connection); + DEBUG_WM(F("beacon_interval: "), (String)config.beacon_interval + "(ms)"); + DEBUG_WM(FPSTR(D_HR)); } /** @@ -2315,38 +2716,48 @@ void WiFiManager::debugSoftAPConfig(){ * @access public * @return {[type]} [description] */ -void WiFiManager::debugPlatformInfo(){ - #ifdef ESP8266 - system_print_meminfo(); - DEBUG_WM(F("getCoreVersion(): "),ESP.getCoreVersion()); - DEBUG_WM(F("system_get_sdk_version(): "),system_get_sdk_version()); - DEBUG_WM(F("system_get_boot_version():"),system_get_boot_version()); - DEBUG_WM(F("getFreeHeap(): "),(String)ESP.getFreeHeap()); - #elif defined(ESP32) - size_t freeHeap = heap_caps_get_free_size(MALLOC_CAP_8BIT); - DEBUG_WM("Free heap: ", freeHeap); - DEBUG_WM("ESP-IDF version: ", esp_get_idf_version()); - #endif +void WiFiManager::debugPlatformInfo() +{ +#ifdef ESP8266 + system_print_meminfo(); + DEBUG_WM(F("getCoreVersion(): "), ESP.getCoreVersion()); + DEBUG_WM(F("system_get_sdk_version(): "), system_get_sdk_version()); + DEBUG_WM(F("system_get_boot_version():"), system_get_boot_version()); + DEBUG_WM(F("getFreeHeap(): "), (String)ESP.getFreeHeap()); +#elif defined(ESP32) + size_t freeHeap = heap_caps_get_free_size(MALLOC_CAP_8BIT); + DEBUG_WM("Free heap: ", freeHeap); + DEBUG_WM("ESP-IDF version: ", esp_get_idf_version()); +#endif } -int WiFiManager::getRSSIasQuality(int RSSI) { +int WiFiManager::getRSSIasQuality(int RSSI) +{ int quality = 0; - if (RSSI <= -100) { + if (RSSI <= -100) + { quality = 0; - } else if (RSSI >= -50) { + } + else if (RSSI >= -50) + { quality = 100; - } else { + } + else + { quality = 2 * (RSSI + 100); } return quality; } /** Is this an IP? */ -boolean WiFiManager::isIp(String str) { - for (size_t i = 0; i < str.length(); i++) { +boolean WiFiManager::isIp(String str) +{ + for (size_t i = 0; i < str.length(); i++) + { int c = str.charAt(i); - if (c != '.' && (c < '0' || c > '9')) { + if (c != '.' && (c < '0' || c > '9')) + { return false; } } @@ -2354,25 +2765,31 @@ boolean WiFiManager::isIp(String str) { } /** IP to String? */ -String WiFiManager::toStringIp(IPAddress ip) { +String WiFiManager::toStringIp(IPAddress ip) +{ String res = ""; - for (int i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) + { res += String((ip >> (8 * i)) & 0xFF) + "."; } res += String(((ip >> 8 * 3)) & 0xFF); return res; } -boolean WiFiManager::validApPassword(){ +boolean WiFiManager::validApPassword() +{ // check that ap password is valid, return false - if (_apPassword == NULL) _apPassword = ""; - if (_apPassword != "") { - if (_apPassword.length() < 8 || _apPassword.length() > 63) { + if (_apPassword == NULL) + _apPassword = ""; + if (_apPassword != "") + { + if (_apPassword.length() < 8 || _apPassword.length() > 63) + { DEBUG_WM(F("AccessPoint set password is INVALID or <8 chars")); _apPassword = ""; return false; // @todo FATAL or fallback to empty ? } - DEBUG_WM(DEBUG_VERBOSE,F("AccessPoint set password is VALID")); + DEBUG_WM(DEBUG_VERBOSE, F("AccessPoint set password is VALID")); DEBUG_WM(_apPassword); } return true; @@ -2384,16 +2801,17 @@ boolean WiFiManager::validApPassword(){ * @param string str string to replace entities * @return string encoded string */ -String WiFiManager::htmlEntities(String str) { - str.replace("&","&"); - str.replace("<","<"); - str.replace(">",">"); +String WiFiManager::htmlEntities(String str) +{ + str.replace("&", "&"); + str.replace("<", "<"); + str.replace(">", ">"); // str.replace("'","'"); // str.replace("\"","""); // str.replace("/": "/"); // str.replace("`": "`"); // str.replace("=": "="); -return str; + return str; } /** @@ -2402,191 +2820,240 @@ return str; * @param {[type]} uint8_t status [description] * @return {[type]} [description] */ -String WiFiManager::getWLStatusString(uint8_t status){ - if(status <= 7) return WIFI_STA_STATUS[status]; +String WiFiManager::getWLStatusString(uint8_t status) +{ + if (status <= 7) + return WIFI_STA_STATUS[status]; return FPSTR(S_NA); } -String WiFiManager::encryptionTypeStr(uint8_t authmode) { +String WiFiManager::encryptionTypeStr(uint8_t authmode) +{ // DEBUG_WM("enc_tye: ",authmode); return AUTH_MODE_NAMES[authmode]; } -String WiFiManager::getModeString(uint8_t mode){ - if(mode <= 3) return WIFI_MODES[mode]; +String WiFiManager::getModeString(uint8_t mode) +{ + if (mode <= 3) + return WIFI_MODES[mode]; return FPSTR(S_NA); } -bool WiFiManager::WiFiSetCountry(){ +bool WiFiManager::WiFiSetCountry() +{ bool ret = false; - #ifdef ESP32 +#ifdef ESP32 // @todo check if wifi is init, no idea how, doesnt seem to be exposed - if(_wificountry == "") return ret; // skip not set - else if(WiFi.getMode() == WIFI_MODE_NULL); // exception if wifi not init! - else if(_wificountry == "US") ret = esp_wifi_set_country(&WM_COUNTRY_US) == ESP_OK; - else if(_wificountry == "JP") ret = esp_wifi_set_country(&WM_COUNTRY_JP) == ESP_OK; - else if(_wificountry == "CN") ret = esp_wifi_set_country(&WM_COUNTRY_CN) == ESP_OK; - else DEBUG_WM(DEBUG_ERROR,"[ERROR] country code not found"); - - if(ret) DEBUG_WM(DEBUG_VERBOSE,"esp_wifi_set_country: " + _wificountry); - else DEBUG_WM(DEBUG_ERROR,"[ERROR] esp_wifi_set_country failed"); - #endif + if (_wificountry == "") + return ret; // skip not set + else if (WiFi.getMode() == WIFI_MODE_NULL) + ; // exception if wifi not init! + else if (_wificountry == "US") + ret = esp_wifi_set_country(&WM_COUNTRY_US) == ESP_OK; + else if (_wificountry == "JP") + ret = esp_wifi_set_country(&WM_COUNTRY_JP) == ESP_OK; + else if (_wificountry == "CN") + ret = esp_wifi_set_country(&WM_COUNTRY_CN) == ESP_OK; + else + DEBUG_WM(DEBUG_ERROR, "[ERROR] country code not found"); + + if (ret) + DEBUG_WM(DEBUG_VERBOSE, "esp_wifi_set_country: " + _wificountry); + else + DEBUG_WM(DEBUG_ERROR, "[ERROR] esp_wifi_set_country failed"); +#endif return ret; } - -// set mode ignores WiFi.persistent -bool WiFiManager::WiFi_Mode(WiFiMode_t m,bool persistent) { - bool ret; - #ifdef ESP8266 - if((wifi_get_opmode() == (uint8) m ) && !persistent) { - return true; - } - ETS_UART_INTR_DISABLE(); - if(persistent) ret = wifi_set_opmode(m); - else ret = wifi_set_opmode_current(m); - ETS_UART_INTR_ENABLE(); - return ret; - #elif defined(ESP32) - if(persistent && esp32persistent) WiFi.persistent(true); - ret = WiFi.mode(m); // @todo persistent check persistant mode , NI - if(persistent && esp32persistent) WiFi.persistent(false); - return ret; - #endif +// set mode ignores WiFi.persistent +bool WiFiManager::WiFi_Mode(WiFiMode_t m, bool persistent) +{ + bool ret; +#ifdef ESP8266 + if ((wifi_get_opmode() == (uint8)m) && !persistent) + { + return true; + } + ETS_UART_INTR_DISABLE(); + if (persistent) + ret = wifi_set_opmode(m); + else + ret = wifi_set_opmode_current(m); + ETS_UART_INTR_ENABLE(); + return ret; +#elif defined(ESP32) + if (persistent && esp32persistent) + WiFi.persistent(true); + ret = WiFi.mode(m); // @todo persistent check persistant mode , NI + if (persistent && esp32persistent) + WiFi.persistent(false); + return ret; +#endif } -bool WiFiManager::WiFi_Mode(WiFiMode_t m) { - return WiFi_Mode(m,false); +bool WiFiManager::WiFi_Mode(WiFiMode_t m) +{ + return WiFi_Mode(m, false); } // sta disconnect without persistent -bool WiFiManager::WiFi_Disconnect() { - #ifdef ESP8266 - if((WiFi.getMode() & WIFI_STA) != 0) { - bool ret; - DEBUG_WM(DEBUG_DEV,F("WIFI station disconnect")); - ETS_UART_INTR_DISABLE(); // @todo probably not needed - ret = wifi_station_disconnect(); - ETS_UART_INTR_ENABLE(); - return ret; - } - #elif defined(ESP32) - DEBUG_WM(DEBUG_DEV,F("WIFI station disconnect")); - return WiFi.disconnect(); // not persistent atm - #endif - return false; +bool WiFiManager::WiFi_Disconnect() +{ +#ifdef ESP8266 + if ((WiFi.getMode() & WIFI_STA) != 0) + { + bool ret; + DEBUG_WM(DEBUG_DEV, F("WIFI station disconnect")); + ETS_UART_INTR_DISABLE(); // @todo probably not needed + ret = wifi_station_disconnect(); + ETS_UART_INTR_ENABLE(); + return ret; + } +#elif defined(ESP32) + DEBUG_WM(DEBUG_DEV, F("WIFI station disconnect")); + return WiFi.disconnect(); // not persistent atm +#endif + return false; } // toggle STA without persistent -bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) { - DEBUG_WM(DEBUG_DEV,F("WiFi station enable")); - #ifdef ESP8266 - WiFiMode_t newMode; - WiFiMode_t currentMode = WiFi.getMode(); - bool isEnabled = (currentMode & WIFI_STA) != 0; - if(enable) newMode = (WiFiMode_t)(currentMode | WIFI_STA); - else newMode = (WiFiMode_t)(currentMode & (~WIFI_STA)); +bool WiFiManager::WiFi_enableSTA(bool enable, bool persistent) +{ + DEBUG_WM(DEBUG_DEV, F("WiFi station enable")); +#ifdef ESP8266 + WiFiMode_t newMode; + WiFiMode_t currentMode = WiFi.getMode(); + bool isEnabled = (currentMode & WIFI_STA) != 0; + if (enable) + newMode = (WiFiMode_t)(currentMode | WIFI_STA); + else + newMode = (WiFiMode_t)(currentMode & (~WIFI_STA)); - if((isEnabled != enable) || persistent) { - if(enable) { - if(persistent) DEBUG_WM(DEBUG_DEV,F("enableSTA PERSISTENT ON")); - return WiFi_Mode(newMode,persistent); - } else { - return WiFi_Mode(newMode,persistent); - } - } else { - return true; - } - #elif defined(ESP32) - bool ret; - if(persistent && esp32persistent) WiFi.persistent(true); - ret = WiFi.enableSTA(enable); // @todo handle persistent when it is implemented in platform - if(persistent && esp32persistent) WiFi.persistent(false); - return ret; - #endif + if ((isEnabled != enable) || persistent) + { + if (enable) + { + if (persistent) + DEBUG_WM(DEBUG_DEV, F("enableSTA PERSISTENT ON")); + return WiFi_Mode(newMode, persistent); + } + else + { + return WiFi_Mode(newMode, persistent); + } + } + else + { + return true; + } +#elif defined(ESP32) + bool ret; + if (persistent && esp32persistent) + WiFi.persistent(true); + ret = WiFi.enableSTA(enable); // @todo handle persistent when it is implemented in platform + if (persistent && esp32persistent) + WiFi.persistent(false); + return ret; +#endif } -bool WiFiManager::WiFi_enableSTA(bool enable) { - return WiFi_enableSTA(enable,false); +bool WiFiManager::WiFi_enableSTA(bool enable) +{ + return WiFi_enableSTA(enable, false); } -bool WiFiManager::WiFi_eraseConfig() { - #ifdef ESP8266 - #ifndef WM_FIXERASECONFIG - return ESP.eraseConfig(); - #else - // erase config BUG replacement - // https://github.com/esp8266/Arduino/pull/3635 - const size_t cfgSize = 0x4000; - size_t cfgAddr = ESP.getFlashChipSize() - cfgSize; +bool WiFiManager::WiFi_eraseConfig() +{ +#ifdef ESP8266 +#ifndef WM_FIXERASECONFIG + return ESP.eraseConfig(); +#else + // erase config BUG replacement + // https://github.com/esp8266/Arduino/pull/3635 + const size_t cfgSize = 0x4000; + size_t cfgAddr = ESP.getFlashChipSize() - cfgSize; - for (size_t offset = 0; offset < cfgSize; offset += SPI_FLASH_SEC_SIZE) { - if (!ESP.flashEraseSector((cfgAddr + offset) / SPI_FLASH_SEC_SIZE)) { - return false; - } - } - return true; - #endif - #elif defined(ESP32) - bool ret; - WiFi.mode(WIFI_AP_STA); // cannot erase if not in STA mode ! - WiFi.persistent(true); - ret = WiFi.disconnect(true,true); - WiFi.persistent(false); - return ret; - #endif + for (size_t offset = 0; offset < cfgSize; offset += SPI_FLASH_SEC_SIZE) + { + if (!ESP.flashEraseSector((cfgAddr + offset) / SPI_FLASH_SEC_SIZE)) + { + return false; + } + } + return true; +#endif +#elif defined(ESP32) + bool ret; + WiFi.mode(WIFI_AP_STA); // cannot erase if not in STA mode ! + WiFi.persistent(true); + ret = WiFi.disconnect(true, true); + WiFi.persistent(false); + return ret; +#endif } -uint8_t WiFiManager::WiFi_softap_num_stations(){ - #ifdef ESP8266 - return wifi_softap_get_station_num(); - #elif defined(ESP32) - return WiFi.softAPgetStationNum(); - #endif +uint8_t WiFiManager::WiFi_softap_num_stations() +{ +#ifdef ESP8266 + return wifi_softap_get_station_num(); +#elif defined(ESP32) + return WiFi.softAPgetStationNum(); +#endif } -bool WiFiManager::WiFi_hasAutoConnect(){ +bool WiFiManager::WiFi_hasAutoConnect() +{ return WiFi_SSID() != ""; } -String WiFiManager::WiFi_SSID(){ - #ifdef ESP8266 - return WiFi.SSID(); - #elif defined(ESP32) - //@todo , workaround only when not connected - wifi_config_t conf; - esp_wifi_get_config(WIFI_IF_STA, &conf); - return String(reinterpret_cast(conf.sta.ssid)); - #endif +String WiFiManager::WiFi_SSID() +{ +#ifdef ESP8266 + return WiFi.SSID(); +#elif defined(ESP32) + //@todo , workaround only when not connected + wifi_config_t conf; + esp_wifi_get_config(WIFI_IF_STA, &conf); + return String(reinterpret_cast(conf.sta.ssid)); +#endif } #ifdef ESP32 -void WiFiManager::WiFiEvent(WiFiEvent_t event,system_event_info_t info){ - DEBUG_WM(DEBUG_VERBOSE,"[EVENT]",event); - if(event == SYSTEM_EVENT_STA_DISCONNECTED){ - DEBUG_WM(DEBUG_VERBOSE,"[EVENT] WIFI_REASON:",info.disconnected.reason); - if(info.disconnected.reason == WIFI_REASON_AUTH_EXPIRE || info.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(); - if(info.disconnected.reason == WIFI_REASON_NO_AP_FOUND) DEBUG_WM(DEBUG_VERBOSE,"[EVENT] WIFI_REASON: NO_AP_FOUND"); - #ifdef esp32autoreconnect - DEBUG_WM(DEBUG_VERBOSE,"[Event] SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); - WiFi.reconnect(); - #endif +void WiFiManager::WiFiEvent(WiFiEvent_t event, system_event_info_t info) +{ + DEBUG_WM(DEBUG_VERBOSE, "[EVENT]", event); + if (event == SYSTEM_EVENT_STA_DISCONNECTED) + { + DEBUG_WM(DEBUG_VERBOSE, "[EVENT] WIFI_REASON:", info.disconnected.reason); + if (info.disconnected.reason == WIFI_REASON_AUTH_EXPIRE || info.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(); + if (info.disconnected.reason == WIFI_REASON_NO_AP_FOUND) + DEBUG_WM(DEBUG_VERBOSE, "[EVENT] WIFI_REASON: NO_AP_FOUND"); +#ifdef esp32autoreconnect + DEBUG_WM(DEBUG_VERBOSE, "[Event] SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); + WiFi.reconnect(); +#endif } - else if(event == SYSTEM_EVENT_SCAN_DONE){ + else if (event == SYSTEM_EVENT_SCAN_DONE) + { uint16_t scans = WiFi.scanComplete(); WiFi_scanComplete(scans); } } #endif -void WiFiManager::WiFi_autoReconnect(){ - #ifdef ESP8266 - WiFi.setAutoReconnect(_wifiAutoReconnect); - #elif defined(ESP32) - // if(_wifiAutoReconnect){ - DEBUG_WM(DEBUG_VERBOSE,"ESP32 event handler enabled"); - using namespace std::placeholders; - WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2)); - // } - #endif +void WiFiManager::WiFi_autoReconnect() +{ +#ifdef ESP8266 + WiFi.setAutoReconnect(_wifiAutoReconnect); +#elif defined(ESP32) + // if(_wifiAutoReconnect){ + DEBUG_WM(DEBUG_VERBOSE, "ESP32 event handler enabled"); + using namespace std::placeholders; + WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent, this, _1, _2)); + // } +#endif } diff --git a/WiFiManager.h b/WiFiManager.h index fa18c1c..025ed54 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -193,6 +193,8 @@ class WiFiManager void setAPCallback( std::function func ); //called when settings have been changed and connection was successful void setSaveConfigCallback( std::function func ); + //called when settings before have been changed and connection was successful + void setPreSaveConfigCallback( std::function func ); //adds a custom parameter, returns false on failure bool addParameter(WiFiManagerParameter *p); //if this is set, it will exit after config, even if connection is unsuccessful. @@ -461,6 +463,7 @@ class WiFiManager // callbacks std::function _apcallback; std::function _savecallback; + std::function _presavecallback; template auto optionalIPFromString(T *obj, const char *s) -> decltype( obj->fromString(s) ) { From f9d1c9bd6f46502455b97a92b5d797a7d529a275 Mon Sep 17 00:00:00 2001 From: ayeah Date: Mon, 17 Sep 2018 01:19:18 +0700 Subject: [PATCH 408/424] reformat --- WiFiManager.cpp | 2614 ++++++++++++++++++++--------------------------- 1 file changed, 1084 insertions(+), 1530 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 9fd7539..85cc3df 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -22,103 +22,84 @@ uint8_t WiFiManager::_lastconxresulttmp = WL_IDLE_STATUS; * -------------------------------------------------------------------------------- **/ -WiFiManagerParameter::WiFiManagerParameter(const char *custom) -{ - _id = NULL; - _placeholder = NULL; - _length = 1; - _value = NULL; +WiFiManagerParameter::WiFiManagerParameter(const char *custom) { + _id = NULL; + _placeholder = NULL; + _length = 1; + _value = NULL; _labelPlacement = WFM_LABEL_BEFORE; - _customHTML = custom; + _customHTML = custom; } -WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder) -{ +WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder) { init(id, placeholder, "", 0, "", WFM_LABEL_BEFORE); } -WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length) -{ +WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length) { init(id, placeholder, defaultValue, length, "", WFM_LABEL_BEFORE); } -WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) -{ +WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom) { init(id, placeholder, defaultValue, length, custom, WFM_LABEL_BEFORE); } -WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) -{ +WiFiManagerParameter::WiFiManagerParameter(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) { init(id, placeholder, defaultValue, length, custom, labelPlacement); } -void WiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) -{ - _id = id; - _placeholder = placeholder; +void WiFiManagerParameter::init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement) { + _id = id; + _placeholder = placeholder; _labelPlacement = labelPlacement; - _customHTML = custom; - setValue(defaultValue, length); + _customHTML = custom; + setValue(defaultValue,length); } -WiFiManagerParameter::~WiFiManagerParameter() -{ - if (_value != NULL) - { +WiFiManagerParameter::~WiFiManagerParameter() { + if (_value != NULL) { delete[] _value; } - _length = 0; // setting length 0, ideally the entire parameter should be removed, or added to wifimanager scope so it follows + _length=0; // setting length 0, ideally the entire parameter should be removed, or added to wifimanager scope so it follows } -void WiFiManagerParameter::setValue(const char *defaultValue, int length) -{ - if (!_id) - { +void WiFiManagerParameter::setValue(const char *defaultValue, int length) { + if(!_id){ // Serial.println("cannot set value of this parameter"); return; } - _length = length; + _length = length; int deflength = strlen(defaultValue); // length actual - // use the defult length if it's longer, + // use the defult length if it's longer, // @todo consider it might be useful to fail, so user knows they were wrong - if (_length < length) - { + if(_length < length){ // Serial.println("defaultValue length mismatch"); _length = deflength; } _value = new char[_length + 1]; - for (int i = 0; i < _length + 1; i++) - { + for (int i = 0; i < _length + 1; i++) { _value[i] = 0; } - if (defaultValue != NULL) - { + if (defaultValue != NULL) { strncpy(_value, defaultValue, _length); _value[_length] = '\0'; // explicit null } } -const char *WiFiManagerParameter::getValue() -{ +const char* WiFiManagerParameter::getValue() { return _value; } -const char *WiFiManagerParameter::getID() -{ +const char* WiFiManagerParameter::getID() { return _id; } -const char *WiFiManagerParameter::getPlaceholder() -{ +const char* WiFiManagerParameter::getPlaceholder() { return _placeholder; } -int WiFiManagerParameter::getValueLength() -{ +int WiFiManagerParameter::getValueLength() { return _length; } -int WiFiManagerParameter::getLabelPlacement() -{ +int WiFiManagerParameter::getLabelPlacement() { return _labelPlacement; } -const char *WiFiManagerParameter::getCustomHTML() -{ +const char* WiFiManagerParameter::getCustomHTML() { return _customHTML; } @@ -127,54 +108,45 @@ const char *WiFiManagerParameter::getCustomHTML() * @access public * @param {[type]} WiFiManagerParameter *p [description] */ -bool WiFiManager::addParameter(WiFiManagerParameter *p) -{ +bool WiFiManager::addParameter(WiFiManagerParameter *p) { // check param id is valid, unless null - if (p->getID()) - { - for (size_t i = 0; i < strlen(p->getID()); i++) - { - if (!(isAlphaNumeric(p->getID()[i])) && !(p->getID()[i] == '_')) - { - DEBUG_WM(DEBUG_ERROR, "[ERROR] parameter IDs can only contain alpha numeric chars"); + if(p->getID()){ + for (size_t i = 0; i < strlen(p->getID()); i++){ + if(!(isAlphaNumeric(p->getID()[i])) && !(p->getID()[i]=='_')){ + DEBUG_WM(DEBUG_ERROR,"[ERROR] parameter IDs can only contain alpha numeric chars"); return false; - } + } } } // init params if never malloc - if (_params == NULL) - { - DEBUG_WM(DEBUG_DEV, "allocating params bytes:", _max_params * sizeof(WiFiManagerParameter *)); - _params = (WiFiManagerParameter **)malloc(_max_params * sizeof(WiFiManagerParameter *)); + if(_params == NULL){ + DEBUG_WM(DEBUG_DEV,"allocating params bytes:",_max_params * sizeof(WiFiManagerParameter*)); + _params = (WiFiManagerParameter**)malloc(_max_params * sizeof(WiFiManagerParameter*)); } // resize the params array by increment of WIFI_MANAGER_MAX_PARAMS - if (_paramsCount == _max_params) - { + if(_paramsCount == _max_params){ _max_params += WIFI_MANAGER_MAX_PARAMS; - DEBUG_WM(DEBUG_DEV, F("Updated _max_params:"), _max_params); - DEBUG_WM(DEBUG_DEV, "re-allocating params bytes:", _max_params * sizeof(WiFiManagerParameter *)); - WiFiManagerParameter **new_params = (WiFiManagerParameter **)realloc(_params, _max_params * sizeof(WiFiManagerParameter *)); + DEBUG_WM(DEBUG_DEV,F("Updated _max_params:"),_max_params); + DEBUG_WM(DEBUG_DEV,"re-allocating params bytes:",_max_params * sizeof(WiFiManagerParameter*)); + WiFiManagerParameter** new_params = (WiFiManagerParameter**)realloc(_params, _max_params * sizeof(WiFiManagerParameter*)); // DEBUG_WM(WIFI_MANAGER_MAX_PARAMS); // DEBUG_WM(_paramsCount); // DEBUG_WM(_max_params); - if (new_params != NULL) - { + if (new_params != NULL) { _params = new_params; - } - else - { - DEBUG_WM(DEBUG_ERROR, "[ERROR] failed to realloc params, size not increased!"); + } else { + DEBUG_WM(DEBUG_ERROR,"[ERROR] failed to realloc params, size not increased!"); return false; } } _params[_paramsCount] = p; _paramsCount++; - - DEBUG_WM(DEBUG_VERBOSE, "Added Parameter:", p->getID()); + + DEBUG_WM(DEBUG_VERBOSE,"Added Parameter:",p->getID()); return true; } @@ -185,62 +157,51 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) **/ // constructors -WiFiManager::WiFiManager(Stream &consolePort) : _debugPort(consolePort) -{ +WiFiManager::WiFiManager(Stream& consolePort):_debugPort(consolePort){ WiFiManagerInit(); } -WiFiManager::WiFiManager() : WiFiManager(Serial) -{ +WiFiManager::WiFiManager():WiFiManager(Serial) { } -void WiFiManager::WiFiManagerInit() -{ +void WiFiManager::WiFiManagerInit(){ setMenu(_menuIdsDefault); - if (_debug && _debugLevel > DEBUG_DEV) - debugPlatformInfo(); + if(_debug && _debugLevel > DEBUG_DEV) debugPlatformInfo(); _max_params = WIFI_MANAGER_MAX_PARAMS; } // destructor -WiFiManager::~WiFiManager() -{ +WiFiManager::~WiFiManager() { _end(); // parameters // @todo belongs to wifimanagerparameter - if (_params != NULL) - { - DEBUG_WM(DEBUG_DEV, F("freeing allocated params!")); + if (_params != NULL){ + DEBUG_WM(DEBUG_DEV,F("freeing allocated params!")); free(_params); _params = NULL; } - DEBUG_WM(DEBUG_DEV, F("unloading")); + DEBUG_WM(DEBUG_DEV,F("unloading")); } -void WiFiManager::_begin() -{ - if (_hasBegun) - return; +void WiFiManager::_begin(){ + if(_hasBegun) return; _usermode = WiFi.getMode(); -#ifndef ESP32 + #ifndef ESP32 WiFi.persistent(false); // disable persistent so scannetworks and mode switching do not cause overwrites -#endif + #endif } -void WiFiManager::_end() -{ - if (_userpersistent) - WiFi.persistent(true); // reenable persistent, there is no getter we rely on _userpersistent +void WiFiManager::_end(){ + if(_userpersistent) WiFi.persistent(true); // reenable persistent, there is no getter we rely on _userpersistent // if(_usermode != WIFI_OFF) WiFi.mode(_usermode); } // AUTOCONNECT -boolean WiFiManager::autoConnect() -{ - String ssid = _wifissidprefix + "_" + String(WIFI_getChipId(), HEX); +boolean WiFiManager::autoConnect() { + String ssid = _wifissidprefix + "_" + String(WIFI_getChipId(),HEX); return autoConnect(ssid.c_str(), NULL); } @@ -251,25 +212,22 @@ boolean WiFiManager::autoConnect() * @param {[type]} char const *apPassword [description] * @return {[type]} [description] */ -boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) -{ +boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { DEBUG_WM(F("AutoConnect")); _begin(); // attempt to connect using saved settings, on fail fallback to AP config portal - if (!WiFi.enableSTA(true)) - { + if(!WiFi.enableSTA(true)){ // handle failure mode Brownout detector etc. - DEBUG_WM(DEBUG_ERROR, "[FATAL] Unable to enable wifi!"); + DEBUG_WM(DEBUG_ERROR,"[FATAL] Unable to enable wifi!"); return false; } - + WiFiSetCountry(); -#ifdef ESP32 - if (esp32persistent) - WiFi.persistent(false); // disable persistent for esp32 after esp_wifi_start or else saves wont work -#endif + #ifdef ESP32 + if(esp32persistent) WiFi.persistent(false); // disable persistent for esp32 after esp_wifi_start or else saves wont work + #endif _usermode = WIFI_STA; @@ -279,76 +237,67 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) WiFi_autoReconnect(); // set hostname before stating - if ((String)_hostname != "") - { - DEBUG_WM(DEBUG_VERBOSE, "Setting hostname:", _hostname); + if((String)_hostname != ""){ + DEBUG_WM(DEBUG_VERBOSE,"Setting hostname:",_hostname); bool res = true; -#ifdef ESP8266 - res = WiFi.hostname(_hostname); -#ifdef ESP8266MDNS_H - DEBUG_WM(DEBUG_VERBOSE, "Setting MDNS hostname"); - if (MDNS.begin(_hostname)) - { - MDNS.addService("http", "tcp", 80); - } -#endif -#elif defined(ESP32) - // @note hostname must be set after STA_START - delay(200); // do not remove, give time for STA_START - res = WiFi.setHostname(_hostname); -#ifdef ESP32MDNS_H - DEBUG_WM(DEBUG_VERBOSE, "Setting MDNS hostname"); - if (MDNS.begin(_hostname)) - { - MDNS.addService("http", "tcp", 80); - } -#endif -#endif - - if (!res) - DEBUG_WM(DEBUG_ERROR, F("[ERROR] hostname: set failed!")); - - if (WiFi.status() == WL_CONNECTED) - { - DEBUG_WM(DEBUG_VERBOSE, F("reconnecting to set new hostname")); + #ifdef ESP8266 + res = WiFi.hostname(_hostname); + #ifdef ESP8266MDNS_H + DEBUG_WM(DEBUG_VERBOSE,"Setting MDNS hostname"); + if(MDNS.begin(_hostname)){ + MDNS.addService("http", "tcp", 80); + } + #endif + #elif defined(ESP32) + // @note hostname must be set after STA_START + delay(200); // do not remove, give time for STA_START + res = WiFi.setHostname(_hostname); + #ifdef ESP32MDNS_H + DEBUG_WM(DEBUG_VERBOSE,"Setting MDNS hostname"); + if(MDNS.begin(_hostname)){ + MDNS.addService("http", "tcp", 80); + } + #endif + #endif + + if(!res)DEBUG_WM(DEBUG_ERROR,F("[ERROR] hostname: set failed!")); + + if(WiFi.status() == WL_CONNECTED){ + DEBUG_WM(DEBUG_VERBOSE,F("reconnecting to set new hostname")); // WiFi.reconnect(); // This does not reset dhcp WiFi_Disconnect(); delay(200); // do not remove, need a delay for disconnect to change status() } } - // if already connected, or try stored connect + // if already connected, or try stored connect // @note @todo ESP32 has no autoconnect, so connectwifi will always be called unless user called begin etc before // @todo check if correct ssid == saved ssid when already connected bool connected = false; - if (WiFi.status() == WL_CONNECTED) - { + if (WiFi.status() == WL_CONNECTED){ connected = true; DEBUG_WM(F("AutoConnect: ESP Already Connected")); setSTAConfig(); } - if (connected || connectWifi("", "") == WL_CONNECTED) - { + if(connected || connectWifi("", "") == WL_CONNECTED){ //connected DEBUG_WM(F("AutoConnect: SUCCESS")); - DEBUG_WM(F("STA IP Address:"), WiFi.localIP()); + DEBUG_WM(F("STA IP Address:"),WiFi.localIP()); _lastconxresult = WL_CONNECTED; - if ((String)_hostname != "") - { -#ifdef ESP8266 - DEBUG_WM(DEBUG_DEV, "hostname: STA", WiFi.hostname()); -#elif defined(ESP32) - DEBUG_WM(DEBUG_DEV, "hostname: STA", WiFi.getHostname()); -#endif + if((String)_hostname != ""){ + #ifdef ESP8266 + DEBUG_WM(DEBUG_DEV,"hostname: STA",WiFi.hostname()); + #elif defined(ESP32) + DEBUG_WM(DEBUG_DEV,"hostname: STA",WiFi.getHostname()); + #endif } return true; } // possibly skip the config portal - if (!_enableConfigPortal) - { + if (!_enableConfigPortal) { return false; } @@ -359,88 +308,71 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) } // CONFIG PORTAL -bool WiFiManager::startAP() -{ +bool WiFiManager::startAP(){ bool ret = true; - DEBUG_WM(F("StartAP with SSID: "), _apName); + DEBUG_WM(F("StartAP with SSID: "),_apName); // do AP callback if set - if (_apcallback != NULL) - { + if ( _apcallback != NULL) { _apcallback(this); } // setup optional soft AP static ip config - if (_ap_static_ip) - { + if (_ap_static_ip) { DEBUG_WM(F("Custom AP IP/GW/Subnet:")); - if (!WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn)) - { - DEBUG_WM(DEBUG_ERROR, "[ERROR] softAPConfig failed!"); + if(!WiFi.softAPConfig(_ap_static_ip, _ap_static_gw, _ap_static_sn)){ + DEBUG_WM(DEBUG_ERROR,"[ERROR] softAPConfig failed!"); } } -#ifdef ESP8266 - // @bug workaround for bug #4372 https://github.com/esp8266/Arduino/issues/4372 - if (!WiFi.enableAP(true)) - { - DEBUG_WM(DEBUG_ERROR, "[ERROR] enableAP failed!"); - return false; - } - delay(500); // workaround delay -#endif + #ifdef ESP8266 + // @bug workaround for bug #4372 https://github.com/esp8266/Arduino/issues/4372 + if(!WiFi.enableAP(true)) { + DEBUG_WM(DEBUG_ERROR,"[ERROR] enableAP failed!"); + return false; + } + delay(500); // workaround delay + #endif - if (_channelSync) - { - DEBUG_WM(DEBUG_VERBOSE, "Starting AP on channel:", WiFi.channel()); - } + if(_channelSync){ + DEBUG_WM(DEBUG_VERBOSE,"Starting AP on channel:",WiFi.channel()); + } // start soft AP with password or anonymous - if (_apPassword != "") - { - if (_channelSync) - { - ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(), WiFi.channel()); + if (_apPassword != "") { + if(_channelSync){ + ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(),WiFi.channel()); + } + else{ + ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str());//password option } - else - { - ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str()); //password option - } - } - else - { - DEBUG_WM(DEBUG_VERBOSE, F("AP has anonymous access!")); - if (_channelSync) - { - ret = WiFi.softAP(_apName.c_str(), "", WiFi.channel()); - } - else - { + } else { + DEBUG_WM(DEBUG_VERBOSE,F("AP has anonymous access!")); + if(_channelSync){ + ret = WiFi.softAP(_apName.c_str(),"",WiFi.channel()); + } + else{ ret = WiFi.softAP(_apName.c_str()); - } + } } - if (_debugLevel > DEBUG_DEV) - debugSoftAPConfig(); + if(_debugLevel > DEBUG_DEV) debugSoftAPConfig(); - if (!ret) - DEBUG_WM(DEBUG_ERROR, "[ERROR] There was a problem starting the AP"); + if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] There was a problem starting the AP"); // @todo add softAP retry here - + delay(500); // slight delay to make sure we get an AP IP - DEBUG_WM(F("AP IP address:"), WiFi.softAPIP()); + DEBUG_WM(F("AP IP address:"),WiFi.softAPIP()); -// set ap hostname -#ifdef ESP32 - if (ret && (String)_hostname != "") - { - DEBUG_WM(DEBUG_VERBOSE, "setting softAP Hostname:", _hostname); - bool res = WiFi.softAPsetHostname(_hostname); - if (!res) - DEBUG_WM(DEBUG_ERROR, F("[ERROR] hostname: AP set failed!")); - DEBUG_WM(DEBUG_DEV, F("hostname: AP"), WiFi.softAPgetHostname()); - } -#endif + // set ap hostname + #ifdef ESP32 + if(ret && (String)_hostname != ""){ + DEBUG_WM(DEBUG_VERBOSE,"setting softAP Hostname:",_hostname); + bool res = WiFi.softAPsetHostname(_hostname); + if(!res)DEBUG_WM(DEBUG_ERROR,F("[ERROR] hostname: AP set failed!")); + DEBUG_WM(DEBUG_DEV,F("hostname: AP"),WiFi.softAPgetHostname()); + } + #endif return ret; } @@ -450,10 +382,8 @@ bool WiFiManager::startAP() * @access public * @return {[type]} [description] */ -void WiFiManager::startWebPortal() -{ - if (configPortalActive || webPortalActive) - return; +void WiFiManager::startWebPortal() { + if(configPortalActive || webPortalActive) return; setupConfigPortal(); webPortalActive = true; } @@ -463,56 +393,44 @@ void WiFiManager::startWebPortal() * @access public * @return {[type]} [description] */ -void WiFiManager::stopWebPortal() -{ - if (!configPortalActive && !webPortalActive) - return; - DEBUG_WM(DEBUG_VERBOSE, F("Stopping Web Portal")); +void WiFiManager::stopWebPortal() { + if(!configPortalActive && !webPortalActive) return; + DEBUG_WM(DEBUG_VERBOSE,F("Stopping Web Portal")); webPortalActive = false; stopConfigPortal(); } -boolean WiFiManager::configPortalHasTimeout() -{ +boolean WiFiManager::configPortalHasTimeout(){ - if (_configPortalTimeout == 0 || (_cpClientCheck && (WiFi_softap_num_stations() > 0))) - { - if (millis() - timer > 30000) - { - timer = millis(); - DEBUG_WM(DEBUG_VERBOSE, "NUM CLIENTS: " + (String)WiFi_softap_num_stations()); - } - _configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts - return false; - } - // handle timeout - if (_webClientCheck && (_webPortalAccessed > _configPortalStart) > 0) - _configPortalStart = _webPortalAccessed; - - if (millis() > _configPortalStart + _configPortalTimeout) - { - DEBUG_WM(F("config portal has timed out")); - return true; - } - else if (_debugLevel > 0) - { - // log timeout - if (_debug) - { - uint16_t logintvl = 30000; // how often to emit timeing out counter logging - if ((millis() - timer) > logintvl) - { + if(_configPortalTimeout == 0 || (_cpClientCheck && (WiFi_softap_num_stations() > 0))){ + if(millis() - timer > 30000){ timer = millis(); - DEBUG_WM(DEBUG_VERBOSE, F("Portal Timeout In"), (String)((_configPortalStart + _configPortalTimeout - millis()) / 1000) + (String)F(" seconds")); + DEBUG_WM(DEBUG_VERBOSE,"NUM CLIENTS: " + (String)WiFi_softap_num_stations()); + } + _configPortalStart = millis(); // kludge, bump configportal start time to skew timeouts + return false; + } + // handle timeout + if(_webClientCheck && (_webPortalAccessed>_configPortalStart)>0) _configPortalStart = _webPortalAccessed; + + if(millis() > _configPortalStart + _configPortalTimeout){ + DEBUG_WM(F("config portal has timed out")); + return true; + } else if(_debugLevel > 0) { + // log timeout + if(_debug){ + uint16_t logintvl = 30000; // how often to emit timeing out counter logging + if((millis() - timer) > logintvl){ + timer = millis(); + DEBUG_WM(DEBUG_VERBOSE,F("Portal Timeout In"),(String)((_configPortalStart + _configPortalTimeout-millis())/1000) + (String)F(" seconds")); + } } } - } - return false; + return false; } -void WiFiManager::setupConfigPortal() -{ +void WiFiManager::setupConfigPortal() { DEBUG_WM(F("Starting Web Portal")); @@ -523,34 +441,32 @@ void WiFiManager::setupConfigPortal() /* Setup the DNS server redirecting all the domains to the apIP */ dnsServer->setErrorReplyCode(DNSReplyCode::NoError); // DEBUG_WM("dns server started port: ",DNS_PORT); - DEBUG_WM(DEBUG_DEV, "dns server started with ip: ", WiFi.softAPIP()); + DEBUG_WM(DEBUG_DEV,"dns server started with ip: ",WiFi.softAPIP()); dnsServer->start(DNS_PORT, F("*"), WiFi.softAPIP()); /* Setup httpd callbacks, web pages: root, wifi config pages, SO captive portal detectors and not found. */ - server->on(String(FPSTR(R_root)).c_str(), std::bind(&WiFiManager::handleRoot, this)); - server->on(String(FPSTR(R_wifi)).c_str(), std::bind(&WiFiManager::handleWifi, this, true)); + server->on(String(FPSTR(R_root)).c_str(), std::bind(&WiFiManager::handleRoot, this)); + server->on(String(FPSTR(R_wifi)).c_str(), std::bind(&WiFiManager::handleWifi, this, true)); server->on(String(FPSTR(R_wifinoscan)).c_str(), std::bind(&WiFiManager::handleWifi, this, false)); - server->on(String(FPSTR(R_wifisave)).c_str(), std::bind(&WiFiManager::handleWifiSave, this)); - server->on(String(FPSTR(R_info)).c_str(), std::bind(&WiFiManager::handleInfo, this)); - server->on(String(FPSTR(R_param)).c_str(), std::bind(&WiFiManager::handleParam, this)); - server->on(String(FPSTR(R_paramsave)).c_str(), std::bind(&WiFiManager::handleParamSave, this)); - server->on(String(FPSTR(R_restart)).c_str(), std::bind(&WiFiManager::handleReset, this)); - server->on(String(FPSTR(R_exit)).c_str(), std::bind(&WiFiManager::handleExit, this)); - server->on(String(FPSTR(R_close)).c_str(), std::bind(&WiFiManager::handleClose, this)); - server->on(String(FPSTR(R_erase)).c_str(), std::bind(&WiFiManager::handleErase, this, false)); - server->on(String(FPSTR(R_status)).c_str(), std::bind(&WiFiManager::handleWiFiStatus, this)); - server->onNotFound(std::bind(&WiFiManager::handleNotFound, this)); - + server->on(String(FPSTR(R_wifisave)).c_str(), std::bind(&WiFiManager::handleWifiSave, this)); + server->on(String(FPSTR(R_info)).c_str(), std::bind(&WiFiManager::handleInfo, this)); + server->on(String(FPSTR(R_param)).c_str(), std::bind(&WiFiManager::handleParam, this)); + server->on(String(FPSTR(R_paramsave)).c_str(), std::bind(&WiFiManager::handleParamSave, this)); + server->on(String(FPSTR(R_restart)).c_str(), std::bind(&WiFiManager::handleReset, this)); + server->on(String(FPSTR(R_exit)).c_str(), std::bind(&WiFiManager::handleExit, this)); + server->on(String(FPSTR(R_close)).c_str(), std::bind(&WiFiManager::handleClose, this)); + server->on(String(FPSTR(R_erase)).c_str(), std::bind(&WiFiManager::handleErase, this, false)); + server->on(String(FPSTR(R_status)).c_str(), std::bind(&WiFiManager::handleWiFiStatus, this)); + server->onNotFound (std::bind(&WiFiManager::handleNotFound, this)); + server->begin(); // Web server start - DEBUG_WM(DEBUG_VERBOSE, F("HTTP server started")); + DEBUG_WM(DEBUG_VERBOSE,F("HTTP server started")); - if (_preloadwifiscan) - WiFi_scanNetworks(true, true); // preload wifiscan , async + if(_preloadwifiscan) WiFi_scanNetworks(true,true); // preload wifiscan , async } -boolean WiFiManager::startConfigPortal() -{ - String ssid = _wifissidprefix + "_" + String(WIFI_getChipId(), HEX); +boolean WiFiManager::startConfigPortal() { + String ssid = _wifissidprefix + "_" + String(WIFI_getChipId(),HEX); return startConfigPortal(ssid.c_str(), NULL); } @@ -561,30 +477,25 @@ boolean WiFiManager::startConfigPortal() * @param {[type]} char const *apPassword [description] * @return {[type]} [description] */ -boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) -{ +boolean WiFiManager::startConfigPortal(char const *apName, char const *apPassword) { _begin(); //setup AP - _apName = apName; // @todo check valid apname ? + _apName = apName; // @todo check valid apname ? _apPassword = apPassword; - - if (_apName == "") - _apName = _wifissidprefix + "_" + String(WIFI_getChipId(), HEX); - if (!validApPassword()) - return false; - + + if(_apName == "") _apName = _wifissidprefix + "_" + String(WIFI_getChipId(),HEX); + if(!validApPassword()) return false; + // HANDLE issues with STA connections, shutdown sta if not connected, or else this will hang channel scanning and softap will not respond // @todo sometimes still cannot connect to AP for no known reason, no events in log either - if (_disableSTA || (!WiFi.isConnected() && _disableSTAConn)) - { - // this fixes most ap problems, however, simply doing mode(WIFI_AP) does not work if sta connection is hanging, must `wifi_station_disconnect` + if(_disableSTA || (!WiFi.isConnected() && _disableSTAConn)){ + // this fixes most ap problems, however, simply doing mode(WIFI_AP) does not work if sta connection is hanging, must `wifi_station_disconnect` WiFi_Disconnect(); WiFi_enableSTA(false); - DEBUG_WM(DEBUG_VERBOSE, F("Disabling STA")); + DEBUG_WM(DEBUG_VERBOSE,F("Disabling STA")); } - else - { + else { // @todo even if sta is connected, it is possible that softap connections will fail, IOS says "invalid password", windows says "cannot connect to this network" researching WiFi_enableSTA(true); } @@ -597,29 +508,26 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswor _configPortalStart = millis(); // start access point - DEBUG_WM(DEBUG_VERBOSE, F("Enabling AP")); + DEBUG_WM(DEBUG_VERBOSE,F("Enabling AP")); startAP(); WiFiSetCountry(); // init configportal - DEBUG_WM(DEBUG_DEV, F("setupConfigPortal")); + DEBUG_WM(DEBUG_DEV,F("setupConfigPortal")); setupConfigPortal(); - if (!_configPortalIsBlocking) - { - DEBUG_WM(DEBUG_VERBOSE, F("Config Portal Running, non blocking/processing")); + if(!_configPortalIsBlocking){ + DEBUG_WM(DEBUG_VERBOSE,F("Config Portal Running, non blocking/processing")); return result; } - DEBUG_WM(DEBUG_VERBOSE, F("Config Portal Running, blocking, waiting for clients...")); + DEBUG_WM(DEBUG_VERBOSE,F("Config Portal Running, blocking, waiting for clients...")); // blocking loop waiting for config - while (1) - { + while(1){ // if timed out or abort, break - if (configPortalHasTimeout() || abort) - { - DEBUG_WM(DEBUG_DEV, F("configportal abort")); + if(configPortalHasTimeout() || abort){ + DEBUG_WM(DEBUG_DEV,F("configportal abort")); stopConfigPortal(); result = abort ? portalAbortResult : portalTimeoutResult; // false, false break; @@ -628,16 +536,15 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswor state = processConfigPortal(); // status change, break - if (state != WL_IDLE_STATUS) - { - result = (state == WL_CONNECTED); // true if connected - break; + if(state != WL_IDLE_STATUS){ + result = (state == WL_CONNECTED); // true if connected + break; } yield(); // watchdog } - DEBUG_WM(DEBUG_NOTIFY, F("config portal exiting")); + DEBUG_WM(DEBUG_NOTIFY,F("config portal exiting")); return result; } @@ -646,82 +553,70 @@ boolean WiFiManager::startConfigPortal(char const *apName, char const *apPasswor * @access public * @return {[type]} [description] */ -boolean WiFiManager::process() -{ - if (webPortalActive || (configPortalActive && !_configPortalIsBlocking)) - { - uint8_t state = processConfigPortal(); - return state == WL_CONNECTED; - } - return false; +boolean WiFiManager::process(){ + if(webPortalActive || (configPortalActive && !_configPortalIsBlocking)){ + uint8_t state = processConfigPortal(); + return state == WL_CONNECTED; + } + return false; } //using esp enums returns for now, should be fine -uint8_t WiFiManager::processConfigPortal() -{ - //DNS handler - dnsServer->processNextRequest(); - //HTTP handler - server->handleClient(); +uint8_t WiFiManager::processConfigPortal(){ + //DNS handler + dnsServer->processNextRequest(); + //HTTP handler + server->handleClient(); - // Waiting for save... - if (connect) - { - connect = false; - DEBUG_WM(DEBUG_VERBOSE, F("process connect")); - if (_enableCaptivePortal) - delay(_cpclosedelay); // keeps the captiveportal from closing to fast. + // Waiting for save... + if(connect) { + connect = false; + DEBUG_WM(DEBUG_VERBOSE,F("process connect")); + if(_enableCaptivePortal) delay(_cpclosedelay); // keeps the captiveportal from closing to fast. - // skip wifi if no ssid - if (_ssid == "") - { - DEBUG_WM(DEBUG_VERBOSE, F("No ssid, skipping wifi")); - } - else - { - // attempt sta connection to submitted _ssid, _pass - if (connectWifi(_ssid, _pass) == WL_CONNECTED) - { + // skip wifi if no ssid + if(_ssid == ""){ + DEBUG_WM(DEBUG_VERBOSE,F("No ssid, skipping wifi")); + } + else{ + // attempt sta connection to submitted _ssid, _pass + if (connectWifi(_ssid, _pass) == WL_CONNECTED) { + + DEBUG_WM(F("Connect to new AP [SUCCESS]")); + DEBUG_WM(F("Got IP Address:")); + DEBUG_WM(WiFi.localIP()); - DEBUG_WM(F("Connect to new AP [SUCCESS]")); - DEBUG_WM(F("Got IP Address:")); - DEBUG_WM(WiFi.localIP()); - - if (_savecallback != NULL) - { + if ( _savecallback != NULL) { + _savecallback(); + } + stopConfigPortal(); + return WL_CONNECTED; // CONNECT SUCCESS + } + DEBUG_WM(DEBUG_ERROR,F("[ERROR] Connect to new AP Failed")); + } + + if (_shouldBreakAfterConfig) { + // do save callback + // @todo this is more of an exiting callback than a save, clarify when this should actually occur + // confirm or verify data was saved to make this more accurate callback + if ( _savecallback != NULL) { _savecallback(); } stopConfigPortal(); - return WL_CONNECTED; // CONNECT SUCCESS + return WL_CONNECT_FAILED; // CONNECT FAIL + } + else{ + // clear save strings + _ssid = ""; + _pass = ""; + // if connect fails, turn sta off to stabilize AP + WiFi_Disconnect(); + WiFi_enableSTA(false); + DEBUG_WM(DEBUG_VERBOSE,F("Disabling STA")); } - DEBUG_WM(DEBUG_ERROR, F("[ERROR] Connect to new AP Failed")); } - if (_shouldBreakAfterConfig) - { - // do save callback - // @todo this is more of an exiting callback than a save, clarify when this should actually occur - // confirm or verify data was saved to make this more accurate callback - if (_savecallback != NULL) - { - _savecallback(); - } - stopConfigPortal(); - return WL_CONNECT_FAILED; // CONNECT FAIL - } - else - { - // clear save strings - _ssid = ""; - _pass = ""; - // if connect fails, turn sta off to stabilize AP - WiFi_Disconnect(); - WiFi_enableSTA(false); - DEBUG_WM(DEBUG_VERBOSE, F("Disabling STA")); - } - } - - return WL_IDLE_STATUS; + return WL_IDLE_STATUS; } /** @@ -729,10 +624,8 @@ uint8_t WiFiManager::processConfigPortal() * @access public * @return {[type]} [description] */ -boolean WiFiManager::stopConfigPortal() -{ - if (webPortalActive) - return false; +boolean WiFiManager::stopConfigPortal(){ + if(webPortalActive) return false; //DNS handler dnsServer->processNextRequest(); @@ -747,29 +640,26 @@ boolean WiFiManager::stopConfigPortal() WiFi.scanDelete(); // free wifi scan results - if (!configPortalActive) - return false; + if(!configPortalActive) return false; // turn off AP // @todo bug workaround // https://github.com/esp8266/Arduino/issues/3793 // [APdisconnect] set_config failed! *WM: disconnect configportal - softAPdisconnect failed // still no way to reproduce reliably - DEBUG_WM(DEBUG_VERBOSE, F("disconnect configportal")); + DEBUG_WM(DEBUG_VERBOSE,F("disconnect configportal")); bool ret = false; ret = WiFi.softAPdisconnect(false); - if (!ret) - DEBUG_WM(DEBUG_ERROR, F("[ERROR] disconnect configportal - softAPdisconnect FAILED")); + if(!ret)DEBUG_WM(DEBUG_ERROR,F("[ERROR] disconnect configportal - softAPdisconnect FAILED")); delay(1000); - DEBUG_WM(DEBUG_VERBOSE, "restoring usermode", getModeString(_usermode)); + DEBUG_WM(DEBUG_VERBOSE,"restoring usermode",getModeString(_usermode)); WiFi_Mode(_usermode); // restore users wifi mode, BUG https://github.com/esp8266/Arduino/issues/4372 - if (WiFi.status() == WL_IDLE_STATUS) - { + if(WiFi.status()==WL_IDLE_STATUS){ WiFi.reconnect(); // restart wifi since we disconnected it in startconfigportal - DEBUG_WM(DEBUG_VERBOSE, "WiFi Reconnect, was idle"); + DEBUG_WM(DEBUG_VERBOSE,"WiFi Reconnect, was idle"); } - DEBUG_WM(DEBUG_VERBOSE, "wifi status:", getWLStatusString(WiFi.status())); - DEBUG_WM(DEBUG_VERBOSE, "wifi mode:", getModeString(WiFi.getMode())); + DEBUG_WM(DEBUG_VERBOSE,"wifi status:",getWLStatusString(WiFi.status())); + DEBUG_WM(DEBUG_VERBOSE,"wifi mode:",getModeString(WiFi.getMode())); configPortalActive = false; _end(); return ret; @@ -778,63 +668,53 @@ boolean WiFiManager::stopConfigPortal() // @todo refactor this up into seperate functions // one for connecting to flash , one for new client // clean up, flow is convoluted, and causes bugs -uint8_t WiFiManager::connectWifi(String ssid, String pass) -{ - DEBUG_WM(DEBUG_VERBOSE, F("Connecting as wifi client...")); - +uint8_t WiFiManager::connectWifi(String ssid, String pass) { + DEBUG_WM(DEBUG_VERBOSE,F("Connecting as wifi client...")); + uint8_t connRes = (uint8_t)WL_NO_SSID_AVAIL; setSTAConfig(); //@todo catch failures in set_config - + // make sure sta is on before `begin` so it does not call enablesta->mode while persistent is ON ( which would save WM AP state to eeprom !) - if (_cleanConnect) - WiFi_Disconnect(); // disconnect before begin, in case anything is hung, this causes a 2 seconds delay for connect + if(_cleanConnect) WiFi_Disconnect(); // disconnect before begin, in case anything is hung, this causes a 2 seconds delay for connect // @todo find out what status is when this is needed, can we detect it and handle it, say in between states or idle_status // if ssid argument provided connect to that - if (ssid != "") - { - wifiConnectNew(ssid, pass); - if (_saveTimeout > 0) - { + if (ssid != "") { + wifiConnectNew(ssid,pass); + if(_saveTimeout > 0){ connRes = waitForConnectResult(_saveTimeout); // use default save timeout for saves to prevent bugs in esp->waitforconnectresult loop - } - else - { - connRes = waitForConnectResult(0); + } + else { + connRes = waitForConnectResult(0); } } - else - { + else { // connect using saved ssid if there is one - if (WiFi_hasAutoConnect()) - { + if (WiFi_hasAutoConnect()) { wifiConnectDefault(); connRes = waitForConnectResult(); } - else - { + else { DEBUG_WM(F("No saved credentials, skipping wifi")); } } - DEBUG_WM(DEBUG_VERBOSE, F("Connection result:"), getWLStatusString(connRes)); + DEBUG_WM(DEBUG_VERBOSE,F("Connection result:"),getWLStatusString(connRes)); // WPS enabled? https://github.com/esp8266/Arduino/pull/4889 #ifdef NO_EXTRA_4K_HEAP // do WPS, if WPS options enabled and not connected and no password was supplied // @todo this seems like wrong place for this, is it a fallback or option? - if (_tryWPS && connRes != WL_CONNECTED && pass == "") - { + if (_tryWPS && connRes != WL_CONNECTED && pass == "") { startWPS(); // should be connected at the end of WPS connRes = waitForConnectResult(); } #endif - if (connRes != WL_SCAN_COMPLETED) - { + if(connRes != WL_SCAN_COMPLETED){ updateConxResult(connRes); } @@ -848,16 +728,14 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) * @param String pass * @return bool success */ -bool WiFiManager::wifiConnectNew(String ssid, String pass) -{ +bool WiFiManager::wifiConnectNew(String ssid, String pass){ bool ret = false; - DEBUG_WM(F("Connecting to new AP:"), ssid); - WiFi_enableSTA(true, storeSTAmode); // storeSTAmode will also toggle STA on in default opmode (persistent) if true (default) + DEBUG_WM(F("Connecting to new AP:"),ssid); + 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()); WiFi.persistent(false); - if (!ret) - DEBUG_WM(DEBUG_ERROR, "[ERROR] wifi begin failed"); + if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi begin failed"); return ret; } @@ -866,84 +744,68 @@ bool WiFiManager::wifiConnectNew(String ssid, String pass) * @since dev * @return bool success */ -bool WiFiManager::wifiConnectDefault() -{ +bool WiFiManager::wifiConnectDefault(){ bool ret = false; - DEBUG_WM(F("Connecting to saved AP:"), WiFi_SSID()); - ret = WiFi_enableSTA(true, storeSTAmode); - if (!ret) - DEBUG_WM(DEBUG_ERROR, "[ERROR] wifi enableSta failed"); + DEBUG_WM(F("Connecting to saved AP:"),WiFi_SSID()); + ret = WiFi_enableSTA(true,storeSTAmode); + if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi enableSta failed"); ret = WiFi.begin(); - if (!ret) - DEBUG_WM(DEBUG_ERROR, "[ERROR] wifi begin failed"); + if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi begin failed"); return ret; } + /** * set sta config if set * @since $dev * @return bool success */ -bool WiFiManager::setSTAConfig() -{ +bool WiFiManager::setSTAConfig(){ bool ret = true; - if (_sta_static_ip) - { - if (_sta_static_dns) - { - DEBUG_WM(DEBUG_VERBOSE, F("Custom STA IP/GW/Subnet/DNS")); + if (_sta_static_ip) { + if(_sta_static_dns) { + DEBUG_WM(DEBUG_VERBOSE,F("Custom STA IP/GW/Subnet/DNS")); ret = WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn, _sta_static_dns); } - else - { - DEBUG_WM(DEBUG_VERBOSE, F("Custom STA IP/GW/Subnet")); + else { + DEBUG_WM(DEBUG_VERBOSE,F("Custom STA IP/GW/Subnet")); ret = WiFi.config(_sta_static_ip, _sta_static_gw, _sta_static_sn); } - if (!ret) - DEBUG_WM(DEBUG_ERROR, "[ERROR] wifi config failed"); - else - DEBUG_WM(F("STA IP set:"), WiFi.localIP()); - } - else - { - DEBUG_WM(DEBUG_VERBOSE, F("setSTAConfig static ip not set")); + if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi config failed"); + else DEBUG_WM(F("STA IP set:"),WiFi.localIP()); + } else { + DEBUG_WM(DEBUG_VERBOSE,F("setSTAConfig static ip not set")); } return ret; } // @todo change to getLastFailureReason and do not touch conxresult -void WiFiManager::updateConxResult(uint8_t status) -{ +void WiFiManager::updateConxResult(uint8_t status){ // hack in wrong password detection _lastconxresult = status; -#ifdef ESP8266 - if (_lastconxresult == WL_CONNECT_FAILED) - { - if (wifi_station_get_connect_status() == STATION_WRONG_PASSWORD) - { - _lastconxresult = WL_STATION_WRONG_PASSWORD; - } - } -#elif defined(ESP32) - // if(_lastconxresult == WL_CONNECT_FAILED){ - if (_lastconxresult == WL_CONNECT_FAILED || _lastconxresult == WL_DISCONNECTED) - { - DEBUG_WM(DEBUG_DEV, "lastconxresulttmp:", getWLStatusString(_lastconxresulttmp)); - if (_lastconxresulttmp != WL_IDLE_STATUS) - { - _lastconxresult = _lastconxresulttmp; - // _lastconxresulttmp = WL_IDLE_STATUS; - } - } -#endif - DEBUG_WM(DEBUG_DEV, "lastconxresult:", getWLStatusString(_lastconxresult)); + #ifdef ESP8266 + if(_lastconxresult == WL_CONNECT_FAILED){ + if(wifi_station_get_connect_status() == STATION_WRONG_PASSWORD){ + _lastconxresult = WL_STATION_WRONG_PASSWORD; + } + } + #elif defined(ESP32) + // if(_lastconxresult == WL_CONNECT_FAILED){ + if(_lastconxresult == WL_CONNECT_FAILED || _lastconxresult == WL_DISCONNECTED){ + DEBUG_WM(DEBUG_DEV,"lastconxresulttmp:",getWLStatusString(_lastconxresulttmp)); + if(_lastconxresulttmp != WL_IDLE_STATUS){ + _lastconxresult = _lastconxresulttmp; + // _lastconxresulttmp = WL_IDLE_STATUS; + } + } + #endif + DEBUG_WM(DEBUG_DEV,"lastconxresult:",getWLStatusString(_lastconxresult)); } -uint8_t WiFiManager::waitForConnectResult() -{ - if (_connectTimeout > 0) - DEBUG_WM(DEBUG_VERBOSE, _connectTimeout, F("ms connectTimeout set")); + +uint8_t WiFiManager::waitForConnectResult() { + if(_connectTimeout > 0) DEBUG_WM(DEBUG_VERBOSE,_connectTimeout,F("ms connectTimeout set")); return waitForConnectResult(_connectTimeout); } @@ -952,27 +814,23 @@ uint8_t WiFiManager::waitForConnectResult() * @param uint16_t timeout in seconds * @return uint8_t WL Status */ -uint8_t WiFiManager::waitForConnectResult(uint16_t timeout) -{ - if (timeout == 0) - { +uint8_t WiFiManager::waitForConnectResult(uint16_t timeout) { + if (timeout == 0){ DEBUG_WM(F("connectTimeout not set, ESP waitForConnectResult...")); return WiFi.waitForConnectResult(); } unsigned long timeoutmillis = millis() + timeout; - DEBUG_WM(DEBUG_VERBOSE, timeout, F("ms timeout, waiting for connect...")); + DEBUG_WM(DEBUG_VERBOSE,timeout,F("ms timeout, waiting for connect...")); uint8_t status = WiFi.status(); - - while (millis() < timeoutmillis) - { + + while(millis() < timeoutmillis) { status = WiFi.status(); // @todo detect additional states, connect happens, then dhcp then get ip, there is some delay here, make sure not to timeout if waiting on IP - if (status == WL_CONNECTED || status == WL_CONNECT_FAILED) - { + if (status == WL_CONNECTED || status == WL_CONNECT_FAILED) { return status; } - DEBUG_WM(DEBUG_VERBOSE, F(".")); + DEBUG_WM (DEBUG_VERBOSE,F(".")); delay(100); } return status; @@ -980,20 +838,18 @@ uint8_t WiFiManager::waitForConnectResult(uint16_t timeout) // WPS enabled? https://github.com/esp8266/Arduino/pull/4889 #ifdef NO_EXTRA_4K_HEAP -void WiFiManager::startWPS() -{ +void WiFiManager::startWPS() { DEBUG_WM(F("START WPS")); -#ifdef ESP8266 - WiFi.beginWPSConfig(); -#else - // @todo -#endif + #ifdef ESP8266 + WiFi.beginWPSConfig(); + #else + // @todo + #endif DEBUG_WM(F("END WPS")); } #endif -String WiFiManager::getHTTPHead(String title) -{ +String WiFiManager::getHTTPHead(String title){ String page; page += FPSTR(HTTP_HEAD_START); page.replace(FPSTR(T_v), title); @@ -1001,16 +857,14 @@ String WiFiManager::getHTTPHead(String title) page += FPSTR(HTTP_STYLE); page += _customHeadElement; - if (_bodyClass != "") - { + if(_bodyClass != ""){ String p = FPSTR(HTTP_HEAD_END); p.replace(FPSTR(T_c), _bodyClass); // add class str page += p; } - else - { + else { page += FPSTR(HTTP_HEAD_END); - } + } return page; } @@ -1018,23 +872,20 @@ String WiFiManager::getHTTPHead(String title) /** * HTTPD handler for page requests */ -void WiFiManager::handleRequest() -{ +void WiFiManager::handleRequest() { _webPortalAccessed = millis(); } /** * HTTPD CALLBACK root or redirect to captive portal */ -void WiFiManager::handleRoot() -{ - DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP Root")); - if (captivePortal()) - return; // If captive portal redirect instead of displaying the page +void WiFiManager::handleRoot() { + DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Root")); + if (captivePortal()) return; // If captive portal redirect instead of displaying the page handleRequest(); String page = getHTTPHead(FPSTR(S_options)); // @token options - String str = FPSTR(HTTP_ROOT_MAIN); - str.replace(FPSTR(T_v), configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading + String str = FPSTR(HTTP_ROOT_MAIN); + str.replace(FPSTR(T_v),configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading page += str; page += FPSTR(HTTP_PORTAL_OPTIONS); page += getMenuOut(); @@ -1043,9 +894,8 @@ void WiFiManager::handleRoot() server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); - // server->close(); // testing reliability fix for content length mismatches during mutiple flood hits WiFi_scanNetworks(); // preload wifiscan - if (_preloadwifiscan) - WiFi_scanNetworks((unsigned)20000, true); // preload wifiscan throttled, async + // server->close(); // testing reliability fix for content length mismatches during mutiple flood hits WiFi_scanNetworks(); // preload wifiscan + if(_preloadwifiscan) WiFi_scanNetworks((unsigned)20000,true); // preload wifiscan throttled, async // @todo buggy, captive portals make a query on every page load, causing this to run every time in addition to the real page load // I dont understand why, when you are already in the captive portal, I guess they want to know that its still up and not done or gone // if we can detect these and ignore them that would be great, since they come from the captive portal redirect maybe there is a refferer @@ -1054,15 +904,13 @@ void WiFiManager::handleRoot() /** * HTTPD CALLBACK Wifi config page handler */ -void WiFiManager::handleWifi(boolean scan) -{ - DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP Wifi")); +void WiFiManager::handleWifi(boolean scan) { + DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Wifi")); handleRequest(); String page = getHTTPHead(FPSTR(S_titlewifi)); // @token titlewifi - if (scan) - { + if (scan) { // DEBUG_WM(DEBUG_DEV,"refresh flag:",server->hasArg(F("refresh"))); - WiFi_scanNetworks(server->hasArg(F("refresh")), false); //wifiscan, force if arg refresh + WiFi_scanNetworks(server->hasArg(F("refresh")),false); //wifiscan, force if arg refresh page += getScanItemOut(); } String pitem = ""; @@ -1077,8 +925,7 @@ void WiFiManager::handleWifi(boolean scan) page += getStaticOut(); page += FPSTR(HTTP_FORM_WIFI_END); - if (_paramsInWifi && _paramsCount > 0) - { + if(_paramsInWifi && _paramsCount>0){ page += FPSTR(HTTP_FORM_PARAM_HEAD); page += getParamOut(); } @@ -1091,15 +938,14 @@ void WiFiManager::handleWifi(boolean scan) server->send(200, FPSTR(HTTP_HEAD_CT), page); // server->close(); // testing reliability fix for content length mismatches during mutiple flood hits - DEBUG_WM(DEBUG_DEV, F("Sent config page")); + DEBUG_WM(DEBUG_DEV,F("Sent config page")); } /** * HTTPD CALLBACK Wifi param page handler */ -void WiFiManager::handleParam() -{ - DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP Param")); +void WiFiManager::handleParam(){ + DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Param")); handleRequest(); String page = getHTTPHead(FPSTR(S_titleparam)); // @token titlewifi @@ -1117,17 +963,15 @@ void WiFiManager::handleParam() server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); - DEBUG_WM(DEBUG_DEV, F("Sent param page")); + DEBUG_WM(DEBUG_DEV,F("Sent param page")); } -String WiFiManager::getMenuOut() -{ - String page; - for (auto menuId : _menuIds) - { - if (((String)menuId == "param") && (_paramsCount == 0)) - continue; // no params set, omit params +String WiFiManager::getMenuOut(){ + String page; + + for(auto menuId :_menuIds ){ + if(((String)menuId == "param") && (_paramsCount == 0)) continue; // no params set, omit params page += HTTP_PORTAL_MENU[menuId]; } @@ -1139,253 +983,207 @@ String WiFiManager::getMenuOut() // WiFi_scanNetworks(force); // } -void WiFiManager::WiFi_scanComplete(int networksFound) -{ +void WiFiManager::WiFi_scanComplete(int networksFound){ _lastscan = millis(); _numNetworks = networksFound; - 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(DEBUG_VERBOSE,F("WiFi Scan ASYNC completed"), "in "+(String)(_lastscan - _startscan)+" ms"); + DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC found:"),_numNetworks); } -bool WiFiManager::WiFi_scanNetworks() -{ - return WiFi_scanNetworks(false, false); +bool WiFiManager::WiFi_scanNetworks(){ + return WiFi_scanNetworks(false,false); } -bool WiFiManager::WiFi_scanNetworks(unsigned int cachetime, bool async) -{ - return WiFi_scanNetworks(millis() - _lastscan > cachetime, async); +bool WiFiManager::WiFi_scanNetworks(unsigned int cachetime,bool async){ + return WiFi_scanNetworks(millis()-_lastscan > cachetime,async); } -bool WiFiManager::WiFi_scanNetworks(unsigned int cachetime) -{ - return WiFi_scanNetworks(millis() - _lastscan > cachetime, false); +bool WiFiManager::WiFi_scanNetworks(unsigned int cachetime){ + return WiFi_scanNetworks(millis()-_lastscan > cachetime,false); } -bool WiFiManager::WiFi_scanNetworks(bool force, bool async) -{ - // DEBUG_WM(DEBUG_DEV,"scanNetworks async:",async == true); - // DEBUG_WM(DEBUG_DEV,_numNetworks,(millis()-_lastscan )); - // DEBUG_WM(DEBUG_DEV,"scanNetworks force:",force == true); - if (force || _numNetworks == 0 || (millis() - _lastscan > 60000)) - { - int8_t res; - _startscan = millis(); - if (async) - { - DEBUG_WM(DEBUG_VERBOSE, F("WiFi Scan ASYNC started")); -#ifdef ESP8266 -#ifndef WM_NOASYNC // no async available < 2.4.0 - using namespace std::placeholders; // for `_1` - WiFi.scanNetworksAsync(std::bind(&WiFiManager::WiFi_scanComplete, this, _1)); -#else - res = WiFi.scanNetworks(); -#endif -#else - res = WiFi.scanNetworks(true); -#endif - return false; - } - else - { - res = WiFi.scanNetworks(); - } - if (res == WIFI_SCAN_FAILED) - DEBUG_WM(DEBUG_ERROR, "[ERROR] scan failed"); - else if (res == WIFI_SCAN_RUNNING) - { - DEBUG_WM(DEBUG_ERROR, "[ERROR] scan waiting"); - while (WiFi.scanComplete() == WIFI_SCAN_RUNNING) - { - DEBUG_WM(DEBUG_ERROR, "."); - delay(100); +bool WiFiManager::WiFi_scanNetworks(bool force,bool async){ + // DEBUG_WM(DEBUG_DEV,"scanNetworks async:",async == true); + // DEBUG_WM(DEBUG_DEV,_numNetworks,(millis()-_lastscan )); + // DEBUG_WM(DEBUG_DEV,"scanNetworks force:",force == true); + if(force || _numNetworks == 0 || (millis()-_lastscan > 60000)){ + int8_t res; + _startscan = millis(); + if(async){ + DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan ASYNC started")); + #ifdef ESP8266 + #ifndef WM_NOASYNC // no async available < 2.4.0 + using namespace std::placeholders; // for `_1` + WiFi.scanNetworksAsync(std::bind(&WiFiManager::WiFi_scanComplete,this,_1)); + #else + res = WiFi.scanNetworks(); + #endif + #else + res = WiFi.scanNetworks(true); + #endif + return false; } - _numNetworks = WiFi.scanComplete(); - } - else if (res >= 0) - _numNetworks = res; - _lastscan = millis(); - DEBUG_WM(DEBUG_VERBOSE, F("WiFi Scan completed"), "in " + (String)(_lastscan - _startscan) + " ms"); - return true; - } - else - DEBUG_WM(DEBUG_VERBOSE, "Scan is cached", (String)(millis() - _lastscan) + " ms ago"); - return false; + else{ + res = WiFi.scanNetworks(); + } + if(res == WIFI_SCAN_FAILED) DEBUG_WM(DEBUG_ERROR,"[ERROR] scan failed"); + else if(res == WIFI_SCAN_RUNNING){ + DEBUG_WM(DEBUG_ERROR,"[ERROR] scan waiting"); + while(WiFi.scanComplete() == WIFI_SCAN_RUNNING){ + DEBUG_WM(DEBUG_ERROR,"."); + delay(100); + } + _numNetworks = WiFi.scanComplete(); + } + else if(res >=0 ) _numNetworks = res; + _lastscan = millis(); + DEBUG_WM(DEBUG_VERBOSE,F("WiFi Scan completed"), "in "+(String)(_lastscan - _startscan)+" ms"); + return true; + } else DEBUG_WM(DEBUG_VERBOSE,"Scan is cached",(String)(millis()-_lastscan )+" ms ago"); + return false; } -String WiFiManager::WiFiManager::getScanItemOut() -{ - String page; +String WiFiManager::WiFiManager::getScanItemOut(){ + String page; - if (!_numNetworks) - WiFi_scanNetworks(); // scan in case this gets called before any scans + if(!_numNetworks) WiFi_scanNetworks(); // scan in case this gets called before any scans - int n = _numNetworks; - if (n == 0) - { - DEBUG_WM(F("No networks found")); - page += FPSTR(S_nonetworks); // @token nonetworks - } - else - { - DEBUG_WM(n, F("networks found")); - //sort networks - int indices[n]; - for (int i = 0; i < n; i++) - { - indices[i] = i; - } + int n = _numNetworks; + if (n == 0) { + DEBUG_WM(F("No networks found")); + page += FPSTR(S_nonetworks); // @token nonetworks + } + else { + DEBUG_WM(n,F("networks found")); + //sort networks + int indices[n]; + for (int i = 0; i < n; i++) { + indices[i] = i; + } - // RSSI SORT - for (int i = 0; i < n; i++) - { - for (int j = i + 1; j < n; j++) - { - if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) - { - std::swap(indices[i], indices[j]); + // RSSI SORT + for (int i = 0; i < n; i++) { + for (int j = i + 1; j < n; j++) { + if (WiFi.RSSI(indices[j]) > WiFi.RSSI(indices[i])) { + std::swap(indices[i], indices[j]); + } } } - } - /* test std:sort + /* test std:sort std::sort(indices, indices + n, [](const int & a, const int & b) -> bool { return WiFi.RSSI(a) > WiFi.RSSI(b); }); */ - // remove duplicates ( must be RSSI sorted ) - if (_removeDuplicateAPs) - { - String cssid; - for (int i = 0; i < n; i++) - { - if (indices[i] == -1) - continue; - cssid = WiFi.SSID(indices[i]); - for (int j = i + 1; j < n; j++) - { - if (cssid == WiFi.SSID(indices[j])) - { - DEBUG_WM(DEBUG_VERBOSE, F("DUP AP:"), WiFi.SSID(indices[j])); - indices[j] = -1; // set dup aps to index -1 + // remove duplicates ( must be RSSI sorted ) + if (_removeDuplicateAPs) { + String cssid; + for (int i = 0; i < n; i++) { + if (indices[i] == -1) continue; + cssid = WiFi.SSID(indices[i]); + for (int j = i + 1; j < n; j++) { + if (cssid == WiFi.SSID(indices[j])) { + DEBUG_WM(DEBUG_VERBOSE,F("DUP AP:"),WiFi.SSID(indices[j])); + indices[j] = -1; // set dup aps to index -1 + } } } } - } - // token precheck, to speed up replacements on large ap lists - String HTTP_ITEM_STR = FPSTR(HTTP_ITEM); + // token precheck, to speed up replacements on large ap lists + String HTTP_ITEM_STR = FPSTR(HTTP_ITEM); - // toggle icons with percentage - HTTP_ITEM_STR.replace("{qp}", FPSTR(HTTP_ITEM_QP)); - HTTP_ITEM_STR.replace("{h}", _scanDispOptions ? "" : "h"); - HTTP_ITEM_STR.replace("{qi}", FPSTR(HTTP_ITEM_QI)); - HTTP_ITEM_STR.replace("{h}", _scanDispOptions ? "h" : ""); + // toggle icons with percentage + HTTP_ITEM_STR.replace("{qp}", FPSTR(HTTP_ITEM_QP)); + HTTP_ITEM_STR.replace("{h}",_scanDispOptions ? "" : "h"); + HTTP_ITEM_STR.replace("{qi}", FPSTR(HTTP_ITEM_QI)); + HTTP_ITEM_STR.replace("{h}",_scanDispOptions ? "h" : ""); + + // set token precheck flags + bool tok_r = HTTP_ITEM_STR.indexOf(FPSTR(T_r)) > 0; + bool tok_R = HTTP_ITEM_STR.indexOf(FPSTR(T_R)) > 0; + bool tok_e = HTTP_ITEM_STR.indexOf(FPSTR(T_e)) > 0; + bool tok_q = HTTP_ITEM_STR.indexOf(FPSTR(T_q)) > 0; + bool tok_i = HTTP_ITEM_STR.indexOf(FPSTR(T_i)) > 0; + + //display networks in page + for (int i = 0; i < n; i++) { + if (indices[i] == -1) continue; // skip dups - // set token precheck flags - bool tok_r = HTTP_ITEM_STR.indexOf(FPSTR(T_r)) > 0; - bool tok_R = HTTP_ITEM_STR.indexOf(FPSTR(T_R)) > 0; - bool tok_e = HTTP_ITEM_STR.indexOf(FPSTR(T_e)) > 0; - bool tok_q = HTTP_ITEM_STR.indexOf(FPSTR(T_q)) > 0; - bool tok_i = HTTP_ITEM_STR.indexOf(FPSTR(T_i)) > 0; + DEBUG_WM(DEBUG_VERBOSE,F("AP: "),(String)WiFi.RSSI(indices[i]) + " " + (String)WiFi.SSID(indices[i])); - //display networks in page - for (int i = 0; i < n; i++) - { - if (indices[i] == -1) - continue; // skip dups + int rssiperc = getRSSIasQuality(WiFi.RSSI(indices[i])); + uint8_t enc_type = WiFi.encryptionType(indices[i]); - DEBUG_WM(DEBUG_VERBOSE, F("AP: "), (String)WiFi.RSSI(indices[i]) + " " + (String)WiFi.SSID(indices[i])); - - int rssiperc = getRSSIasQuality(WiFi.RSSI(indices[i])); - uint8_t enc_type = WiFi.encryptionType(indices[i]); - - if (_minimumQuality == -1 || _minimumQuality < rssiperc) - { - String item = HTTP_ITEM_STR; - item.replace(FPSTR(T_v), htmlEntities(WiFi.SSID(indices[i]))); // ssid no encoding - if (tok_e) - item.replace(FPSTR(T_e), encryptionTypeStr(enc_type)); - if (tok_r) - item.replace(FPSTR(T_r), (String)rssiperc); // rssi percentage 0-100 - if (tok_R) - item.replace(FPSTR(T_R), (String)WiFi.RSSI(indices[i])); // rssi db - if (tok_q) - item.replace(FPSTR(T_q), (String)round(map(rssiperc, 0, 100, 1, 4))); //quality icon 1-4 - if (tok_i) - { - if (enc_type != WM_WIFIOPEN) - { - item.replace(FPSTR(T_i), F("l")); - } - else - { - item.replace(FPSTR(T_i), ""); + if (_minimumQuality == -1 || _minimumQuality < rssiperc) { + String item = HTTP_ITEM_STR; + item.replace(FPSTR(T_v), htmlEntities(WiFi.SSID(indices[i]))); // ssid no encoding + if(tok_e) item.replace(FPSTR(T_e), encryptionTypeStr(enc_type)); + if(tok_r) item.replace(FPSTR(T_r), (String)rssiperc); // rssi percentage 0-100 + if(tok_R) item.replace(FPSTR(T_R), (String)WiFi.RSSI(indices[i])); // rssi db + if(tok_q) item.replace(FPSTR(T_q), (String)round(map(rssiperc,0,100,1,4))); //quality icon 1-4 + if(tok_i){ + if (enc_type != WM_WIFIOPEN) { + item.replace(FPSTR(T_i), F("l")); + } else { + item.replace(FPSTR(T_i), ""); + } } + //DEBUG_WM(item); + page += item; + delay(0); + } else { + DEBUG_WM(DEBUG_VERBOSE,F("Skipping , does not meet _minimumQuality")); } - //DEBUG_WM(item); - page += item; - delay(0); - } - else - { - DEBUG_WM(DEBUG_VERBOSE, F("Skipping , does not meet _minimumQuality")); + } + page += FPSTR(HTTP_BR); } - page += FPSTR(HTTP_BR); - } - return page; + return page; } -String WiFiManager::getIpForm(String id, String title, String value) -{ - String item = FPSTR(HTTP_FORM_LABEL); - item += FPSTR(HTTP_FORM_PARAM); - item.replace(FPSTR(T_i), id); - item.replace(FPSTR(T_n), id); - item.replace(FPSTR(T_p), FPSTR(T_t)); - // item.replace(FPSTR(T_p), default); - item.replace(FPSTR(T_t), title); - item.replace(FPSTR(T_l), F("15")); - item.replace(FPSTR(T_v), value); - item.replace(FPSTR(T_c), ""); - return item; +String WiFiManager::getIpForm(String id, String title, String value){ + String item = FPSTR(HTTP_FORM_LABEL); + item += FPSTR(HTTP_FORM_PARAM); + item.replace(FPSTR(T_i), id); + item.replace(FPSTR(T_n), id); + item.replace(FPSTR(T_p), FPSTR(T_t)); + // item.replace(FPSTR(T_p), default); + item.replace(FPSTR(T_t), title); + item.replace(FPSTR(T_l), F("15")); + item.replace(FPSTR(T_v), value); + item.replace(FPSTR(T_c), ""); + return item; } -String WiFiManager::getStaticOut() -{ +String WiFiManager::getStaticOut(){ String page; - if ((_staShowStaticFields || _sta_static_ip) && _staShowStaticFields >= 0) - { - DEBUG_WM(DEBUG_DEV, "_staShowStaticFields"); + if ((_staShowStaticFields || _sta_static_ip) && _staShowStaticFields>=0) { + DEBUG_WM(DEBUG_DEV,"_staShowStaticFields"); 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 - page += getIpForm(FPSTR(S_ip), FPSTR(S_staticip), (_sta_static_ip ? _sta_static_ip.toString() : "")); // @token staticip + page += getIpForm(FPSTR(S_ip),FPSTR(S_staticip),(_sta_static_ip ? _sta_static_ip.toString() : "")); // @token staticip // WiFi.localIP().toString(); - page += getIpForm(FPSTR(S_gw), FPSTR(S_staticgw), (_sta_static_gw ? _sta_static_gw.toString() : "")); // @token staticgw + page += getIpForm(FPSTR(S_gw),FPSTR(S_staticgw),(_sta_static_gw ? _sta_static_gw.toString() : "")); // @token staticgw // WiFi.gatewayIP().toString(); - page += getIpForm(FPSTR(S_sn), FPSTR(S_subnet), (_sta_static_sn ? _sta_static_sn.toString() : "")); // @token subnet + page += getIpForm(FPSTR(S_sn),FPSTR(S_subnet),(_sta_static_sn ? _sta_static_sn.toString() : "")); // @token subnet // WiFi.subnetMask().toString(); } - if ((_staShowDns || _sta_static_dns) && _staShowDns >= 0) - { - page += getIpForm(FPSTR(S_dns), FPSTR(S_staticdns), (_sta_static_dns ? _sta_static_dns.toString() : "")); // @token dns + if((_staShowDns || _sta_static_dns) && _staShowDns>=0){ + page += getIpForm(FPSTR(S_dns),FPSTR(S_staticdns),(_sta_static_dns ? _sta_static_dns.toString() : "")); // @token dns } - if (page != "") - page += FPSTR(HTTP_BR); // @todo remove these, use css + if(page!="") page += FPSTR(HTTP_BR); // @todo remove these, use css return page; } -String WiFiManager::getParamOut() -{ +String WiFiManager::getParamOut(){ String page; - if (_paramsCount > 0) - { + if(_paramsCount > 0){ String HTTP_PARAM_temp = FPSTR(HTTP_FORM_LABEL); HTTP_PARAM_temp += FPSTR(HTTP_FORM_PARAM); @@ -1400,55 +1198,41 @@ String WiFiManager::getParamOut() char parLength[5]; // add the extra parameters to the form - for (int i = 0; i < _paramsCount; i++) - { - if (_params[i] == NULL || _params[i]->_length == 0) - { - DEBUG_WM(DEBUG_ERROR, "[ERROR] WiFiManagerParameter is out of scope"); + for (int i = 0; i < _paramsCount; i++) { + if (_params[i] == NULL || _params[i]->_length == 0) { + DEBUG_WM(DEBUG_ERROR,"[ERROR] WiFiManagerParameter is out of scope"); break; } - // label before or after, this could probably be done via floats however - String pitem; - switch (_params[i]->getLabelPlacement()) - { - case WFM_LABEL_BEFORE: - pitem = FPSTR(HTTP_FORM_LABEL); - pitem += FPSTR(HTTP_FORM_PARAM); - break; - case WFM_LABEL_AFTER: - pitem = FPSTR(HTTP_FORM_PARAM); - pitem += FPSTR(HTTP_FORM_LABEL); - break; - default: - // WFM_NO_LABEL - pitem = FPSTR(HTTP_FORM_PARAM); - break; + // label before or after, this could probably be done via floats however + String pitem; + switch (_params[i]->getLabelPlacement()) { + case WFM_LABEL_BEFORE: + pitem = FPSTR(HTTP_FORM_LABEL); + pitem += FPSTR(HTTP_FORM_PARAM); + break; + case WFM_LABEL_AFTER: + pitem = FPSTR(HTTP_FORM_PARAM); + pitem += FPSTR(HTTP_FORM_LABEL); + break; + default: + // WFM_NO_LABEL + pitem = FPSTR(HTTP_FORM_PARAM); + break; } // if no ID use customhtml for item, else generate from param string - if (_params[i]->getID() != NULL) - { - if (tok_I) - pitem.replace(FPSTR(T_I), (String)FPSTR(S_parampre) + (String)i); - if (tok_i) - pitem.replace(FPSTR(T_i), _params[i]->getID()); - if (tok_n) - pitem.replace(FPSTR(T_n), _params[i]->getID()); - if (tok_p) - pitem.replace(FPSTR(T_p), FPSTR(T_t)); - if (tok_t) - pitem.replace(FPSTR(T_t), _params[i]->getPlaceholder()); + if (_params[i]->getID() != NULL) { + if(tok_I)pitem.replace(FPSTR(T_I), (String)FPSTR(S_parampre)+(String)i); + if(tok_i)pitem.replace(FPSTR(T_i), _params[i]->getID()); + if(tok_n)pitem.replace(FPSTR(T_n), _params[i]->getID()); + if(tok_p)pitem.replace(FPSTR(T_p), FPSTR(T_t)); + if(tok_t)pitem.replace(FPSTR(T_t), _params[i]->getPlaceholder()); snprintf(parLength, 5, "%d", _params[i]->getValueLength()); - if (tok_l) - pitem.replace(FPSTR(T_l), parLength); - if (tok_v) - pitem.replace(FPSTR(T_v), _params[i]->getValue()); - if (tok_c) - pitem.replace(FPSTR(T_c), _params[i]->getCustomHTML()); // meant for additional attributes, not html - } - else - { + if(tok_l)pitem.replace(FPSTR(T_l), parLength); + if(tok_v)pitem.replace(FPSTR(T_v), _params[i]->getValue()); + if(tok_c)pitem.replace(FPSTR(T_c), _params[i]->getCustomHTML()); // meant for additional attributes, not html + } else { pitem = _params[i]->getCustomHTML(); } @@ -1459,15 +1243,14 @@ String WiFiManager::getParamOut() return page; } -void WiFiManager::handleWiFiStatus() -{ - DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP WiFi status ")); +void WiFiManager::handleWiFiStatus(){ + DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP WiFi status ")); handleRequest(); String page; -// String page = "{\"result\":true,\"count\":1}"; -#ifdef JSTEST - page = FPSTR(HTTP_JS); -#endif + // String page = "{\"result\":true,\"count\":1}"; + #ifdef JSTEST + page = FPSTR(HTTP_JS); + #endif server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); } @@ -1475,15 +1258,13 @@ void WiFiManager::handleWiFiStatus() /** * HTTPD CALLBACK save form and redirect to WLAN config page again */ -void WiFiManager::handleWifiSave() -{ - 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)); +void WiFiManager::handleWifiSave() { + 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)); handleRequest(); - // @todo use new callback for pre saves - if (_presavecallback != NULL) - { + // @todo use new callback for before paramsaves + if ( _presavecallback != NULL) { _presavecallback(); } @@ -1491,33 +1272,28 @@ void WiFiManager::handleWifiSave() _ssid = server->arg(F("s")).c_str(); _pass = server->arg(F("p")).c_str(); - if (_paramsInWifi) - doParamSave(); + if(_paramsInWifi) doParamSave(); - if (server->arg(FPSTR(S_ip)) != "") - { + if (server->arg(FPSTR(S_ip)) != "") { //_sta_static_ip.fromString(server->arg(FPSTR(S_ip)); String ip = server->arg(FPSTR(S_ip)); optionalIPFromString(&_sta_static_ip, ip.c_str()); - DEBUG_WM(DEBUG_DEV, F("static ip:"), ip); + DEBUG_WM(DEBUG_DEV,F("static ip:"),ip); } - if (server->arg(FPSTR(S_gw)) != "") - { + if (server->arg(FPSTR(S_gw)) != "") { String gw = server->arg(FPSTR(S_gw)); optionalIPFromString(&_sta_static_gw, gw.c_str()); - DEBUG_WM(DEBUG_DEV, F("static gateway:"), gw); + DEBUG_WM(DEBUG_DEV,F("static gateway:"),gw); } - if (server->arg(FPSTR(S_sn)) != "") - { + if (server->arg(FPSTR(S_sn)) != "") { String sn = server->arg(FPSTR(S_sn)); optionalIPFromString(&_sta_static_sn, sn.c_str()); - DEBUG_WM(DEBUG_DEV, F("static netmask:"), sn); + DEBUG_WM(DEBUG_DEV,F("static netmask:"),sn); } - if (server->arg(FPSTR(S_dns)) != "") - { + if (server->arg(FPSTR(S_dns)) != "") { String dns = server->arg(FPSTR(S_dns)); optionalIPFromString(&_sta_static_dns, dns.c_str()); - DEBUG_WM(DEBUG_DEV, F("static DNS:"), dns); + DEBUG_WM(DEBUG_DEV,F("static DNS:"),dns); } String page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved @@ -1528,28 +1304,26 @@ void WiFiManager::handleWifiSave() server->sendHeader(FPSTR(HTTP_HEAD_CORS), FPSTR(HTTP_HEAD_CORS_ALLOW_ALL)); server->send(200, FPSTR(HTTP_HEAD_CT), page); - DEBUG_WM(DEBUG_DEV, F("Sent wifi save page")); + DEBUG_WM(DEBUG_DEV,F("Sent wifi save page")); connect = true; //signal ready to connect/reset process in processConfigPortal } -void WiFiManager::handleParamSave() -{ - 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)); +void WiFiManager::handleParamSave() { + + 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)); handleRequest(); - // @todo use new callback for pre saves - if (_presavecallback != NULL) - { + // @todo use new callback for before paramsaves + if ( _presavecallback != NULL) { _presavecallback(); } doParamSave(); // @todo use new callback for paramsaves - if (_savecallback != NULL) - { + if ( _savecallback != NULL) { _savecallback(); } @@ -1560,58 +1334,50 @@ void WiFiManager::handleParamSave() server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); - DEBUG_WM(DEBUG_DEV, F("Sent param save page")); + DEBUG_WM(DEBUG_DEV,F("Sent param save page")); } -void WiFiManager::doParamSave() -{ +void WiFiManager::doParamSave(){ //parameters - if (_paramsCount > 0) - { - DEBUG_WM(DEBUG_VERBOSE, F("Parameters")); - DEBUG_WM(DEBUG_VERBOSE, FPSTR(D_HR)); - for (int i = 0; i < _paramsCount; i++) - { - if (_params[i] == NULL) - { + if(_paramsCount > 0){ + DEBUG_WM(DEBUG_VERBOSE,F("Parameters")); + DEBUG_WM(DEBUG_VERBOSE,FPSTR(D_HR)); + for (int i = 0; i < _paramsCount; i++) { + if (_params[i] == NULL) { break; } //read parameter from server - String name = (String)FPSTR(S_parampre) + (String)i; + String name = (String)FPSTR(S_parampre)+(String)i; String value; - if (server->hasArg(name)) - { + if(server->hasArg(name)) { value = server->arg(name); - } - else - { + } else { value = server->arg(_params[i]->getID()); } //store it in params array - value.toCharArray(_params[i]->_value, _params[i]->_length + 1); // length+1 null terminated - DEBUG_WM(DEBUG_VERBOSE, (String)_params[i]->getID() + ":", value); + value.toCharArray(_params[i]->_value, _params[i]->_length+1); // length+1 null terminated + DEBUG_WM(DEBUG_VERBOSE,(String)_params[i]->getID() + ":",value); } - DEBUG_WM(DEBUG_VERBOSE, FPSTR(D_HR)); + DEBUG_WM(DEBUG_VERBOSE,FPSTR(D_HR)); } } /** * HTTPD CALLBACK info page */ -void WiFiManager::handleInfo() -{ - DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP Info")); +void WiFiManager::handleInfo() { + DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Info")); handleRequest(); String page = getHTTPHead(FPSTR(S_titleinfo)); // @token titleinfo reportStatus(page); uint16_t infos = 0; -//@todo convert to enum or refactor to strings -#ifdef ESP8266 - infos = 27; - String infoids[] = { + //@todo convert to enum or refactor to strings + #ifdef ESP8266 + infos = 27; + String infoids[] = { F("esphead"), F("uptime"), F("chipid"), @@ -1638,11 +1404,12 @@ void WiFiManager::handleInfo() F("host"), F("stamac"), F("conx"), - F("autoconx")}; + F("autoconx") + }; -#elif defined(ESP32) - infos = 22; - String infoids[] = { + #elif defined(ESP32) + infos = 22; + String infoids[] = { F("esphead"), F("uptime"), F("chipid"), @@ -1664,279 +1431,214 @@ void WiFiManager::handleInfo() F("dnss"), F("host"), F("stamac"), - F("conx")}; -#endif + F("conx") + }; + #endif - for (size_t i = 0; i < infos; i++) - { - if (infoids[i] != NULL) - page += getInfoData(infoids[i]); + for(size_t i=0; i"); - if (_showInfoErase) - page += FPSTR(HTTP_ERASEBTN); + if(_showInfoErase) page += FPSTR(HTTP_ERASEBTN); page += FPSTR(HTTP_HELP); page += FPSTR(HTTP_END); server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); - DEBUG_WM(DEBUG_DEV, F("Sent info page")); + DEBUG_WM(DEBUG_DEV,F("Sent info page")); } -String WiFiManager::getInfoData(String id) -{ +String WiFiManager::getInfoData(String id){ String p; // @todo add versioning - if (id == F("esphead")) - p = FPSTR(HTTP_INFO_esphead); - else if (id == F("wifihead")) - p = FPSTR(HTTP_INFO_wifihead); - else if (id == F("uptime")) - { + if(id==F("esphead"))p = FPSTR(HTTP_INFO_esphead); + else if(id==F("wifihead"))p = FPSTR(HTTP_INFO_wifihead); + else if(id==F("uptime")){ // subject to rollover! p = FPSTR(HTTP_INFO_uptime); - p.replace(FPSTR(T_1), (String)(millis() / 1000 / 60)); - p.replace(FPSTR(T_2), (String)((millis() / 1000) % 60)); + p.replace(FPSTR(T_1),(String)(millis() / 1000 / 60)); + p.replace(FPSTR(T_2),(String)((millis() / 1000) % 60)); } - else if (id == F("chipid")) - { + else if(id==F("chipid")){ p = FPSTR(HTTP_INFO_chipid); - p.replace(FPSTR(T_1), String(WIFI_getChipId(), HEX)); + p.replace(FPSTR(T_1),String(WIFI_getChipId(),HEX)); } -#ifdef ESP32 - else if (id == F("chiprev")) - { - p = FPSTR(HTTP_INFO_chiprev); - String rev = (String)ESP.getChipRevision(); -#ifdef _SOC_EFUSE_REG_H_ - String revb = (String)(REG_READ(EFUSE_BLK0_RDATA3_REG) >> (EFUSE_RD_CHIP_VER_RESERVE_S) && EFUSE_RD_CHIP_VER_RESERVE_V); - p.replace(FPSTR(T_1), rev + "
" + revb); -#else - p.replace(FPSTR(T_1), rev); -#endif + #ifdef ESP32 + else if(id==F("chiprev")){ + p = FPSTR(HTTP_INFO_chiprev); + String rev = (String)ESP.getChipRevision(); + #ifdef _SOC_EFUSE_REG_H_ + String revb = (String)(REG_READ(EFUSE_BLK0_RDATA3_REG) >> (EFUSE_RD_CHIP_VER_RESERVE_S)&&EFUSE_RD_CHIP_VER_RESERVE_V); + p.replace(FPSTR(T_1),rev+"
"+revb); + #else + p.replace(FPSTR(T_1),rev); + #endif } -#endif -#ifdef ESP8266 - else if (id == F("fchipid")) - { - p = FPSTR(HTTP_INFO_fchipid); - p.replace(FPSTR(T_1), (String)ESP.getFlashChipId()); + #endif + #ifdef ESP8266 + else if(id==F("fchipid")){ + p = FPSTR(HTTP_INFO_fchipid); + p.replace(FPSTR(T_1),(String)ESP.getFlashChipId()); } -#endif - else if (id == F("idesize")) - { + #endif + else if(id==F("idesize")){ p = FPSTR(HTTP_INFO_idesize); - p.replace(FPSTR(T_1), (String)ESP.getFlashChipSize()); + p.replace(FPSTR(T_1),(String)ESP.getFlashChipSize()); } - else if (id == F("flashsize")) - { -#ifdef ESP8266 - p = FPSTR(HTTP_INFO_flashsize); - p.replace(FPSTR(T_1), (String)ESP.getFlashChipRealSize()); -#endif + else if(id==F("flashsize")){ + #ifdef ESP8266 + p = FPSTR(HTTP_INFO_flashsize); + p.replace(FPSTR(T_1),(String)ESP.getFlashChipRealSize()); + #endif } - else if (id == F("sdkver")) - { + else if(id==F("sdkver")){ p = FPSTR(HTTP_INFO_sdkver); -#ifdef ESP32 - p.replace(FPSTR(T_1), (String)esp_get_idf_version()); -#else - p.replace(FPSTR(T_1), (String)system_get_sdk_version()); -#endif + #ifdef ESP32 + p.replace(FPSTR(T_1),(String)esp_get_idf_version()); + #else + p.replace(FPSTR(T_1),(String)system_get_sdk_version()); + #endif } - else if (id == F("corever")) - { -#ifdef ESP8266 - p = FPSTR(HTTP_INFO_corever); - p.replace(FPSTR(T_1), (String)ESP.getCoreVersion()); -#endif + else if(id==F("corever")){ + #ifdef ESP8266 + p = FPSTR(HTTP_INFO_corever); + p.replace(FPSTR(T_1),(String)ESP.getCoreVersion()); + #endif } -#ifdef ESP8266 - else if (id == F("bootver")) - { - p = FPSTR(HTTP_INFO_bootver); - p.replace(FPSTR(T_1), (String)system_get_boot_version()); + #ifdef ESP8266 + else if(id==F("bootver")){ + p = FPSTR(HTTP_INFO_bootver); + p.replace(FPSTR(T_1),(String)system_get_boot_version()); } -#endif - else if (id == F("cpufreq")) - { + #endif + else if(id==F("cpufreq")){ p = FPSTR(HTTP_INFO_cpufreq); - p.replace(FPSTR(T_1), (String)ESP.getCpuFreqMHz()); + p.replace(FPSTR(T_1),(String)ESP.getCpuFreqMHz()); } - else if (id == F("freeheap")) - { + else if(id==F("freeheap")){ p = FPSTR(HTTP_INFO_freeheap); - p.replace(FPSTR(T_1), (String)ESP.getFreeHeap()); + p.replace(FPSTR(T_1),(String)ESP.getFreeHeap()); } -#ifdef ESP8266 - else if (id == F("memsketch")) - { + #ifdef ESP8266 + else if(id==F("memsketch")){ p = FPSTR(HTTP_INFO_memsketch); - p.replace(FPSTR(T_1), (String)(ESP.getSketchSize())); - p.replace(FPSTR(T_2), (String)(ESP.getSketchSize() + ESP.getFreeSketchSpace())); + p.replace(FPSTR(T_1),(String)(ESP.getSketchSize())); + p.replace(FPSTR(T_2),(String)(ESP.getSketchSize()+ESP.getFreeSketchSpace())); } -#endif -#ifdef ESP8266 - else if (id == F("memsmeter")) - { + #endif + #ifdef ESP8266 + else if(id==F("memsmeter")){ p = FPSTR(HTTP_INFO_memsmeter); - p.replace(FPSTR(T_1), (String)(ESP.getSketchSize())); - p.replace(FPSTR(T_2), (String)(ESP.getSketchSize() + ESP.getFreeSketchSpace())); + p.replace(FPSTR(T_1),(String)(ESP.getSketchSize())); + p.replace(FPSTR(T_2),(String)(ESP.getSketchSize()+ESP.getFreeSketchSpace())); } -#endif - else if (id == F("lastreset")) - { -#ifdef ESP8266 - p = FPSTR(HTTP_INFO_lastreset); - p.replace(FPSTR(T_1), (String)ESP.getResetReason()); -#elif defined(ESP32) && defined(_ROM_RTC_H_) - // requires #include - p = FPSTR(HTTP_INFO_lastreset); - for (int i = 0; i < 2; i++) - { - int reason = rtc_get_reset_reason(i); - String tok = (String)T_ss + (String)(i + 1) + (String)T_es; - switch (reason) - { - //@todo move to array - case 1: - p.replace(tok, F("Vbat power on reset")); - break; - case 3: - p.replace(tok, F("Software reset digital core")); - break; - case 4: - p.replace(tok, F("Legacy watch dog reset digital core")); - break; - case 5: - p.replace(tok, F("Deep Sleep reset digital core")); - break; - case 6: - p.replace(tok, F("Reset by SLC module, reset digital core")); - break; - case 7: - p.replace(tok, F("Timer Group0 Watch dog reset digital core")); - break; - case 8: - p.replace(tok, F("Timer Group1 Watch dog reset digital core")); - break; - case 9: - p.replace(tok, F("RTC Watch dog Reset digital core")); - break; - case 10: - p.replace(tok, F("Instrusion tested to reset CPU")); - break; - case 11: - p.replace(tok, F("Time Group reset CPU")); - break; - case 12: - p.replace(tok, F("Software reset CPU")); - break; - case 13: - p.replace(tok, F("RTC Watch dog Reset CPU")); - break; - case 14: - p.replace(tok, F("for APP CPU, reseted by PRO CPU")); - break; - case 15: - p.replace(tok, F("Reset when the vdd voltage is not stable")); - break; - case 16: - p.replace(tok, F("RTC Watch dog reset digital core and rtc module")); - break; - default: - p.replace(tok, F("NO_MEAN")); + #endif + else if(id==F("lastreset")){ + #ifdef ESP8266 + p = FPSTR(HTTP_INFO_lastreset); + p.replace(FPSTR(T_1),(String)ESP.getResetReason()); + #elif defined(ESP32) && defined(_ROM_RTC_H_) + // requires #include + p = FPSTR(HTTP_INFO_lastreset); + for(int i=0;i<2;i++){ + int reason = rtc_get_reset_reason(i); + String tok = (String)T_ss+(String)(i+1)+(String)T_es; + switch (reason) + { + //@todo move to array + case 1 : p.replace(tok,F("Vbat power on reset"));break; + case 3 : p.replace(tok,F("Software reset digital core"));break; + case 4 : p.replace(tok,F("Legacy watch dog reset digital core"));break; + case 5 : p.replace(tok,F("Deep Sleep reset digital core"));break; + case 6 : p.replace(tok,F("Reset by SLC module, reset digital core"));break; + case 7 : p.replace(tok,F("Timer Group0 Watch dog reset digital core"));break; + case 8 : p.replace(tok,F("Timer Group1 Watch dog reset digital core"));break; + case 9 : p.replace(tok,F("RTC Watch dog Reset digital core"));break; + case 10 : p.replace(tok,F("Instrusion tested to reset CPU"));break; + case 11 : p.replace(tok,F("Time Group reset CPU"));break; + case 12 : p.replace(tok,F("Software reset CPU"));break; + case 13 : p.replace(tok,F("RTC Watch dog Reset CPU"));break; + case 14 : p.replace(tok,F("for APP CPU, reseted by PRO CPU"));break; + case 15 : p.replace(tok,F("Reset when the vdd voltage is not stable"));break; + case 16 : p.replace(tok,F("RTC Watch dog reset digital core and rtc module"));break; + default : p.replace(tok,F("NO_MEAN")); + } } - } -#endif + #endif } - else if (id == F("apip")) - { + else if(id==F("apip")){ p = FPSTR(HTTP_INFO_apip); - p.replace(FPSTR(T_1), WiFi.softAPIP().toString()); + p.replace(FPSTR(T_1),WiFi.softAPIP().toString()); } - else if (id == F("apmac")) - { + else if(id==F("apmac")){ p = FPSTR(HTTP_INFO_apmac); - p.replace(FPSTR(T_1), (String)WiFi.softAPmacAddress()); + p.replace(FPSTR(T_1),(String)WiFi.softAPmacAddress()); } -#ifdef ESP32 - else if (id == F("aphost")) - { - p = FPSTR(HTTP_INFO_aphost); - p.replace(FPSTR(T_1), WiFi.softAPgetHostname()); + #ifdef ESP32 + else if(id==F("aphost")){ + p = FPSTR(HTTP_INFO_aphost); + p.replace(FPSTR(T_1),WiFi.softAPgetHostname()); } -#endif - else if (id == F("apssid")) - { + #endif + else if(id==F("apssid")){ p = FPSTR(HTTP_INFO_apssid); - p.replace(FPSTR(T_1), htmlEntities((String)WiFi_SSID())); + p.replace(FPSTR(T_1),htmlEntities((String)WiFi_SSID())); } - else if (id == F("apbssid")) - { + else if(id==F("apbssid")){ p = FPSTR(HTTP_INFO_apbssid); - p.replace(FPSTR(T_1), (String)WiFi.BSSIDstr()); + p.replace(FPSTR(T_1),(String)WiFi.BSSIDstr()); } - else if (id == F("staip")) - { + else if(id==F("staip")){ p = FPSTR(HTTP_INFO_staip); - p.replace(FPSTR(T_1), WiFi.localIP().toString()); + p.replace(FPSTR(T_1),WiFi.localIP().toString()); } - else if (id == F("stagw")) - { + else if(id==F("stagw")){ p = FPSTR(HTTP_INFO_stagw); - p.replace(FPSTR(T_1), WiFi.gatewayIP().toString()); + p.replace(FPSTR(T_1),WiFi.gatewayIP().toString()); } - else if (id == F("stasub")) - { + else if(id==F("stasub")){ p = FPSTR(HTTP_INFO_stasub); - p.replace(FPSTR(T_1), WiFi.subnetMask().toString()); + p.replace(FPSTR(T_1),WiFi.subnetMask().toString()); } - else if (id == F("dnss")) - { + else if(id==F("dnss")){ p = FPSTR(HTTP_INFO_dnss); - p.replace(FPSTR(T_1), WiFi.dnsIP().toString()); + p.replace(FPSTR(T_1),WiFi.dnsIP().toString()); } - else if (id == F("host")) - { + else if(id==F("host")){ p = FPSTR(HTTP_INFO_host); -#ifdef ESP32 - p.replace(FPSTR(T_1), WiFi.getHostname()); -#else - p.replace(FPSTR(T_1), WiFi.hostname()); -#endif + #ifdef ESP32 + p.replace(FPSTR(T_1),WiFi.getHostname()); + #else + p.replace(FPSTR(T_1),WiFi.hostname()); + #endif } - else if (id == F("stamac")) - { + else if(id==F("stamac")){ p = FPSTR(HTTP_INFO_stamac); - p.replace(FPSTR(T_1), WiFi.macAddress()); + p.replace(FPSTR(T_1),WiFi.macAddress()); } - else if (id == F("conx")) - { + else if(id==F("conx")){ p = FPSTR(HTTP_INFO_conx); - p.replace(FPSTR(T_1), WiFi.isConnected() ? FPSTR(S_y) : FPSTR(S_n)); + p.replace(FPSTR(T_1),WiFi.isConnected() ? FPSTR(S_y) : FPSTR(S_n)); } -#ifdef ESP8266 - else if (id == F("autoconx")) - { + #ifdef ESP8266 + else if(id==F("autoconx")){ p = FPSTR(HTTP_INFO_autoconx); - p.replace(FPSTR(T_1), WiFi.getAutoConnect() ? FPSTR(S_enable) : FPSTR(S_disable)); + p.replace(FPSTR(T_1),WiFi.getAutoConnect() ? FPSTR(S_enable) : FPSTR(S_disable)); } -#endif + #endif return p; } /** * HTTPD CALLBACK root or redirect to captive portal */ -void WiFiManager::handleExit() -{ - DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP Exit")); +void WiFiManager::handleExit() { + DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Exit")); handleRequest(); String page = getHTTPHead(FPSTR(S_titleexit)); // @token titleexit - page += FPSTR(S_exiting); // @token exiting + page += FPSTR(S_exiting); // @token exiting server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); abort = true; @@ -1945,12 +1647,11 @@ void WiFiManager::handleExit() /** * HTTPD CALLBACK reset page */ -void WiFiManager::handleReset() -{ - DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP Reset")); +void WiFiManager::handleReset() { + DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Reset")); handleRequest(); String page = getHTTPHead(FPSTR(S_titlereset)); //@token titlereset - page += FPSTR(S_resetting); //@token resetting + page += FPSTR(S_resetting); //@token resetting page += FPSTR(HTTP_END); server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); @@ -1968,60 +1669,53 @@ void WiFiManager::handleReset() // void WiFiManager::handleErase() { // handleErase(false); // } -void WiFiManager::handleErase(boolean opt) -{ - DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP Erase")); +void WiFiManager::handleErase(boolean opt) { + DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP Erase")); handleRequest(); String page = getHTTPHead(FPSTR(S_titleerase)); // @token titleerase bool ret = erase(opt); - if (ret) - page += FPSTR(S_resetting); // @token resetting - else - { + if(ret) page += FPSTR(S_resetting); // @token resetting + else { page += FPSTR(S_error); // @token erroroccur - DEBUG_WM(DEBUG_ERROR, F("[ERROR] WiFi EraseConfig failed")); + DEBUG_WM(DEBUG_ERROR,F("[ERROR] WiFi EraseConfig failed")); } page += FPSTR(HTTP_END); server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); - if (ret) - { + if(ret){ delay(2000); - DEBUG_WM(F("RESETTING ESP")); - reboot(); - } + DEBUG_WM(F("RESETTING ESP")); + reboot(); + } } /** * HTTPD CALLBACK 404 */ -void WiFiManager::handleNotFound() -{ - if (captivePortal()) - return; // If captive portal redirect instead of displaying the page +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 += 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 += ( 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"; + 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")); server->sendHeader(F("Pragma"), F("no-cache")); server->sendHeader(F("Expires"), F("-1")); server->sendHeader(FPSTR(HTTP_HEAD_CL), String(message.length())); - server->send(404, FPSTR(HTTP_HEAD_CT2), message); + server->send ( 404, FPSTR(HTTP_HEAD_CT2), message ); } /** @@ -2029,84 +1723,70 @@ void WiFiManager::handleNotFound() * Redirect to captive portal if we got a request for another domain. * Return true in that case so the page handler do not try to handle the request again. */ -boolean WiFiManager::captivePortal() -{ - DEBUG_WM(DEBUG_DEV, "-> " + server->hostHeader()); +boolean WiFiManager::captivePortal() { + DEBUG_WM(DEBUG_DEV,"-> " + server->hostHeader()); + + if(!_enableCaptivePortal) return false; // skip redirections - if (!_enableCaptivePortal) - return false; // skip redirections - - if (!isIp(server->hostHeader())) - { - DEBUG_WM(DEBUG_VERBOSE, F("<- Request redirected to captive portal")); + if (!isIp(server->hostHeader())) { + DEBUG_WM(DEBUG_VERBOSE,F("<- Request redirected to captive portal")); server->sendHeader(F("Location"), (String)F("http://") + toStringIp(server->client().localIP()), true); - server->send(302, FPSTR(HTTP_HEAD_CT2), ""); // Empty content inhibits Content-length header so we have to close the socket ourselves. - server->client().stop(); // Stop is needed because we sent no content length + server->send ( 302, FPSTR(HTTP_HEAD_CT2), ""); // Empty content inhibits Content-length header so we have to close the socket ourselves. + server->client().stop(); // Stop is needed because we sent no content length return true; } return false; } -void WiFiManager::stopCaptivePortal() -{ - _enableCaptivePortal = false; +void WiFiManager::stopCaptivePortal(){ + _enableCaptivePortal= false; // @todo maybe disable configportaltimeout(optional), or just provide callback for user } -void WiFiManager::handleClose() -{ +void WiFiManager::handleClose(){ stopCaptivePortal(); - DEBUG_WM(DEBUG_VERBOSE, F("<- HTTP close")); + DEBUG_WM(DEBUG_VERBOSE,F("<- HTTP close")); handleRequest(); String page = getHTTPHead(FPSTR(S_titleclose)); // @token titleclose - page += FPSTR(S_closing); // @token closing + page += FPSTR(S_closing); // @token closing server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); server->send(200, FPSTR(HTTP_HEAD_CT), page); } -void WiFiManager::reportStatus(String &page) -{ +void WiFiManager::reportStatus(String &page){ updateConxResult(WiFi.status()); String str; - if (WiFi_SSID() != "") - { - if (WiFi.status() == WL_CONNECTED) - { + if (WiFi_SSID() != ""){ + if (WiFi.status()==WL_CONNECTED){ str = FPSTR(HTTP_STATUS_ON); - str.replace(FPSTR(T_i), WiFi.localIP().toString()); - str.replace(FPSTR(T_v), htmlEntities(WiFi_SSID())); + str.replace(FPSTR(T_i),WiFi.localIP().toString()); + str.replace(FPSTR(T_v),htmlEntities(WiFi_SSID())); } - else - { + else { str = FPSTR(HTTP_STATUS_OFF); - str.replace(FPSTR(T_v), htmlEntities(WiFi_SSID())); - if (_lastconxresult == WL_STATION_WRONG_PASSWORD) - { + str.replace(FPSTR(T_v),htmlEntities(WiFi_SSID())); + if(_lastconxresult == WL_STATION_WRONG_PASSWORD){ // wrong password - str.replace(FPSTR(T_c), "D"); // class - str.replace(FPSTR(T_r), FPSTR(HTTP_STATUS_OFFPW)); + str.replace(FPSTR(T_c),"D"); // class + str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_OFFPW)); } - else if (_lastconxresult == WL_NO_SSID_AVAIL) - { + else if(_lastconxresult == WL_NO_SSID_AVAIL){ // connect failed, or ap not found - str.replace(FPSTR(T_c), "D"); - str.replace(FPSTR(T_r), FPSTR(HTTP_STATUS_OFFNOAP)); + str.replace(FPSTR(T_c),"D"); + str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_OFFNOAP)); } - else if (_lastconxresult == WL_CONNECT_FAILED) - { + else if(_lastconxresult == WL_CONNECT_FAILED){ // connect failed - str.replace(FPSTR(T_c), "D"); - str.replace(FPSTR(T_r), FPSTR(HTTP_STATUS_OFFFAIL)); - } - else - { - str.replace(FPSTR(T_c), ""); - str.replace(FPSTR(T_r), ""); + str.replace(FPSTR(T_c),"D"); + str.replace(FPSTR(T_r),FPSTR(HTTP_STATUS_OFFFAIL)); } + else{ + str.replace(FPSTR(T_c),""); + str.replace(FPSTR(T_r),""); + } } } - else - { + else { str = FPSTR(HTTP_STATUS_NONE); } page += str; @@ -2126,13 +1806,11 @@ void WiFiManager::reportStatus(String &page) * @since $dev * @return bool success */ -bool WiFiManager::disconnect() -{ - if (WiFi.status() != WL_CONNECTED) - { - DEBUG_WM(DEBUG_VERBOSE, "Disconnecting: Not connected"); +bool WiFiManager::disconnect(){ + if(WiFi.status() != WL_CONNECTED){ + DEBUG_WM(DEBUG_VERBOSE,"Disconnecting: Not connected"); return false; - } + } DEBUG_WM("Disconnecting"); return WiFi_Disconnect(); } @@ -2141,8 +1819,7 @@ bool WiFiManager::disconnect() * reboot the device * @access public */ -void WiFiManager::reboot() -{ +void WiFiManager::reboot(){ DEBUG_WM("Restarting"); ESP.restart(); } @@ -2151,31 +1828,28 @@ void WiFiManager::reboot() * reboot the device * @access public */ -bool WiFiManager::erase() -{ +bool WiFiManager::erase(){ return erase(false); } -bool WiFiManager::erase(bool opt) -{ +bool WiFiManager::erase(bool opt){ DEBUG_WM("Erasing"); -#if defined(ESP32) && ((defined(WM_ERASE_NVS) || defined(nvs_flash_h))) - // if opt true, do nvs erase - if (opt) - { - DEBUG_WM("Erasing NVS"); - int err; - esp_err_t err; - err = nvs_flash_init(); - DEBUG_WM(DEBUG_VERBOSE, "nvs_flash_init: ", err != ESP_OK ? (String)err : "Success"); - err = nvs_flash_erase(); - DEBUG_WM(DEBUG_VERBOSE, "nvs_flash_erase: ", err != ESP_OK ? (String)err : "Success"); - return err == ESP_OK; - } -#else - (void)opt; -#endif + #if defined(ESP32) && ((defined(WM_ERASE_NVS) || defined(nvs_flash_h))) + // if opt true, do nvs erase + if(opt){ + DEBUG_WM("Erasing NVS"); + int err; + esp_err_t err; + err = nvs_flash_init(); + DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_init: ",err!=ESP_OK ? (String)err : "Success"); + err = nvs_flash_erase(); + DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_erase: ", err!=ESP_OK ? (String)err : "Success"); + return err == ESP_OK; + } + #else + (void)opt; + #endif return WiFi_eraseConfig(); } @@ -2185,18 +1859,17 @@ bool WiFiManager::erase(bool opt) * ERASES STA CREDENTIALS * @access public */ -void WiFiManager::resetSettings() -{ +void WiFiManager::resetSettings() { DEBUG_WM(F("SETTINGS ERASED")); - WiFi_enableSTA(true, true); // must be sta to disconnect erase - -#ifdef ESP32 - WiFi.disconnect(true, true); -#else - WiFi.persistent(true); - WiFi.disconnect(true); - WiFi.persistent(false); -#endif + WiFi_enableSTA(true,true); // must be sta to disconnect erase + + #ifdef ESP32 + WiFi.disconnect(true,true); + #else + WiFi.persistent(true); + WiFi.disconnect(true); + WiFi.persistent(false); + #endif } // SETTERS @@ -2206,8 +1879,7 @@ void WiFiManager::resetSettings() * @access public * @param {[type]} unsigned long seconds [description] */ -void WiFiManager::setTimeout(unsigned long seconds) -{ +void WiFiManager::setTimeout(unsigned long seconds) { setConfigPortalTimeout(seconds); } @@ -2216,8 +1888,7 @@ void WiFiManager::setTimeout(unsigned long seconds) * @access public * @param {[type]} unsigned long seconds [description] */ -void WiFiManager::setConfigPortalTimeout(unsigned long seconds) -{ +void WiFiManager::setConfigPortalTimeout(unsigned long seconds) { _configPortalTimeout = seconds * 1000; } @@ -2226,8 +1897,7 @@ void WiFiManager::setConfigPortalTimeout(unsigned long seconds) * @access public * @param {[type]} unsigned long seconds [description] */ -void WiFiManager::setConnectTimeout(unsigned long seconds) -{ +void WiFiManager::setConnectTimeout(unsigned long seconds) { _connectTimeout = seconds * 1000; } @@ -2236,8 +1906,7 @@ void WiFiManager::setConnectTimeout(unsigned long seconds) * @access public * @param {[type]} unsigned long seconds [description] */ -void WiFiManager::setSaveConnectTimeout(unsigned long seconds) -{ +void WiFiManager::setSaveConnectTimeout(unsigned long seconds) { _saveTimeout = seconds * 1000; } @@ -2246,8 +1915,7 @@ void WiFiManager::setSaveConnectTimeout(unsigned long seconds) * @access public * @param {[type]} boolean debug [description] */ -void WiFiManager::setDebugOutput(boolean debug) -{ +void WiFiManager::setDebugOutput(boolean debug) { _debug = debug; } @@ -2258,8 +1926,7 @@ void WiFiManager::setDebugOutput(boolean debug) * @param {[type]} IPAddress gw [description] * @param {[type]} IPAddress sn [description] */ -void WiFiManager::setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) -{ +void WiFiManager::setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) { _ap_static_ip = ip; _ap_static_gw = gw; _ap_static_sn = sn; @@ -2272,8 +1939,7 @@ void WiFiManager::setAPStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) * @param {[type]} IPAddress gw [description] * @param {[type]} IPAddress sn [description] */ -void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) -{ +void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) { _sta_static_ip = ip; _sta_static_gw = gw; _sta_static_sn = sn; @@ -2288,9 +1954,8 @@ void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn) * @param {[type]} IPAddress sn [description] * @param {[type]} IPAddress dns [description] */ -void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn, IPAddress dns) -{ - setSTAStaticIPConfig(ip, gw, sn); +void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn, IPAddress dns) { + setSTAStaticIPConfig(ip,gw,sn); _sta_static_dns = dns; } @@ -2299,8 +1964,7 @@ void WiFiManager::setSTAStaticIPConfig(IPAddress ip, IPAddress gw, IPAddress sn, * @access public * @param {[type]} int quality [description] */ -void WiFiManager::setMinimumSignalQuality(int quality) -{ +void WiFiManager::setMinimumSignalQuality(int quality) { _minimumQuality = quality; } @@ -2309,8 +1973,7 @@ void WiFiManager::setMinimumSignalQuality(int quality) * @access public * @param {[type]} boolean shouldBreak [description] */ -void WiFiManager::setBreakAfterConfig(boolean shouldBreak) -{ +void WiFiManager::setBreakAfterConfig(boolean shouldBreak) { _shouldBreakAfterConfig = shouldBreak; } @@ -2319,30 +1982,27 @@ void WiFiManager::setBreakAfterConfig(boolean shouldBreak) * @access public * @param {[type]} void (*func)(WiFiManager* myWiFiManager) [description] */ -void WiFiManager::setAPCallback(std::function func) -{ +void WiFiManager::setAPCallback( std::function func ) { _apcallback = func; } - + /** * setSaveConfigCallback, set a save config callback after closing configportal * @todo only calls if configportal stopped * @access public * @param {[type]} void (*func)(void) [description] */ -void WiFiManager::setSaveConfigCallback(std::function func) -{ +void WiFiManager::setSaveConfigCallback( std::function func ) { _savecallback = func; } /** - * setSaveConfigCallback, set a save config callback after closing configportal + * setPreSaveConfigCallback, set a pre save config callback after closing configportal * @todo only calls if configportal stopped * @access public * @param {[type]} void (*func)(void) [description] */ -void WiFiManager::setPreSaveConfigCallback(std::function func) -{ +void WiFiManager::setPreSaveConfigCallback( std::function func ) { _presavecallback = func; } @@ -2352,8 +2012,7 @@ void WiFiManager::setPreSaveConfigCallback(std::function func) * @access public * @param char element */ -void WiFiManager::setCustomHeadElement(const char *element) -{ +void WiFiManager::setCustomHeadElement(const char* element) { _customHeadElement = element; } @@ -2364,8 +2023,7 @@ void WiFiManager::setCustomHeadElement(const char *element) * @access public * @param boolean removeDuplicates [true] */ -void WiFiManager::setRemoveDuplicateAPs(boolean removeDuplicates) -{ +void WiFiManager::setRemoveDuplicateAPs(boolean removeDuplicates) { _removeDuplicateAPs = removeDuplicates; } @@ -2377,8 +2035,7 @@ void WiFiManager::setRemoveDuplicateAPs(boolean removeDuplicates) * @access public * @param boolean shoudlBlock [false] */ -void WiFiManager::setConfigPortalBlocking(boolean shoudlBlock) -{ +void WiFiManager::setConfigPortalBlocking(boolean shoudlBlock) { _configPortalIsBlocking = shoudlBlock; } @@ -2390,11 +2047,9 @@ void WiFiManager::setConfigPortalBlocking(boolean shoudlBlock) * @access public * @param boolean persistent [true] */ -void WiFiManager::setRestorePersistent(boolean persistent) -{ +void WiFiManager::setRestorePersistent(boolean persistent) { _userpersistent = persistent; - if (!persistent) - DEBUG_WM(F("persistent is off")); + if(!persistent) DEBUG_WM(F("persistent is off")); } /** @@ -2404,12 +2059,9 @@ void WiFiManager::setRestorePersistent(boolean persistent) * @access public * @param boolean alwaysShow [false] */ -void WiFiManager::setShowStaticFields(boolean alwaysShow) -{ - if (_disableIpFields) - _staShowStaticFields = alwaysShow ? 1 : -1; - else - _staShowStaticFields = alwaysShow ? 1 : 0; +void WiFiManager::setShowStaticFields(boolean alwaysShow){ + if(_disableIpFields) _staShowStaticFields = alwaysShow ? 1 : -1; + else _staShowStaticFields = alwaysShow ? 1 : 0; } /** @@ -2419,10 +2071,8 @@ void WiFiManager::setShowStaticFields(boolean alwaysShow) * @access public * @param boolean alwaysShow [false] */ -void WiFiManager::setShowDnsFields(boolean alwaysShow) -{ - if (_disableIpFields) - _staShowDns = alwaysShow ? 1 : -1; +void WiFiManager::setShowDnsFields(boolean alwaysShow){ + if(_disableIpFields) _staShowDns = alwaysShow ? 1 : -1; _staShowDns = alwaysShow ? 1 : 0; } @@ -2434,8 +2084,7 @@ void WiFiManager::setShowDnsFields(boolean alwaysShow) * @access public * @param boolean enabled [true] */ -void WiFiManager::setCaptivePortalEnable(boolean enabled) -{ +void WiFiManager::setCaptivePortalEnable(boolean enabled){ _enableCaptivePortal = enabled; } @@ -2448,8 +2097,7 @@ void WiFiManager::setCaptivePortalEnable(boolean enabled) * @access public * @param boolean enabled [true] */ -void WiFiManager::setWiFiAutoReconnect(boolean enabled) -{ +void WiFiManager::setWiFiAutoReconnect(boolean enabled){ _wifiAutoReconnect = enabled; } @@ -2461,8 +2109,7 @@ void WiFiManager::setWiFiAutoReconnect(boolean enabled) * @access public * @param boolean enabled [false] */ -void WiFiManager::setCaptivePortalClientCheck(boolean enabled) -{ +void WiFiManager::setCaptivePortalClientCheck(boolean enabled){ _cpClientCheck = enabled; } @@ -2473,8 +2120,7 @@ void WiFiManager::setCaptivePortalClientCheck(boolean enabled) * @access public * @param boolean enabled [true] */ -void WiFiManager::setWebPortalClientCheck(boolean enabled) -{ +void WiFiManager::setWebPortalClientCheck(boolean enabled){ _webClientCheck = enabled; } @@ -2484,8 +2130,7 @@ void WiFiManager::setWebPortalClientCheck(boolean enabled) * @access public * @param boolean enabled [false] */ -void WiFiManager::setScanDispPerc(boolean enabled) -{ +void WiFiManager::setScanDispPerc(boolean enabled){ _scanDispOptions = enabled; } @@ -2498,9 +2143,10 @@ void WiFiManager::setScanDispPerc(boolean enabled) */ void WiFiManager::setEnableConfigPortal(boolean enable) { - _enableConfigPortal = enable; + _enableConfigPortal = enable; } + /** * set the hostname (dhcp client id) * @since $dev @@ -2508,8 +2154,7 @@ void WiFiManager::setEnableConfigPortal(boolean enable) * @param char* hostname 32 character hostname to use for sta+ap in esp32, sta in esp8266 * @return bool false if hostname is not valid */ -bool WiFiManager::setHostname(const char *hostname) -{ +bool WiFiManager::setHostname(const char * hostname){ //@todo max length 32 _hostname = hostname; return true; @@ -2519,8 +2164,7 @@ bool WiFiManager::setHostname(const char *hostname) * toggle showing erase wifi config button on info page * @param boolean enabled */ -void WiFiManager::setShowInfoErase(boolean enabled) -{ +void WiFiManager::setShowInfoErase(boolean enabled){ _showInfoErase = enabled; } @@ -2533,18 +2177,13 @@ void WiFiManager::setShowInfoErase(boolean enabled) * @since $dev * @param uint8_t menu[] array of menu ids */ -void WiFiManager::setMenu(const char *menu[], uint8_t size) -{ +void WiFiManager::setMenu(const char * menu[], uint8_t size){ // DEBUG_WM(DEBUG_VERBOSE,"setmenu array"); _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] == "param") - _paramsInWifi = false; // param auto flag + 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] == "param") _paramsInWifi = false; // param auto flag _menuIds.push_back(j); } } @@ -2561,18 +2200,13 @@ void WiFiManager::setMenu(const char *menu[], uint8_t size) * @shiftIncrement $dev * @param {[type]} std::vector& menu [description] */ -void WiFiManager::setMenu(std::vector &menu) -{ +void WiFiManager::setMenu(std::vector& menu){ // DEBUG_WM(DEBUG_VERBOSE,"setmenu vector"); _menuIds.clear(); - for (auto menuitem : menu) - { - for (size_t j = 0; j < _nummenutokens; j++) - { - if (menuitem == _menutokens[j]) - { - if ((String)menuitem == "param") - _paramsInWifi = false; // param auto flag + for(auto menuitem : menu ){ + for(size_t j = 0; j < _nummenutokens; j++){ + if(menuitem == _menutokens[j]){ + if((String)menuitem == "param") _paramsInWifi = false; // param auto flag _menuIds.push_back(j); } } @@ -2580,6 +2214,7 @@ void WiFiManager::setMenu(std::vector &menu) // DEBUG_WM(getMenuOut()); } + // GETTERS /** @@ -2588,8 +2223,7 @@ void WiFiManager::setMenu(std::vector &menu) * @access public * @return String the configportal ap name */ -String WiFiManager::getConfigPortalSSID() -{ +String WiFiManager::getConfigPortalSSID() { return _apName; } @@ -2601,8 +2235,7 @@ String WiFiManager::getConfigPortalSSID() * @access public * @return bool return wl_status codes */ -uint8_t WiFiManager::getLastConxResult() -{ +uint8_t WiFiManager::getLastConxResult(){ return _lastconxresult; } @@ -2612,8 +2245,7 @@ uint8_t WiFiManager::getLastConxResult() * @access public * @return bool true if a saved ap config exists */ -bool WiFiManager::getWiFiIsSaved() -{ +bool WiFiManager::getWiFiIsSaved(){ return WiFi_hasAutoConnect(); } @@ -2622,8 +2254,7 @@ bool WiFiManager::getWiFiIsSaved() * @since $dev * @param String cc country code, must be defined in WiFiSetCountry, US, JP, CN */ -void WiFiManager::setCountry(String cc) -{ +void WiFiManager::setCountry(String cc){ _wificountry = cc; } @@ -2631,51 +2262,41 @@ void WiFiManager::setCountry(String cc) * setClass * @param String str body class string */ -void WiFiManager::setClass(String str) -{ +void WiFiManager::setClass(String str){ _bodyClass = str; } - + // HELPERS // DEBUG // @todo fix DEBUG_WM(0,0); template -void WiFiManager::DEBUG_WM(Generic text) -{ - DEBUG_WM(DEBUG_NOTIFY, text, ""); +void WiFiManager::DEBUG_WM(Generic text) { + DEBUG_WM(DEBUG_NOTIFY,text,""); } template -void WiFiManager::DEBUG_WM(wm_debuglevel_t level, Generic text) -{ - if (_debugLevel >= level) - DEBUG_WM(level, text, ""); +void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text) { + if(_debugLevel >= level) DEBUG_WM(level,text,""); } template -void WiFiManager::DEBUG_WM(Generic text, Genericb textb) -{ - DEBUG_WM(DEBUG_NOTIFY, text, textb); +void WiFiManager::DEBUG_WM(Generic text,Genericb textb) { + DEBUG_WM(DEBUG_NOTIFY,text,textb); } template -void WiFiManager::DEBUG_WM(wm_debuglevel_t level, Generic text, Genericb textb) -{ - if (!_debug || _debugLevel < level) - return; +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){ _debugPort.print("MEM: "); _debugPort.println((String)ESP.getFreeHeap()); } _debugPort.print("*WM: "); - if (_debugLevel == DEBUG_DEV) - _debugPort.print("[" + (String)level + "] "); + if(_debugLevel == DEBUG_DEV) _debugPort.print("["+(String)level+"] "); _debugPort.print(text); - if (textb) - { + if(textb){ _debugPort.print(" "); _debugPort.print(textb); } @@ -2687,28 +2308,27 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level, Generic text, Genericb textb) * @access public * @return {[type]} [description] */ -void WiFiManager::debugSoftAPConfig() -{ -#ifdef ESP8266 - softap_config config; - wifi_softap_get_config(&config); -#elif defined(ESP32) - wifi_config_t conf_config; - esp_wifi_get_config(WIFI_IF_AP, &conf_config); // == ESP_OK - wifi_ap_config_t config = conf_config.ap; -#endif +void WiFiManager::debugSoftAPConfig(){ + #ifdef ESP8266 + softap_config config; + wifi_softap_get_config(&config); + #elif defined(ESP32) + wifi_config_t conf_config; + esp_wifi_get_config(WIFI_IF_AP, &conf_config); // == ESP_OK + wifi_ap_config_t config = conf_config.ap; + #endif - DEBUG_WM(F("SoftAP Configuration")); - DEBUG_WM(FPSTR(D_HR)); - DEBUG_WM(F("ssid: "), (char *)config.ssid); - DEBUG_WM(F("password: "), (char *)config.password); - DEBUG_WM(F("ssid_len: "), config.ssid_len); - DEBUG_WM(F("channel: "), config.channel); - DEBUG_WM(F("authmode: "), config.authmode); - DEBUG_WM(F("ssid_hidden: "), config.ssid_hidden); - DEBUG_WM(F("max_connection: "), config.max_connection); - DEBUG_WM(F("beacon_interval: "), (String)config.beacon_interval + "(ms)"); - DEBUG_WM(FPSTR(D_HR)); + DEBUG_WM(F("SoftAP Configuration")); + DEBUG_WM(FPSTR(D_HR)); + DEBUG_WM(F("ssid: "),(char *) config.ssid); + DEBUG_WM(F("password: "),(char *) config.password); + DEBUG_WM(F("ssid_len: "),config.ssid_len); + DEBUG_WM(F("channel: "),config.channel); + DEBUG_WM(F("authmode: "),config.authmode); + DEBUG_WM(F("ssid_hidden: "),config.ssid_hidden); + DEBUG_WM(F("max_connection: "),config.max_connection); + DEBUG_WM(F("beacon_interval: "),(String)config.beacon_interval + "(ms)"); + DEBUG_WM(FPSTR(D_HR)); } /** @@ -2716,48 +2336,38 @@ void WiFiManager::debugSoftAPConfig() * @access public * @return {[type]} [description] */ -void WiFiManager::debugPlatformInfo() -{ -#ifdef ESP8266 - system_print_meminfo(); - DEBUG_WM(F("getCoreVersion(): "), ESP.getCoreVersion()); - DEBUG_WM(F("system_get_sdk_version(): "), system_get_sdk_version()); - DEBUG_WM(F("system_get_boot_version():"), system_get_boot_version()); - DEBUG_WM(F("getFreeHeap(): "), (String)ESP.getFreeHeap()); -#elif defined(ESP32) - size_t freeHeap = heap_caps_get_free_size(MALLOC_CAP_8BIT); - DEBUG_WM("Free heap: ", freeHeap); - DEBUG_WM("ESP-IDF version: ", esp_get_idf_version()); -#endif +void WiFiManager::debugPlatformInfo(){ + #ifdef ESP8266 + system_print_meminfo(); + DEBUG_WM(F("getCoreVersion(): "),ESP.getCoreVersion()); + DEBUG_WM(F("system_get_sdk_version(): "),system_get_sdk_version()); + DEBUG_WM(F("system_get_boot_version():"),system_get_boot_version()); + DEBUG_WM(F("getFreeHeap(): "),(String)ESP.getFreeHeap()); + #elif defined(ESP32) + size_t freeHeap = heap_caps_get_free_size(MALLOC_CAP_8BIT); + DEBUG_WM("Free heap: ", freeHeap); + DEBUG_WM("ESP-IDF version: ", esp_get_idf_version()); + #endif } -int WiFiManager::getRSSIasQuality(int RSSI) -{ +int WiFiManager::getRSSIasQuality(int RSSI) { int quality = 0; - if (RSSI <= -100) - { + if (RSSI <= -100) { quality = 0; - } - else if (RSSI >= -50) - { + } else if (RSSI >= -50) { quality = 100; - } - else - { + } else { quality = 2 * (RSSI + 100); } return quality; } /** Is this an IP? */ -boolean WiFiManager::isIp(String str) -{ - for (size_t i = 0; i < str.length(); i++) - { +boolean WiFiManager::isIp(String str) { + for (size_t i = 0; i < str.length(); i++) { int c = str.charAt(i); - if (c != '.' && (c < '0' || c > '9')) - { + if (c != '.' && (c < '0' || c > '9')) { return false; } } @@ -2765,31 +2375,25 @@ boolean WiFiManager::isIp(String str) } /** IP to String? */ -String WiFiManager::toStringIp(IPAddress ip) -{ +String WiFiManager::toStringIp(IPAddress ip) { String res = ""; - for (int i = 0; i < 3; i++) - { + for (int i = 0; i < 3; i++) { res += String((ip >> (8 * i)) & 0xFF) + "."; } res += String(((ip >> 8 * 3)) & 0xFF); return res; } -boolean WiFiManager::validApPassword() -{ +boolean WiFiManager::validApPassword(){ // check that ap password is valid, return false - if (_apPassword == NULL) - _apPassword = ""; - if (_apPassword != "") - { - if (_apPassword.length() < 8 || _apPassword.length() > 63) - { + if (_apPassword == NULL) _apPassword = ""; + if (_apPassword != "") { + if (_apPassword.length() < 8 || _apPassword.length() > 63) { DEBUG_WM(F("AccessPoint set password is INVALID or <8 chars")); _apPassword = ""; return false; // @todo FATAL or fallback to empty ? } - DEBUG_WM(DEBUG_VERBOSE, F("AccessPoint set password is VALID")); + DEBUG_WM(DEBUG_VERBOSE,F("AccessPoint set password is VALID")); DEBUG_WM(_apPassword); } return true; @@ -2801,17 +2405,16 @@ boolean WiFiManager::validApPassword() * @param string str string to replace entities * @return string encoded string */ -String WiFiManager::htmlEntities(String str) -{ - str.replace("&", "&"); - str.replace("<", "<"); - str.replace(">", ">"); +String WiFiManager::htmlEntities(String str) { + str.replace("&","&"); + str.replace("<","<"); + str.replace(">",">"); // str.replace("'","'"); // str.replace("\"","""); // str.replace("/": "/"); // str.replace("`": "`"); // str.replace("=": "="); - return str; +return str; } /** @@ -2820,240 +2423,191 @@ String WiFiManager::htmlEntities(String str) * @param {[type]} uint8_t status [description] * @return {[type]} [description] */ -String WiFiManager::getWLStatusString(uint8_t status) -{ - if (status <= 7) - return WIFI_STA_STATUS[status]; +String WiFiManager::getWLStatusString(uint8_t status){ + if(status <= 7) return WIFI_STA_STATUS[status]; return FPSTR(S_NA); } -String WiFiManager::encryptionTypeStr(uint8_t authmode) -{ +String WiFiManager::encryptionTypeStr(uint8_t authmode) { // DEBUG_WM("enc_tye: ",authmode); return AUTH_MODE_NAMES[authmode]; } -String WiFiManager::getModeString(uint8_t mode) -{ - if (mode <= 3) - return WIFI_MODES[mode]; +String WiFiManager::getModeString(uint8_t mode){ + if(mode <= 3) return WIFI_MODES[mode]; return FPSTR(S_NA); } -bool WiFiManager::WiFiSetCountry() -{ +bool WiFiManager::WiFiSetCountry(){ bool ret = false; -#ifdef ESP32 + #ifdef ESP32 // @todo check if wifi is init, no idea how, doesnt seem to be exposed - if (_wificountry == "") - return ret; // skip not set - else if (WiFi.getMode() == WIFI_MODE_NULL) - ; // exception if wifi not init! - else if (_wificountry == "US") - ret = esp_wifi_set_country(&WM_COUNTRY_US) == ESP_OK; - else if (_wificountry == "JP") - ret = esp_wifi_set_country(&WM_COUNTRY_JP) == ESP_OK; - else if (_wificountry == "CN") - ret = esp_wifi_set_country(&WM_COUNTRY_CN) == ESP_OK; - else - DEBUG_WM(DEBUG_ERROR, "[ERROR] country code not found"); - - if (ret) - DEBUG_WM(DEBUG_VERBOSE, "esp_wifi_set_country: " + _wificountry); - else - DEBUG_WM(DEBUG_ERROR, "[ERROR] esp_wifi_set_country failed"); -#endif + if(_wificountry == "") return ret; // skip not set + else if(WiFi.getMode() == WIFI_MODE_NULL); // exception if wifi not init! + else if(_wificountry == "US") ret = esp_wifi_set_country(&WM_COUNTRY_US) == ESP_OK; + else if(_wificountry == "JP") ret = esp_wifi_set_country(&WM_COUNTRY_JP) == ESP_OK; + else if(_wificountry == "CN") ret = esp_wifi_set_country(&WM_COUNTRY_CN) == ESP_OK; + else DEBUG_WM(DEBUG_ERROR,"[ERROR] country code not found"); + + if(ret) DEBUG_WM(DEBUG_VERBOSE,"esp_wifi_set_country: " + _wificountry); + else DEBUG_WM(DEBUG_ERROR,"[ERROR] esp_wifi_set_country failed"); + #endif return ret; } -// set mode ignores WiFi.persistent -bool WiFiManager::WiFi_Mode(WiFiMode_t m, bool persistent) -{ - bool ret; -#ifdef ESP8266 - if ((wifi_get_opmode() == (uint8)m) && !persistent) - { - return true; - } - ETS_UART_INTR_DISABLE(); - if (persistent) - ret = wifi_set_opmode(m); - else - ret = wifi_set_opmode_current(m); - ETS_UART_INTR_ENABLE(); - return ret; -#elif defined(ESP32) - if (persistent && esp32persistent) - WiFi.persistent(true); - ret = WiFi.mode(m); // @todo persistent check persistant mode , NI - if (persistent && esp32persistent) - WiFi.persistent(false); - return ret; -#endif + +// set mode ignores WiFi.persistent +bool WiFiManager::WiFi_Mode(WiFiMode_t m,bool persistent) { + bool ret; + #ifdef ESP8266 + if((wifi_get_opmode() == (uint8) m ) && !persistent) { + return true; + } + ETS_UART_INTR_DISABLE(); + if(persistent) ret = wifi_set_opmode(m); + else ret = wifi_set_opmode_current(m); + ETS_UART_INTR_ENABLE(); + return ret; + #elif defined(ESP32) + if(persistent && esp32persistent) WiFi.persistent(true); + ret = WiFi.mode(m); // @todo persistent check persistant mode , NI + if(persistent && esp32persistent) WiFi.persistent(false); + return ret; + #endif } -bool WiFiManager::WiFi_Mode(WiFiMode_t m) -{ - return WiFi_Mode(m, false); +bool WiFiManager::WiFi_Mode(WiFiMode_t m) { + return WiFi_Mode(m,false); } // sta disconnect without persistent -bool WiFiManager::WiFi_Disconnect() -{ -#ifdef ESP8266 - if ((WiFi.getMode() & WIFI_STA) != 0) - { - bool ret; - DEBUG_WM(DEBUG_DEV, F("WIFI station disconnect")); - ETS_UART_INTR_DISABLE(); // @todo probably not needed - ret = wifi_station_disconnect(); - ETS_UART_INTR_ENABLE(); - return ret; - } -#elif defined(ESP32) - DEBUG_WM(DEBUG_DEV, F("WIFI station disconnect")); - return WiFi.disconnect(); // not persistent atm -#endif - return false; +bool WiFiManager::WiFi_Disconnect() { + #ifdef ESP8266 + if((WiFi.getMode() & WIFI_STA) != 0) { + bool ret; + DEBUG_WM(DEBUG_DEV,F("WIFI station disconnect")); + ETS_UART_INTR_DISABLE(); // @todo probably not needed + ret = wifi_station_disconnect(); + ETS_UART_INTR_ENABLE(); + return ret; + } + #elif defined(ESP32) + DEBUG_WM(DEBUG_DEV,F("WIFI station disconnect")); + return WiFi.disconnect(); // not persistent atm + #endif + return false; } // toggle STA without persistent -bool WiFiManager::WiFi_enableSTA(bool enable, bool persistent) -{ - DEBUG_WM(DEBUG_DEV, F("WiFi station enable")); -#ifdef ESP8266 - WiFiMode_t newMode; - WiFiMode_t currentMode = WiFi.getMode(); - bool isEnabled = (currentMode & WIFI_STA) != 0; - if (enable) - newMode = (WiFiMode_t)(currentMode | WIFI_STA); - else - newMode = (WiFiMode_t)(currentMode & (~WIFI_STA)); +bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) { + DEBUG_WM(DEBUG_DEV,F("WiFi station enable")); + #ifdef ESP8266 + WiFiMode_t newMode; + WiFiMode_t currentMode = WiFi.getMode(); + bool isEnabled = (currentMode & WIFI_STA) != 0; + if(enable) newMode = (WiFiMode_t)(currentMode | WIFI_STA); + else newMode = (WiFiMode_t)(currentMode & (~WIFI_STA)); - if ((isEnabled != enable) || persistent) - { - if (enable) - { - if (persistent) - DEBUG_WM(DEBUG_DEV, F("enableSTA PERSISTENT ON")); - return WiFi_Mode(newMode, persistent); - } - else - { - return WiFi_Mode(newMode, persistent); - } - } - else - { - return true; - } -#elif defined(ESP32) - bool ret; - if (persistent && esp32persistent) - WiFi.persistent(true); - ret = WiFi.enableSTA(enable); // @todo handle persistent when it is implemented in platform - if (persistent && esp32persistent) - WiFi.persistent(false); - return ret; -#endif + if((isEnabled != enable) || persistent) { + if(enable) { + if(persistent) DEBUG_WM(DEBUG_DEV,F("enableSTA PERSISTENT ON")); + return WiFi_Mode(newMode,persistent); + } else { + return WiFi_Mode(newMode,persistent); + } + } else { + return true; + } + #elif defined(ESP32) + bool ret; + if(persistent && esp32persistent) WiFi.persistent(true); + ret = WiFi.enableSTA(enable); // @todo handle persistent when it is implemented in platform + if(persistent && esp32persistent) WiFi.persistent(false); + return ret; + #endif } -bool WiFiManager::WiFi_enableSTA(bool enable) -{ - return WiFi_enableSTA(enable, false); +bool WiFiManager::WiFi_enableSTA(bool enable) { + return WiFi_enableSTA(enable,false); } -bool WiFiManager::WiFi_eraseConfig() -{ -#ifdef ESP8266 -#ifndef WM_FIXERASECONFIG - return ESP.eraseConfig(); -#else - // erase config BUG replacement - // https://github.com/esp8266/Arduino/pull/3635 - const size_t cfgSize = 0x4000; - size_t cfgAddr = ESP.getFlashChipSize() - cfgSize; +bool WiFiManager::WiFi_eraseConfig() { + #ifdef ESP8266 + #ifndef WM_FIXERASECONFIG + return ESP.eraseConfig(); + #else + // erase config BUG replacement + // https://github.com/esp8266/Arduino/pull/3635 + const size_t cfgSize = 0x4000; + size_t cfgAddr = ESP.getFlashChipSize() - cfgSize; - for (size_t offset = 0; offset < cfgSize; offset += SPI_FLASH_SEC_SIZE) - { - if (!ESP.flashEraseSector((cfgAddr + offset) / SPI_FLASH_SEC_SIZE)) - { - return false; - } - } - return true; -#endif -#elif defined(ESP32) - bool ret; - WiFi.mode(WIFI_AP_STA); // cannot erase if not in STA mode ! - WiFi.persistent(true); - ret = WiFi.disconnect(true, true); - WiFi.persistent(false); - return ret; -#endif + for (size_t offset = 0; offset < cfgSize; offset += SPI_FLASH_SEC_SIZE) { + if (!ESP.flashEraseSector((cfgAddr + offset) / SPI_FLASH_SEC_SIZE)) { + return false; + } + } + return true; + #endif + #elif defined(ESP32) + bool ret; + WiFi.mode(WIFI_AP_STA); // cannot erase if not in STA mode ! + WiFi.persistent(true); + ret = WiFi.disconnect(true,true); + WiFi.persistent(false); + return ret; + #endif } -uint8_t WiFiManager::WiFi_softap_num_stations() -{ -#ifdef ESP8266 - return wifi_softap_get_station_num(); -#elif defined(ESP32) - return WiFi.softAPgetStationNum(); -#endif +uint8_t WiFiManager::WiFi_softap_num_stations(){ + #ifdef ESP8266 + return wifi_softap_get_station_num(); + #elif defined(ESP32) + return WiFi.softAPgetStationNum(); + #endif } -bool WiFiManager::WiFi_hasAutoConnect() -{ +bool WiFiManager::WiFi_hasAutoConnect(){ return WiFi_SSID() != ""; } -String WiFiManager::WiFi_SSID() -{ -#ifdef ESP8266 - return WiFi.SSID(); -#elif defined(ESP32) - //@todo , workaround only when not connected - wifi_config_t conf; - esp_wifi_get_config(WIFI_IF_STA, &conf); - return String(reinterpret_cast(conf.sta.ssid)); -#endif +String WiFiManager::WiFi_SSID(){ + #ifdef ESP8266 + return WiFi.SSID(); + #elif defined(ESP32) + //@todo , workaround only when not connected + wifi_config_t conf; + esp_wifi_get_config(WIFI_IF_STA, &conf); + return String(reinterpret_cast(conf.sta.ssid)); + #endif } #ifdef ESP32 -void WiFiManager::WiFiEvent(WiFiEvent_t event, system_event_info_t info) -{ - DEBUG_WM(DEBUG_VERBOSE, "[EVENT]", event); - if (event == SYSTEM_EVENT_STA_DISCONNECTED) - { - DEBUG_WM(DEBUG_VERBOSE, "[EVENT] WIFI_REASON:", info.disconnected.reason); - if (info.disconnected.reason == WIFI_REASON_AUTH_EXPIRE || info.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(); - if (info.disconnected.reason == WIFI_REASON_NO_AP_FOUND) - DEBUG_WM(DEBUG_VERBOSE, "[EVENT] WIFI_REASON: NO_AP_FOUND"); -#ifdef esp32autoreconnect - DEBUG_WM(DEBUG_VERBOSE, "[Event] SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); - WiFi.reconnect(); -#endif +void WiFiManager::WiFiEvent(WiFiEvent_t event,system_event_info_t info){ + DEBUG_WM(DEBUG_VERBOSE,"[EVENT]",event); + if(event == SYSTEM_EVENT_STA_DISCONNECTED){ + DEBUG_WM(DEBUG_VERBOSE,"[EVENT] WIFI_REASON:",info.disconnected.reason); + if(info.disconnected.reason == WIFI_REASON_AUTH_EXPIRE || info.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(); + if(info.disconnected.reason == WIFI_REASON_NO_AP_FOUND) DEBUG_WM(DEBUG_VERBOSE,"[EVENT] WIFI_REASON: NO_AP_FOUND"); + #ifdef esp32autoreconnect + DEBUG_WM(DEBUG_VERBOSE,"[Event] SYSTEM_EVENT_STA_DISCONNECTED, reconnecting"); + WiFi.reconnect(); + #endif } - else if (event == SYSTEM_EVENT_SCAN_DONE) - { + else if(event == SYSTEM_EVENT_SCAN_DONE){ uint16_t scans = WiFi.scanComplete(); WiFi_scanComplete(scans); } } #endif -void WiFiManager::WiFi_autoReconnect() -{ -#ifdef ESP8266 - WiFi.setAutoReconnect(_wifiAutoReconnect); -#elif defined(ESP32) - // if(_wifiAutoReconnect){ - DEBUG_WM(DEBUG_VERBOSE, "ESP32 event handler enabled"); - using namespace std::placeholders; - WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent, this, _1, _2)); - // } -#endif +void WiFiManager::WiFi_autoReconnect(){ + #ifdef ESP8266 + WiFi.setAutoReconnect(_wifiAutoReconnect); + #elif defined(ESP32) + // if(_wifiAutoReconnect){ + DEBUG_WM(DEBUG_VERBOSE,"ESP32 event handler enabled"); + using namespace std::placeholders; + WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2)); + // } + #endif } From b4cc27cb56e6908f3a9cc28f4b8f3f04252e56dc Mon Sep 17 00:00:00 2001 From: Fernando Llaca Date: Sun, 2 Sep 2018 21:11:59 +0200 Subject: [PATCH 409/424] Added getParameters and getParametersCount methods. Useful for iterating over WiFiManager parameter list --- WiFiManager.cpp | 16 ++++++++++++++++ WiFiManager.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 2cb5dd4..4eb540b 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -150,6 +150,22 @@ bool WiFiManager::addParameter(WiFiManagerParameter *p) { return true; } +/** + * [getParameters description] + * @access public + */ +WiFiManagerParameter** WiFiManager::getParameters() { + return _params; +} + +/** + * [getParametersCount description] + * @access public + */ +int WiFiManager::getParametersCount() { + return _paramsCount; +} + /** * -------------------------------------------------------------------------------- * WiFiManager diff --git a/WiFiManager.h b/WiFiManager.h index 262189f..3fe03f3 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -198,6 +198,10 @@ class WiFiManager void setSaveConfigCallback( std::function func ); //adds a custom parameter, returns false on failure bool addParameter(WiFiManagerParameter *p); + //returns the list of Parameters + WiFiManagerParameter** getParameters(); + // returns the Parameters Count + int getParametersCount(); //if this is set, it will exit after config, even if connection is unsuccessful. void setBreakAfterConfig(boolean shouldBreak); // if this is set, portal will be blocking and wait until save or exit, From 448e079bc8584ce735504e1aa3538806f44b258b Mon Sep 17 00:00:00 2001 From: Fernando Llaca Date: Sun, 16 Sep 2018 22:49:40 +0200 Subject: [PATCH 410/424] Use a especific version of ArduinoJson --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ca2ba85..d41a13b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,7 @@ before_install: install: - ln -s $PWD /usr/local/share/arduino/libraries/WiFiManager - arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs - - arduino --install-library "ArduinoJson" + - arduino --install-library "ArduinoJson:5.13.2" - arduino --install-boards esp8266:esp8266 - arduino --pref "compiler.warning_level=all" --save-prefs # install esp32 From 12fc6516d2729a3ce1afb5b08d671066d15f3c89 Mon Sep 17 00:00:00 2001 From: Fernando Llaca Date: Sun, 16 Sep 2018 22:57:01 +0200 Subject: [PATCH 411/424] Missing semicolon --- examples/OnDemand/OnDemandWebPortal/onDemandWebPortal.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/OnDemand/OnDemandWebPortal/onDemandWebPortal.ino b/examples/OnDemand/OnDemandWebPortal/onDemandWebPortal.ino index 5850e40..d3cbe3f 100644 --- a/examples/OnDemand/OnDemandWebPortal/onDemandWebPortal.ino +++ b/examples/OnDemand/OnDemandWebPortal/onDemandWebPortal.ino @@ -31,7 +31,7 @@ void checkButton(){ // is configuration portal requested? if(digitalRead(TRIGGER_PIN) == LOW) { - delay(50) + delay(50); if(digitalRead(TRIGGER_PIN) == LOW) { if(!portalRunning){ Serial.println("Button Pressed, Starting Portal"); From 1c191c1d14674397bc7f89e8f85303fe459bb89d Mon Sep 17 00:00:00 2001 From: Fernando Llaca Date: Sun, 16 Sep 2018 23:08:23 +0200 Subject: [PATCH 412/424] Rename "Old Examples" folder to "Old_Examples", to avoid errors when iterating examples folder. --- .../AutoConnectWithFeedback/AutoConnectWithFeedback.ino | 0 .../AutoConnectWithReset/AutoConnectWithReset.ino | 0 .../AutoConnectWithStaticIP/AutoConnectWithStaticIP.ino | 0 .../AutoConnectWithTimeout/AutoConnectWithTimeout.ino | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename examples/{Old Examples => Old_examples}/AutoConnectWithFeedback/AutoConnectWithFeedback.ino (100%) rename examples/{Old Examples => Old_examples}/AutoConnectWithReset/AutoConnectWithReset.ino (100%) rename examples/{Old Examples => Old_examples}/AutoConnectWithStaticIP/AutoConnectWithStaticIP.ino (100%) rename examples/{Old Examples => Old_examples}/AutoConnectWithTimeout/AutoConnectWithTimeout.ino (100%) diff --git a/examples/Old Examples/AutoConnectWithFeedback/AutoConnectWithFeedback.ino b/examples/Old_examples/AutoConnectWithFeedback/AutoConnectWithFeedback.ino similarity index 100% rename from examples/Old Examples/AutoConnectWithFeedback/AutoConnectWithFeedback.ino rename to examples/Old_examples/AutoConnectWithFeedback/AutoConnectWithFeedback.ino diff --git a/examples/Old Examples/AutoConnectWithReset/AutoConnectWithReset.ino b/examples/Old_examples/AutoConnectWithReset/AutoConnectWithReset.ino similarity index 100% rename from examples/Old Examples/AutoConnectWithReset/AutoConnectWithReset.ino rename to examples/Old_examples/AutoConnectWithReset/AutoConnectWithReset.ino diff --git a/examples/Old Examples/AutoConnectWithStaticIP/AutoConnectWithStaticIP.ino b/examples/Old_examples/AutoConnectWithStaticIP/AutoConnectWithStaticIP.ino similarity index 100% rename from examples/Old Examples/AutoConnectWithStaticIP/AutoConnectWithStaticIP.ino rename to examples/Old_examples/AutoConnectWithStaticIP/AutoConnectWithStaticIP.ino diff --git a/examples/Old Examples/AutoConnectWithTimeout/AutoConnectWithTimeout.ino b/examples/Old_examples/AutoConnectWithTimeout/AutoConnectWithTimeout.ino similarity index 100% rename from examples/Old Examples/AutoConnectWithTimeout/AutoConnectWithTimeout.ino rename to examples/Old_examples/AutoConnectWithTimeout/AutoConnectWithTimeout.ino From c88df8631311beb49abae177205dd566d4706c40 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Mon, 17 Sep 2018 13:44:06 -0500 Subject: [PATCH 413/424] syntax error in examples --- examples/OnDemand/OnDemandWebPortal/onDemandWebPortal.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/OnDemand/OnDemandWebPortal/onDemandWebPortal.ino b/examples/OnDemand/OnDemandWebPortal/onDemandWebPortal.ino index 5850e40..d3cbe3f 100644 --- a/examples/OnDemand/OnDemandWebPortal/onDemandWebPortal.ino +++ b/examples/OnDemand/OnDemandWebPortal/onDemandWebPortal.ino @@ -31,7 +31,7 @@ void checkButton(){ // is configuration portal requested? if(digitalRead(TRIGGER_PIN) == LOW) { - delay(50) + delay(50); if(digitalRead(TRIGGER_PIN) == LOW) { if(!portalRunning){ Serial.println("Button Pressed, Starting Portal"); From 0cd0b75d9e132f591e0654bdf861768fe2be070e Mon Sep 17 00:00:00 2001 From: Shawn A Date: Tue, 18 Sep 2018 11:35:55 -0500 Subject: [PATCH 414/424] added custom html param example pattern --- examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 2677711..6f9a474 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -92,6 +92,7 @@ void setup() { WiFiManagerParameter custom_mqtt_port("port", "mqtt port", "", 6); WiFiManagerParameter custom_token("api_token", "api token", "", 16); WiFiManagerParameter custom_tokenb("invalid token", "invalid token", "", 0); + WiFiManagerParameter custom_ipaddress("input_ip", "input IP", "", 19,"pattern='\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'"); // callbacks wm.setSaveConfigCallback(saveCallback); @@ -102,6 +103,7 @@ void setup() { wm.addParameter(&custom_mqtt_port); wm.addParameter(&custom_token); wm.addParameter(&custom_tokenb); + wm.addParameter(&custom_ipaddress); custom_html.setValue("test",4); custom_token.setValue("test",4); From 0e4af48d549fa67f191ab886610e9fd2016d9cc9 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 19 Sep 2018 09:54:17 -0500 Subject: [PATCH 415/424] fix example --- examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 6f9a474..296f639 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -91,8 +91,8 @@ void setup() { WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40); WiFiManagerParameter custom_mqtt_port("port", "mqtt port", "", 6); WiFiManagerParameter custom_token("api_token", "api token", "", 16); - WiFiManagerParameter custom_tokenb("invalid token", "invalid token", "", 0); - WiFiManagerParameter custom_ipaddress("input_ip", "input IP", "", 19,"pattern='\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'"); + WiFiManagerParameter custom_tokenb("invalid token", "invalid token", "", 0); // id is invalid, cannot contain spaces + WiFiManagerParameter custom_ipaddress("input_ip", "input IP", "", 15,"pattern='\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'"); // callbacks wm.setSaveConfigCallback(saveCallback); From aad1a8d9d2492d1e5e80596b17bc206d66b70a64 Mon Sep 17 00:00:00 2001 From: Dontsov Evgeny Date: Sun, 23 Sep 2018 23:19:17 +0300 Subject: [PATCH 416/424] WiFiManagerParameter init() to protected --- WiFiManager.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/WiFiManager.h b/WiFiManager.h index 262189f..2d92247 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -118,6 +118,11 @@ class WiFiManagerParameter { int getLabelPlacement(); const char *getCustomHTML(); void setValue(const char *defaultValue, int length); + + protected: + void init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom); + void init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement); + private: const char *_id; const char *_placeholder; @@ -126,9 +131,6 @@ class WiFiManagerParameter { int _labelPlacement; const char *_customHTML; - void init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom); - void init(const char *id, const char *placeholder, const char *defaultValue, int length, const char *custom, int labelPlacement); - friend class WiFiManager; }; From dbf91a4e8cbe82b1cc42c94ad85436930cf5b052 Mon Sep 17 00:00:00 2001 From: Dontsov Evgeny Date: Mon, 24 Sep 2018 03:28:03 +0300 Subject: [PATCH 417/424] example: custom paramaters with load/save settings --- .../CustomParamsWithConfig.ino | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 examples/CustomParamsWithConfig/CustomParamsWithConfig.ino diff --git a/examples/CustomParamsWithConfig/CustomParamsWithConfig.ino b/examples/CustomParamsWithConfig/CustomParamsWithConfig.ino new file mode 100644 index 0000000..51e4519 --- /dev/null +++ b/examples/CustomParamsWithConfig/CustomParamsWithConfig.ino @@ -0,0 +1,138 @@ + +#include // https://github.com/tzapu/WiFiManager +#include +#include + +#define SETUP_PIN 0 + +class IPAddressParameter : public WiFiManagerParameter { +public: + IPAddressParameter(const char *id, const char *placeholder, IPAddress address) + : WiFiManagerParameter("") { + init(id, placeholder, address.toString().c_str(), 16, "", WFM_LABEL_BEFORE); + } + + bool getValue(IPAddress &ip) { + return ip.fromString(WiFiManagerParameter::getValue()); + } +}; + +class IntParameter : public WiFiManagerParameter { +public: + IntParameter(const char *id, const char *placeholder, long value, const uint8_t length = 10) + : WiFiManagerParameter("") { + init(id, placeholder, String(value).c_str(), length, "", WFM_LABEL_BEFORE); + } + + long getValue() { + return String(WiFiManagerParameter::getValue()).toInt(); + } +}; + +class FloatParameter : public WiFiManagerParameter { +public: + FloatParameter(const char *id, const char *placeholder, float value, const uint8_t length = 10) + : WiFiManagerParameter("") { + init(id, placeholder, String(value).c_str(), length, "", WFM_LABEL_BEFORE); + } + + float getValue() { + return String(WiFiManagerParameter::getValue()).toFloat(); + } +}; + +struct Settings { + float f; + int i; + char s[20]; + uint32_t ip; +} sett; + + +void setup() { + pinMode(SETUP_PIN, INPUT_PULLUP); + Serial.begin(9600); + + //Delay to push SETUP button + Serial.println("Press setup button"); + for (int sec = 3; sec > 0; sec--) { + Serial.print(sec); + Serial.print(".."); + delay(1000); + } + + EEPROM.begin( 512 ); + EEPROM.get(0, sett); + Serial.println("Settings loaded"); + + if (digitalRead(SETUP_PIN) == LOW) { + // Button pressed + Serial.println("SETUP"); + + WiFiManager wm; + + sett.s[19] = '\0'; //add null terminator at the end cause overflow + WiFiManagerParameter param_str( "str", "param_string", sett.s, 20); + FloatParameter param_float( "float", "param_float", sett.f); + IntParameter param_int( "int", "param_int", sett.i); + + IPAddress ip(sett.ip); + IPAddressParameter param_ip("ip", "param_ip", ip); + + wm.addParameter( ¶m_str ); + wm.addParameter( ¶m_float ); + wm.addParameter( ¶m_int ); + wm.addParameter( ¶m_ip ); + + //SSID & password parameters already included + wm.startConfigPortal(); + + strncpy(sett.s, param_str.getValue(), 20); + sett.s[19] = '\0'; + sett.f = param_float.getValue(); + sett.i = param_int.getValue(); + + Serial.print("String param: "); + Serial.println(sett.s); + Serial.print("Float param: "); + Serial.println(sett.f); + Serial.print("Int param: "); + Serial.println(sett.i, DEC); + + if (param_ip.getValue(ip)) { + sett.ip = ip; + + Serial.print("IP param: "); + Serial.println(ip); + } else { + Serial.println("Incorrect IP"); + } + + EEPROM.put(0, sett); + if (EEPROM.commit()) { + Serial.println("Settings saved"); + } else { + Serial.println("EEPROM error"); + } + } + else { + Serial.println("WORK"); + + //connect to saved SSID + WiFi.begin(); + + //do smth + Serial.print("String param: "); + Serial.println(sett.s); + Serial.print("Float param: "); + Serial.println(sett.f); + Serial.print("Int param: "); + Serial.println(sett.i, DEC); + Serial.print("IP param: "); + IPAddress ip(sett.ip); + Serial.println(ip); + } +} + +void loop() { +} From 85b2319b593a69eb49a0e4c96aefb9a0cc812f02 Mon Sep 17 00:00:00 2001 From: Dontsov Evgeny Date: Mon, 24 Sep 2018 03:45:49 +0300 Subject: [PATCH 418/424] correct your idea about deflength --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 7eef612..9b083da 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -71,7 +71,7 @@ void WiFiManagerParameter::setValue(const char *defaultValue, int length) { int deflength = strlen(defaultValue); // length actual // use the defult length if it's longer, // @todo consider it might be useful to fail, so user knows they were wrong - if(_length < length){ + if(_length < deflength){ // Serial.println("defaultValue length mismatch"); _length = deflength; } From 7d42423894e3006978d8f7d1ab1b2107a446190b Mon Sep 17 00:00:00 2001 From: Dontsov Evgeny Date: Mon, 24 Sep 2018 04:19:21 +0300 Subject: [PATCH 419/424] value limit is length --- WiFiManager.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 9b083da..365eb4f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -68,20 +68,11 @@ void WiFiManagerParameter::setValue(const char *defaultValue, int length) { return; } _length = length; - int deflength = strlen(defaultValue); // length actual - // use the defult length if it's longer, - // @todo consider it might be useful to fail, so user knows they were wrong - if(_length < deflength){ - // Serial.println("defaultValue length mismatch"); - _length = deflength; - } - _value = new char[_length + 1]; - for (int i = 0; i < _length + 1; i++) { - _value[i] = 0; - } + _value = new char[_length + 1]; + memset(_value, 0, _length + 1); // explicit null + if (defaultValue != NULL) { strncpy(_value, defaultValue, _length); - _value[_length] = '\0'; // explicit null } } const char* WiFiManagerParameter::getValue() { From 613ec354bdf5eeeb702e4bcb7bb97d43597a26e2 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 26 Sep 2018 09:44:59 -0500 Subject: [PATCH 420/424] param defvalue mismatch checking --- WiFiManager.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 365eb4f..f0ad474 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -62,13 +62,20 @@ WiFiManagerParameter::~WiFiManagerParameter() { _length=0; // setting length 0, ideally the entire parameter should be removed, or added to wifimanager scope so it follows } +// @note debug is not available in wmparameter class void WiFiManagerParameter::setValue(const char *defaultValue, int length) { if(!_id){ // Serial.println("cannot set value of this parameter"); return; } - _length = length; - _value = new char[_length + 1]; + + // if(strlen(defaultValue) > length){ + // // Serial.println("defaultValue length mismatch"); + // // return false; //@todo bail + // } + + _length = length; + _value = new char[_length + 1]; memset(_value, 0, _length + 1); // explicit null if (defaultValue != NULL) { From 193fdf177c3c52115b6f40027457d8399967d932 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 26 Sep 2018 09:45:03 -0500 Subject: [PATCH 421/424] fix example --- examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 296f639..e8be11b 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -92,7 +92,7 @@ void setup() { WiFiManagerParameter custom_mqtt_port("port", "mqtt port", "", 6); WiFiManagerParameter custom_token("api_token", "api token", "", 16); WiFiManagerParameter custom_tokenb("invalid token", "invalid token", "", 0); // id is invalid, cannot contain spaces - WiFiManagerParameter custom_ipaddress("input_ip", "input IP", "", 15,"pattern='\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'"); + WiFiManagerParameter custom_ipaddress("input_ip", "input IP", "", 15,"pattern='\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}'"); // callbacks wm.setSaveConfigCallback(saveCallback); From fe772f6bf5568e5717e4b4955dcfb2ad4dd996cb Mon Sep 17 00:00:00 2001 From: Shawn A Date: Wed, 26 Sep 2018 09:47:59 -0500 Subject: [PATCH 422/424] fix example --- examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino b/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino index 9d283ec..ef8e1eb 100644 --- a/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino +++ b/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino @@ -48,6 +48,7 @@ void doWiFiManager(){ if(digitalRead(TRIGGER_PIN) == LOW && (!portalRunning)) { if(startCP){ Serial.println("Button Pressed, Starting Config Portal"); + wm.setConfigPortalBlocking(false); wm.startConfigPortal(); } else{ From 8e7b43a02948febdb5acebb1b224015cfd847687 Mon Sep 17 00:00:00 2001 From: Shawn A Date: Thu, 27 Sep 2018 13:39:12 -0500 Subject: [PATCH 423/424] rename example --- .../ParamsChildClass.ino} | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) rename examples/{CustomParamsWithConfig/CustomParamsWithConfig.ino => ParamsChildClass/ParamsChildClass.ino} (98%) diff --git a/examples/CustomParamsWithConfig/CustomParamsWithConfig.ino b/examples/ParamsChildClass/ParamsChildClass.ino similarity index 98% rename from examples/CustomParamsWithConfig/CustomParamsWithConfig.ino rename to examples/ParamsChildClass/ParamsChildClass.ino index 51e4519..c5d991a 100644 --- a/examples/CustomParamsWithConfig/CustomParamsWithConfig.ino +++ b/examples/ParamsChildClass/ParamsChildClass.ino @@ -1,4 +1,6 @@ - +/** + * WiFiManagerParameter child class example + */ #include // https://github.com/tzapu/WiFiManager #include #include From 669dad42064dd88c506fc8a9394b3b2583953850 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Mon, 1 Oct 2018 12:28:37 -0500 Subject: [PATCH 424/424] starting readme updates --- README.md | 56 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1f355a2..e4c3857 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,9 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are - [Wishlist](#wishlist) - [Quick start](#quick-start) - Installing - - [Through Library Manager](#install-through-library-manager) - - [From Github](#checkout-from-github) + - [Arduino - Through Library Manager](#install-through-library-manager) + - [Arduino - From Github](#checkout-from-github) + - [PlatformIO] - [Using](#using) - [Documentation](#documentation) - [Access Point Password](#password-protect-the-configuration-access-point) @@ -46,12 +47,13 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are ## How It Works -- when your ESP starts up, it sets it up in Station mode and tries to connect to a previously saved Access Point +- When your ESP starts up, it sets it up in Station mode and tries to connect to a previously saved Access Point - if this is unsuccessful (or no previous network saved) it moves the ESP into Access Point mode and spins up a DNS and WebServer (default ip 192.168.4.1) - using any wifi enabled device with a browser (computer, phone, tablet) connect to the newly created Access Point - because of the Captive Portal and the DNS server you will either get a 'Join to network' type of popup or get any domain you try to access redirected to the configuration portal - choose one of the access points scanned, enter password, click save - ESP will try to connect. If successful, it relinquishes control back to your app. If not, reconnect to AP and reconfigure. +- There are options to change this behavior or manually start the configportal and webportal independantly as well as run them in non blocking mode. ## How It Looks ![ESP8266 WiFi Captive Portal Homepage](http://i.imgur.com/YPvW9eql.png) ![ESP8266 WiFi Captive Portal Configuration](http://i.imgur.com/oicWJ4gl.png) @@ -67,9 +69,35 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are - [x] add to PlatformIO - [ ] add multiple sets of network credentials - [x] allow users to customize CSS -- [ ] ESP32 support or instructions - [ ] rewrite documentation for simplicity, based on scenarios/goals -- [ ] rely on the SDK's built in auto connect more than forcing a connect + +### Development +- [x] ESP32 support +- [x] rely on the SDK's built in auto connect more than forcing a connect +- [x] add non blocking mode +- [x] easy customization of strings +- [x] hostname support +- [x] fix various bugs and workarounds for esp SDK issues +- [x] additional info page items +- [x] last status display / faiilure reason +- [x] customizeable menu +- [x] seperate custom params page +- [x] ondemand webportal +- [x] complete refactor of code to segment functions +- [x] wiif scan icons or percentage display +- [x] invert class for dark mode +- [x] more template tokens +- [x] progmem for all strings +- [ ] new callbacks +- [ ] new callouts / filters +- [ ] shared web server instance +- [x] latest esp idf/sdk support +- [x] wm is now non persistent, will not erase or change stored esp config on esp8266 +- [x] tons of debugging output / levels +- [ ] disable captiveportal +- [ ] preload wiifscans, faster page loads +- [ ] softap stability fixes when sta is not connected + ## Quick Start @@ -93,14 +121,10 @@ __Github version works with release 2.4.0 or newer of the [ESP8266 core for Ardu ### Using - Include in your sketch ```cpp -#include //ESP8266 Core WiFi Library (you most likely already have this in your sketch) - -#include //Local DNS Server used for redirecting all requests to the configuration portal -#include //Local WebServer used to serve the configuration portal #include //https://github.com/tzapu/WiFiManager WiFi Configuration Magic ``` -- Initialize library, in your setup function add +- Initialize library, in your setup function add, NOTEif you are using non blocking you will make sure you create this in global scope or handle appropriatly , it will not work if in setup and using non blocking mode. ```cpp WiFiManager wifiManager; ``` @@ -284,6 +308,14 @@ Debug is enabled by default on Serial. To disable add before autoConnect wifiManager.setDebugOutput(false); ``` +You can customize the debug level by changing `_debugLevel` in source +options are: +* DEBUG_ERROR +* DEBUG_NOTIFY +* DEBUG_VERBOSE +* DEBUG_DEV +* DEBUG_MAX + ## Troubleshooting If you get compilation errors, more often than not, you may need to install a newer version of the ESP8266 core for Arduino. @@ -296,6 +328,8 @@ If you connect to the created configuration Access Point but the configuration p If trying to connect ends up in an endless loop, try to add `setConnectTimeout(60)` before `autoConnect();`. The parameter is timeout to try connecting in seconds. ## Releases +#### 1.0.1 + #### 0.12 - removed 204 header response - fixed incompatibility with other libs using isnan and other std:: functions without namespace @@ -360,7 +394,7 @@ The support and help I got from the community has been nothing short of phenomen __THANK YOU__ -[Shawn A](https://github.com/tablatronix) +[Shawn A aka tablatronix](https://github.com/tablatronix) [bbx10](https://github.com/bbx10)