From 725f824e5842b13e53ce5e13a5cad401d2c1549e Mon Sep 17 00:00:00 2001 From: Iulian Onofrei <6d0847b9@opayq.com> Date: Sun, 19 Jan 2020 18:35:06 +0200 Subject: [PATCH 1/7] Add missing line to code sample --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e28d960..6acf010 100644 --- a/README.md +++ b/README.md @@ -309,6 +309,7 @@ wifiManager.addParameter(&custom_text); Just add the bit you want added as the last parameter to the custom parameter constructor. ```cpp WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "iot.eclipse", 40, " readonly"); +wifiManager.addParameter(&custom_mqtt_server); ``` #### Theming From 87009dc443923721f5449e363e9aaac02da819f9 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Wed, 22 Jan 2020 10:42:08 -0600 Subject: [PATCH 2/7] fixes #987 --- WiFiManager.cpp | 9 ++++----- WiFiManager.h | 1 + .../DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index ce72e44..1ecc949 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2350,7 +2350,7 @@ void WiFiManager::setMenu(const char * menu[], uint8_t size){ } } } - // DEBUG_WM(getMenuOut()); + DEBUG_WM(getMenuOut()); } /** @@ -2373,7 +2373,7 @@ void WiFiManager::setMenu(std::vector& menu){ } } } - // DEBUG_WM(getMenuOut()); + DEBUG_WM(getMenuOut()); } @@ -2384,9 +2384,8 @@ void WiFiManager::setMenu(std::vector& menu){ * @since $dev */ void WiFiManager::setParamsPage(bool enable){ - _paramsInWifi= false; - _menuIdsDefault = {"wifi","param","info","exit"}; - setMenu(_menuIdsDefault); + _paramsInWifi = !enable; + setMenu(enable ? _menuIdsParams : _menuIdsDefault); } // GETTERS diff --git a/WiFiManager.h b/WiFiManager.h index 9691135..97f6784 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -307,6 +307,7 @@ class WiFiManager private: std::vector _menuIds; + std::vector _menuIdsParams = {"wifi","param","info","exit"}; std::vector _menuIdsDefault = {"wifi","info","exit"}; // ip configs @todo struct ? diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 58f5e9e..34c4d75 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -173,9 +173,9 @@ void setup() { // wm.setMenu(menu,9); // custom menu array must provide length std::vector menu = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"}; - wm.setMenu(menu); // custom menu, pass vector + // wm.setMenu(menu); // custom menu, pass vector - // wm.setParamsPage(true); // move params to seperate page, not wifi, do not combine with setmenu! + wm.setParamsPage(true); // move params to seperate page, not wifi, do not combine with setmenu! // set static sta ip // wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); @@ -244,6 +244,7 @@ void loop() { if ( digitalRead(TRIGGER_PIN) == LOW ){ Serial.println("BUTTON PRESSED"); wm.setConfigPortalTimeout(140); + wm.setParamsPage(false); // move params to seperate page, not wifi, do not combine with setmenu! // disable captive portal redirection // wm.setCaptivePortalEnable(false); From f7d4c166aec495ebcb4a280c530c27a4c7944a72 Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 18 Feb 2020 11:02:56 +0100 Subject: [PATCH 3/7] Update WiFiManager.cpp Fixed bug where, after clicking "Save", it would display an empty page to the user, instead of the wifi save page. (due to local variable) --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 1ecc949..885cb02 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1366,7 +1366,7 @@ void WiFiManager::handleWifiSave() { page += FPSTR(HTTP_PARAMSAVED); } else { - String page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved + page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved page += FPSTR(HTTP_SAVED); } page += FPSTR(HTTP_END); From bdb1ab3c32bdadd29ff472b9d0d716b4282b3892 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 18 Feb 2020 13:31:40 -0600 Subject: [PATCH 4/7] comments, dev example tests --- WiFiManager.cpp | 3 ++- .../OnDemandConfigPortal/OnDemandConfigPortal.ino | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 1ecc949..4a90985 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1446,6 +1446,7 @@ void WiFiManager::handleInfo() { uint16_t infos = 0; //@todo convert to enum or refactor to strings + //@todo wrap in build flag to remove all info code for memory saving #ifdef ESP8266 infos = 27; String infoids[] = { @@ -1524,7 +1525,7 @@ void WiFiManager::handleInfo() { String WiFiManager::getInfoData(String id){ String p; - // @todo add versioning + // @todo add WM 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")){ diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 34c4d75..44525f7 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -72,6 +72,7 @@ WiFiManager wm; // OPTION FLAGS bool TEST_CP = true; // always start the configportal, even if ap found bool TEST_NET = true; // do a network test after connect, (gets ntp time) +bool ALLOWONDEMAND = false; // char ssid[] = "*************"; // your network SSID (name) // char pass[] = "********"; // your network password @@ -208,7 +209,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 - + wifiInfo(); print_oled(F("Connecting..."),2); if(!wm.autoConnect("WM_AutoConnectAP")) { Serial.println("failed to connect and hit timeout"); @@ -226,6 +227,8 @@ void setup() { Serial.println("connected...yeey :)"); print_oled("Connected\nIP: " + WiFi.localIP().toString() + "\nSSID: " + WiFi.SSID(),1); } + + wifiInfo(); pinMode(TRIGGER_PIN, INPUT); #ifdef USEOTA @@ -233,13 +236,20 @@ void setup() { #endif } +void wifiInfo(){ + WiFi.printDiag(Serial); + Serial.println("SAVED: " + (String)wm.getWiFiIsSaved() ? "YES" : "NO"); + Serial.println("SSID: " + (String)wm.getWiFiSSID()); + Serial.println("PASS: " + (String)wm.getWiFiPass()); +} + void loop() { #ifdef USEOTA ArduinoOTA.handle(); #endif // is configuration portal requested? - if ( digitalRead(TRIGGER_PIN) == LOW ) { + if (ALLOWONDEMAND && digitalRead(TRIGGER_PIN) == LOW ) { delay(100); if ( digitalRead(TRIGGER_PIN) == LOW ){ Serial.println("BUTTON PRESSED"); From decd2942c5386f388a8f37535035cb8a9ed2a34f Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 18 Feb 2020 15:09:42 -0600 Subject: [PATCH 5/7] fix param out of scope check in doparamsave --- WiFiManager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index f4872d3..f8f0e6a 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1408,8 +1408,10 @@ void WiFiManager::doParamSave(){ 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 (_params[i] == NULL || _params[i]->_length == 0) { + DEBUG_WM(DEBUG_ERROR,"[ERROR] WiFiManagerParameter is out of scope"); break; // @todo might not be needed anymore } //read parameter from server From b61bc261bf96df08bc8d7eb515f93b7f9b3c0d18 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 18 Feb 2020 16:14:45 -0600 Subject: [PATCH 6/7] disable clean connect, OPTIONAL setter setCleanConnect(bool enable); // default false This was originally intended to improve connection stability, but it is now causing problems , this is now disabled and can be reenabled optionally. Possible race condition diconnecting while auto connecting or async setmode delays --- WiFiManager.cpp | 12 ++++++++++-- WiFiManager.h | 6 ++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index f8f0e6a..9012356 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -725,6 +725,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 !) + 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 @@ -812,7 +813,7 @@ bool WiFiManager::wifiConnectDefault(){ * @return bool success */ bool WiFiManager::setSTAConfig(){ - DEBUG_WM(F("STA static IP:"),_sta_static_ip); + DEBUG_WM(DEBUG_DEV,F("STA static IP:"),_sta_static_ip); bool ret = true; if (_sta_static_ip) { DEBUG_WM(DEBUG_VERBOSE,F("Custom static IP/GW/Subnet/DNS")); @@ -828,7 +829,7 @@ 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")); + DEBUG_WM(DEBUG_VERBOSE,F("setSTAConfig static ip not set, skipping")); } return ret; } @@ -2009,6 +2010,13 @@ void WiFiManager::setConfigPortalTimeout(unsigned long seconds) { void WiFiManager::setConnectTimeout(unsigned long seconds) { _connectTimeout = seconds * 1000; } +/** + * toggle _cleanconnect, always disconnect before connecting + * @param {[type]} bool enable [description] + */ +void WiFiManager::setCleanConnect(bool enable){ + _cleanConnect = enable; +} /** * [setConnectTimeout description diff --git a/WiFiManager.h b/WiFiManager.h index 97f6784..0a73eda 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -261,8 +261,10 @@ class WiFiManager void setWiFiAPChannel(int32_t channel); // set ap hidden void setWiFiAPHidden(bool hidden); // default false - // set custom menu + // clean connect, always disconnect before connecting + void setCleanConnect(bool enable); // default false + // set custom menu // set custom menu items and order void setMenu(std::vector& menu); void setMenu(const char* menu[], uint8_t size); @@ -340,7 +342,7 @@ class WiFiManager 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 + bool _cleanConnect = false; // 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 ) From 89fcfe9680c843f33d3d685f19591fde1f636c26 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 18 Feb 2020 16:25:17 -0600 Subject: [PATCH 7/7] adds to dev example --- .../OnDemandConfigPortal.ino | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 44525f7..91d203d 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -72,7 +72,7 @@ WiFiManager wm; // OPTION FLAGS bool TEST_CP = true; // always start the configportal, even if ap found bool TEST_NET = true; // do a network test after connect, (gets ntp time) -bool ALLOWONDEMAND = false; +bool ALLOWONDEMAND = true; // char ssid[] = "*************"; // your network SSID (name) // char pass[] = "********"; // your network password @@ -134,13 +134,6 @@ void setup() { 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(600); - // wm.setConnectTimeout(5); - // wm.setShowStaticFields(true); - WiFiManagerParameter custom_html("

This Is Custom HTML

"); // only custom html WiFiManagerParameter custom_mqtt_server("server", "mqtt server", "", 40); WiFiManagerParameter custom_mqtt_port("port", "mqtt port", "", 6); @@ -199,10 +192,17 @@ void setup() { // show password publicly! // wm.setShowPassword(true); - // set configrportal timeout - wm.setConfigPortalTimeout(120); + //sets timeout until configuration portal gets turned off + //useful to make it all retry or go to sleep in seconds + wm.setConfigPortalTimeout(120); + + // wm.setConnectTimeout(20); + // wm.setShowStaticFields(true); + // wm.startConfigPortal("AutoConnectAP", "password"); - + + // wm.setCleanConnect(true); // disconenct before connect, clean connect + // wm.setBreakAfterConfig(true); //fetches ssid and pass and tries to connect @@ -229,7 +229,7 @@ void setup() { } wifiInfo(); - pinMode(TRIGGER_PIN, INPUT); + pinMode(TRIGGER_PIN, INPUT_PULLUP); #ifdef USEOTA ArduinoOTA.begin();