From f7d4c166aec495ebcb4a280c530c27a4c7944a72 Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 18 Feb 2020 11:02:56 +0100 Subject: [PATCH 01/40] 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 02/40] 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 03/40] 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 04/40] 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 05/40] 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(); From 3f93afe9c2924fc7da42f301f639045b258e32d5 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 25 Feb 2020 16:31:45 -0600 Subject: [PATCH 06/40] change debug saves logs --- WiFiManager.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 9012356..42336bd 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -619,7 +619,7 @@ uint8_t WiFiManager::processConfigPortal(){ // Waiting for save... if(connect) { connect = false; - DEBUG_WM(DEBUG_VERBOSE,F("process connect")); + DEBUG_WM(DEBUG_VERBOSE,F("processing save")); if(_enableCaptivePortal) delay(_cpclosedelay); // keeps the captiveportal from closing to fast. // skip wifi if no ssid @@ -644,10 +644,12 @@ uint8_t WiFiManager::processConfigPortal(){ } 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 ( _savewificallback != NULL) { + DEBUG_WM(DEBUG_VERBOSE,F("WiFi/Param save callback")); _savewificallback(); } shutdownConfigPortal(); @@ -746,7 +748,7 @@ uint8_t WiFiManager::connectWifi(String ssid, String pass) { connRes = waitForConnectResult(); } else { - DEBUG_WM(F("No saved credentials, skipping wifi")); + DEBUG_WM(F("No wifi save required, skipping")); } } From 4a98ba0e29606c684e66fa80e53f1293a269540b Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 27 Feb 2020 11:34:31 -0600 Subject: [PATCH 07/40] Update OnDemandConfigPortal.ino --- examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 91d203d..9579882 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -169,7 +169,7 @@ void setup() { std::vector menu = {"wifi","wifinoscan","info","param","close","sep","erase","restart","exit"}; // 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)); @@ -203,7 +203,7 @@ void setup() { // wm.setCleanConnect(true); // disconenct before connect, clean connect - // wm.setBreakAfterConfig(true); + wm.setBreakAfterConfig(true); //fetches ssid and pass and tries to connect //if it does not connect it starts an access point with the specified name @@ -211,7 +211,7 @@ void setup() { //and goes into a blocking loop awaiting configuration wifiInfo(); print_oled(F("Connecting..."),2); - if(!wm.autoConnect("WM_AutoConnectAP")) { + if(!wm.autoConnect("WM_AutoConnectAP","12345678")) { Serial.println("failed to connect and hit timeout"); print_oled("Not Connected",2); } From 6c08094e41b1160dabd0e15d207d8890dc3d4bac Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 13 Mar 2020 11:35:04 -0500 Subject: [PATCH 08/40] Skip autoconnect when there are no creds saved --- WiFiManager.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 42336bd..c5f9fd6 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -245,6 +245,8 @@ boolean WiFiManager::autoConnect() { */ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { DEBUG_WM(F("AutoConnect")); + if(getWiFiIsSaved()){ + _begin(); // attempt to connect using saved settings, on fail fallback to AP config portal @@ -333,6 +335,8 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { } DEBUG_WM(F("AutoConnect: FAILED")); + } + else DEBUG_WM(F("No Credentials are Saved, skipping connect")); // not connected start configportal return startConfigPortal(apName, apPassword); @@ -1969,7 +1973,7 @@ bool WiFiManager::erase(bool opt){ * @access public */ void WiFiManager::resetSettings() { - DEBUG_WM(F("SETTINGS ERASED")); + DEBUG_WM(F("resetSettings")); WiFi_enableSTA(true,true); // must be sta to disconnect erase if (_resetcallback != NULL) @@ -1981,7 +1985,8 @@ void WiFiManager::resetSettings() { WiFi.persistent(true); WiFi.disconnect(true); WiFi.persistent(false); - #endif + #endif + DEBUG_WM(F("SETTINGS ERASED")); } // SETTERS From 709cfffb95b87868f92941442d71973ef32002fd Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 7 Apr 2020 11:42:01 -0500 Subject: [PATCH 09/40] adds embedded logo example --- WiFiManager.cpp | 2 +- strings_en.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index c5f9fd6..930baf2 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -943,7 +943,7 @@ 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 page = getHTTPHead(FPSTR(S_options)); // @token options @todo replace options with title 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; diff --git a/strings_en.h b/strings_en.h index bce2ebd..2560ff0 100644 --- a/strings_en.h +++ b/strings_en.h @@ -25,7 +25,8 @@ const char HTTP_SCRIPT[] PROGMEM = ""; const char HTTP_HEAD_END[] PROGMEM = "
"; - +// example of embedded logo, base64 encoded inline, No styling here +// const char HTTP_ROOT_MAIN[] PROGMEM = "

{v}

WiFiManager

"; const char HTTP_ROOT_MAIN[] PROGMEM = "

{v}

WiFiManager

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

\n", // MENU_WIFI From e9d75a08b8ad59508a70441fad1cbba90ec0dcaf Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 10 Apr 2020 10:06:11 -0500 Subject: [PATCH 10/40] Disables usermode restore I may add optionals later for this, right now sta mode is the default, and sta mode will always be the only mode on after using WM, if you were using ap mode you have to turn it back on yourself until I have a better solution or documentation. --- WiFiManager.cpp | 4 ++-- WiFiManager.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 930baf2..f923d47 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -216,7 +216,7 @@ WiFiManager::~WiFiManager() { void WiFiManager::_begin(){ if(_hasBegun) return; _hasBegun = true; - _usermode = WiFi.getMode(); + // _usermode = WiFi.getMode(); #ifndef ESP32 WiFi.persistent(false); // disable persistent so scannetworks and mode switching do not cause overwrites @@ -262,7 +262,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { if(esp32persistent) WiFi.persistent(false); // disable persistent for esp32 after esp_wifi_start or else saves wont work #endif - _usermode = WIFI_STA; + _usermode = WIFI_STA; // When using autoconnect , assume the user wants sta mode on permanently. // no getter for autoreconnectpolicy before this // https://github.com/esp8266/Arduino/pull/4359 diff --git a/WiFiManager.h b/WiFiManager.h index 0a73eda..7ad1628 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -335,7 +335,7 @@ class WiFiManager unsigned long _saveTimeout = 0; // ms stop trying to connect to ap on saves, in case bugs in esp waitforconnectresult 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; + WiFiMode_t _usermode = WIFI_STA; // Default user mode String _wifissidprefix = FPSTR(S_ssidpre); // auto apname prefix prefix+chipid uint8_t _lastconxresult = WL_IDLE_STATUS; int _numNetworks = 0; From 293f705b0ff29f5c78443a1f181a9872875aeac6 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Sun, 19 Apr 2020 00:53:18 -0500 Subject: [PATCH 11/40] #1039 --- WiFiManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index f923d47..3c6675d 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1941,7 +1941,6 @@ bool WiFiManager::erase(bool opt){ // 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"); From 5aebb1dd518de533780f1cb2fbbcab64a0040d8e Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 8 May 2020 23:31:02 -0500 Subject: [PATCH 12/40] Some hostname testing --- WiFiManager.cpp | 172 ++++++++++-------- WiFiManager.h | 3 +- .../onDemandNonBlocking.ino | 17 ++ examples/Tests/AnonymousCB.ino | 24 +++ 4 files changed, 135 insertions(+), 81 deletions(-) create mode 100644 examples/Tests/AnonymousCB.ino diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 3c6675d..6482ec8 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -247,99 +247,111 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { DEBUG_WM(F("AutoConnect")); if(getWiFiIsSaved()){ - _begin(); + _begin(); - // attempt to connect using saved settings, on fail fallback to AP config portal - if(!WiFi.enableSTA(true)){ - // handle failure mode Brownout detector etc. - DEBUG_WM(DEBUG_ERROR,"[FATAL] Unable to enable wifi!"); - return false; - } - - WiFiSetCountry(); + // attempt to connect using saved settings, on fail fallback to AP config portal + if(!WiFi.enableSTA(true)){ + // handle failure mode Brownout detector etc. + 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 - - _usermode = WIFI_STA; // When using autoconnect , assume the user wants sta mode on permanently. - - // no getter for autoreconnectpolicy before this - // https://github.com/esp8266/Arduino/pull/4359 - // so we must force it on else, if not connectimeout then waitforconnectionresult gets stuck endless loop - WiFi_autoReconnect(); - - // set hostname before stating - 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 + #ifdef ESP32 + if(esp32persistent) WiFi.persistent(false); // disable persistent for esp32 after esp_wifi_start or else saves wont work #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 - // @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){ - connected = true; - DEBUG_WM(F("AutoConnect: ESP Already Connected")); - setSTAConfig(); - } + _usermode = WIFI_STA; // When using autoconnect , assume the user wants sta mode on permanently. - if(connected || connectWifi("", "") == WL_CONNECTED){ - //connected - DEBUG_WM(F("AutoConnect: SUCCESS")); - DEBUG_WM(F("STA IP Address:"),WiFi.localIP()); - _lastconxresult = WL_CONNECTED; + // no getter for autoreconnectpolicy before this + // https://github.com/esp8266/Arduino/pull/4359 + // so we must force it on else, if not connectimeout then waitforconnectionresult gets stuck endless loop + WiFi_autoReconnect(); + // set hostname before stating 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 + setupHostname(true); } - return true; - } - // possibly skip the config portal - if (!_enableConfigPortal) { - return false; - } + // 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){ + connected = true; + DEBUG_WM(F("AutoConnect: ESP Already Connected")); + setSTAConfig(); + } - DEBUG_WM(F("AutoConnect: FAILED")); + if(connected || connectWifi("", "") == WL_CONNECTED){ + //connected + DEBUG_WM(F("AutoConnect: SUCCESS")); + 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 + } + return true; + } + + // possibly skip the config portal + if (!_enableConfigPortal) { + return false; + } + + DEBUG_WM(F("AutoConnect: FAILED")); } else DEBUG_WM(F("No Credentials are Saved, skipping connect")); // not connected start configportal - return startConfigPortal(apName, apPassword); + bool res = startConfigPortal(apName, apPassword); + return res; +} + +bool WiFiManager::setupHostname(bool restart){ + DEBUG_WM(DEBUG_VERBOSE,"Setting hostname:",_hostname); + if((String)_hostname == "") { + DEBUG_WM(DEBUG_VERBOSE,"No Hostname to set"); + return false; + } + 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!")); + + // in sta mode restart , not sure about softap + if(restart && (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() + } + + return res; } // CONFIG PORTAL @@ -479,7 +491,7 @@ 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()); // @todo not showing ip dnsServer->start(DNS_PORT, F("*"), WiFi.softAPIP()); // @todo new callback, webserver started, callback cannot override handlers, but can grab them first diff --git a/WiFiManager.h b/WiFiManager.h index 7ad1628..8b84d5d 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -396,7 +396,8 @@ class WiFiManager void setupConfigPortal(); bool shutdownConfigPortal(); - + bool setupHostname(bool restart); + #ifdef NO_EXTRA_4K_HEAP boolean _tryWPS = false; // try WPS on save failure, unsupported void startWPS(); diff --git a/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino b/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino index 7ebd8d5..b231cc3 100644 --- a/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino +++ b/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino @@ -6,6 +6,13 @@ */ #include // https://github.com/tzapu/WiFiManager +// include MDNS +#ifdef ESP8266 +#include +#elif defined(ESP32) +#include +#endif + // select which pin will trigger the configuration portal when set to LOW #define TRIGGER_PIN 0 @@ -20,11 +27,21 @@ void setup() { WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP // put your setup code here, to run once Serial.begin(115200); + Serial.setDebugOutput(true); + delay(1000); Serial.println("\n Starting"); + pinMode(TRIGGER_PIN, INPUT_PULLUP); + + // wm.resetSettings(); + wm.setHostname("MDNSEXAMPLE"); + // wm.setEnableConfigPortal(false); + // wm.setConfigPortalBlocking(false); + wm.autoConnect(); } void loop() { + MDNS.update(); doWiFiManager(); // put your main code here, to run repeatedly: } diff --git a/examples/Tests/AnonymousCB.ino b/examples/Tests/AnonymousCB.ino new file mode 100644 index 0000000..ff44976 --- /dev/null +++ b/examples/Tests/AnonymousCB.ino @@ -0,0 +1,24 @@ +#include // https://github.com/tzapu/WiFiManager + +bool _enteredConfigMode = false; + +void setup(){ + Serial.begin(115200); +WiFiManager wifiManager; + + // wifiManager.setAPCallback([this](WiFiManager* wifiManager) { + wifiManager.setAPCallback([&](WiFiManager* wifiManager) { + Serial.printf("Entered config mode:ip=%s, ssid='%s'\n", + WiFi.softAPIP().toString().c_str(), + wifiManager->getConfigPortalSSID().c_str()); + _enteredConfigMode = true; + }); + wifiManager.resetSettings(); + if (!wifiManager.autoConnect()) { + Serial.printf("*** Failed to connect and hit timeout\n"); + ESP.reset(); + delay(1000); + } +} + +void loop(){} From 32075b32cd3dca17422a62d75f111b7a2e1ba6b1 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Mon, 11 May 2020 12:39:50 -0500 Subject: [PATCH 13/40] fixes #1040, adds http port `setHttpPort` --- WiFiManager.cpp | 21 +++++++++++---- WiFiManager.h | 4 +++ .../OnDemandConfigPortal.ino | 27 ++++++++++++------- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 6482ec8..08e61ec 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -486,7 +486,9 @@ void WiFiManager::setupConfigPortal() { // setup dns and web servers dnsServer.reset(new DNSServer()); - server.reset(new WM_WebServer(80)); + server.reset(new WM_WebServer(_httpPort)); + + if(_httpPort != 80) DEBUG_WM(DEBUG_VERBOSE,"http server started with custom port: ",_httpPort); // @todo not showing ip /* Setup the DNS server redirecting all the domains to the apIP */ dnsServer->setErrorReplyCode(DNSReplyCode::NoError); @@ -1828,11 +1830,16 @@ void WiFiManager::handleNotFound() { boolean WiFiManager::captivePortal() { DEBUG_WM(DEBUG_DEV,"-> " + server->hostHeader()); - if(!_enableCaptivePortal) return false; // skip redirections - - if (!isIp(server->hostHeader())) { + if(!_enableCaptivePortal) return false; // skip redirections, @todo maybe allow redirection even when no cp ? might be useful + + String serverLoc = toStringIp(server->client().localIP()); + if(_httpPort != 80) serverLoc += ":" + (String)_httpPort; // add port if not default + bool doredirect = serverLoc != server->hostHeader(); // redirect if hostheader not server ip, prevent redirect loops + // doredirect = !isIp(server->hostHeader()) // old check + + if (doredirect) { DEBUG_WM(DEBUG_VERBOSE,F("<- Request redirected to captive portal")); - server->sendHeader(F("Location"), (String)F("http://") + toStringIp(server->client().localIP()), true); + server->sendHeader(F("Location"), (String)F("http://") + serverLoc, 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 return true; @@ -2476,6 +2483,10 @@ void WiFiManager::setClass(String str){ _bodyClass = str; } +void WiFiManager::setHttpPort(uint16_t port){ + _httpPort = port; +} + // HELPERS /** diff --git a/WiFiManager.h b/WiFiManager.h index 8b84d5d..87e136e 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -297,6 +297,9 @@ class WiFiManager void setClass(String str); String getDefaultAPName(); + // set port of webserver + void setHttpPort(uint16_t port); + std::unique_ptr dnsServer; #if defined(ESP32) && defined(WM_WEBSERVERSHIM) @@ -349,6 +352,7 @@ class WiFiManager bool _channelSync = false; // use same wifi sta channel when starting ap int32_t _apChannel = 0; // channel to use for ap bool _apHidden = false; // store softap hidden value + uint16_t _httpPort = 80; // port for webserver #ifdef ESP32 static uint8_t _lastconxresulttmp; // tmp var for esp32 callback diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 9579882..b969cc5 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -14,11 +14,11 @@ #include #endif -#define TRIGGER_PIN 0 const char* modes[] = { "NULL", "STA", "AP", "STA+AP" }; unsigned long mtime = 0; +// OLED TEST , untested // // #define MYOLED // #include @@ -69,10 +69,14 @@ void print_oled(String str,uint8_t size){ 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 = true; +// TEST OPTION FLAGS +bool TEST_CP = true; // always start the configportal, even if ap found +int TESP_CP_TIMEOUT = 90; // test cp timeout + +bool TEST_NET = true; // do a network test after connect, (gets ntp time) +bool ALLOWONDEMAND = true; // enable on demand +int ONDDEMANDPIN = 0; // gpio for button + // char ssid[] = "*************"; // your network SSID (name) // char pass[] = "********"; // your network password @@ -194,7 +198,7 @@ void setup() { //sets timeout until configuration portal gets turned off //useful to make it all retry or go to sleep in seconds - wm.setConfigPortalTimeout(120); + wm.setConfigPortalTimeout(120); // wm.setConnectTimeout(20); // wm.setShowStaticFields(true); @@ -205,6 +209,9 @@ void setup() { wm.setBreakAfterConfig(true); + // set custom webserver port, automatic captive portal does not work with custom ports! + // wm.setHttpPort(8080); + //fetches ssid and pass and tries to connect //if it does not connect it starts an access point with the specified name //here "AutoConnectAP" @@ -219,7 +226,7 @@ void setup() { delay(1000); Serial.println("TEST_CP ENABLED"); // start configportal always - wm.setConfigPortalTimeout(60); + wm.setConfigPortalTimeout(TESP_CP_TIMEOUT); wm.startConfigPortal("WM_ConnectAP"); } else { @@ -229,7 +236,7 @@ void setup() { } wifiInfo(); - pinMode(TRIGGER_PIN, INPUT_PULLUP); + pinMode(ONDDEMANDPIN, INPUT_PULLUP); #ifdef USEOTA ArduinoOTA.begin(); @@ -249,9 +256,9 @@ void loop() { ArduinoOTA.handle(); #endif // is configuration portal requested? - if (ALLOWONDEMAND && digitalRead(TRIGGER_PIN) == LOW ) { + if (ALLOWONDEMAND && digitalRead(ONDDEMANDPIN) == LOW ) { delay(100); - if ( digitalRead(TRIGGER_PIN) == LOW ){ + if ( digitalRead(ONDDEMANDPIN) == LOW ){ Serial.println("BUTTON PRESSED"); wm.setConfigPortalTimeout(140); wm.setParamsPage(false); // move params to seperate page, not wifi, do not combine with setmenu! From 6515190124d181a2be5140f530d987d845c5aa51 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Mon, 11 May 2020 17:23:20 -0500 Subject: [PATCH 14/40] fixes #1046 --- WiFiManager.cpp | 12 +++++++----- WiFiManager.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 08e61ec..b2e97eb 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -206,9 +206,10 @@ WiFiManager::~WiFiManager() { } // @todo remove event - // #ifdef ESP32 - // WiFi.removeEvent(std::bind(&WiFiManager::WiFiEvent,this)); - // #endif + // WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2)); + #ifdef ESP32 + WiFi.removeEvent(wm_event_id); + #endif DEBUG_WM(DEBUG_DEV,F("unloading")); } @@ -2898,8 +2899,9 @@ String WiFiManager::WiFi_psk(bool persistent) const { void WiFiManager::WiFiEvent(WiFiEvent_t event,system_event_info_t info){ if(!_hasBegun){ // DEBUG_WM(DEBUG_VERBOSE,"[ERROR] WiFiEvent, not ready"); + Serial.println("[ERROR] wm not ready"); return; - } + } // DEBUG_WM(DEBUG_VERBOSE,"[EVENT]",event); if(event == SYSTEM_EVENT_STA_DISCONNECTED){ DEBUG_WM(DEBUG_VERBOSE,"[EVENT] WIFI_REASON:",info.disconnected.reason); @@ -2927,7 +2929,7 @@ void WiFiManager::WiFi_autoReconnect(){ // @todo move to seperate method, used for event listener now DEBUG_WM(DEBUG_VERBOSE,"ESP32 event handler enabled"); using namespace std::placeholders; - WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2)); + wm_event_id = WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2)); // } #endif } diff --git a/WiFiManager.h b/WiFiManager.h index 87e136e..b5189af 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -134,7 +134,6 @@ class WiFiManagerParameter { int _length; int _labelPlacement; const char *_customHTML; - friend class WiFiManager; }; @@ -355,6 +354,7 @@ class WiFiManager uint16_t _httpPort = 80; // port for webserver #ifdef ESP32 + wifi_event_id_t wm_event_id; static uint8_t _lastconxresulttmp; // tmp var for esp32 callback #endif From 135e872caa513ccfeab100e98e97ac471a9bdd20 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Mon, 11 May 2020 21:29:46 -0500 Subject: [PATCH 15/40] remove debug --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index b2e97eb..bd14602 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2387,7 +2387,7 @@ void WiFiManager::setMenu(const char * menu[], uint8_t size){ } } } - DEBUG_WM(getMenuOut()); + // DEBUG_WM(getMenuOut()); } /** @@ -2410,7 +2410,7 @@ void WiFiManager::setMenu(std::vector& menu){ } } } - DEBUG_WM(getMenuOut()); + // DEBUG_WM(getMenuOut()); } From 7b52e709db13cecf2adbfaf20437c55019059ada Mon Sep 17 00:00:00 2001 From: "doncov.eugene" Date: Thu, 14 May 2020 15:50:39 +0300 Subject: [PATCH 16/40] Readme: fill DNS server if setSTAStaticIPConfig --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6acf010..34f19cb 100644 --- a/README.md +++ b/README.md @@ -292,6 +292,8 @@ wifiManager.setSTAStaticIPConfig(IPAddress(192,168,0,99), IPAddress(192,168,0,1) ``` There are a couple of examples in the examples folder that show you how to set a static IP and even how to configure it through the web configuration portal. +NOTE: You should fill DNS server if you have HTTP requests with hostnames or syncronize time (NTP). It's the same as gateway ip or a popular (Google DNS: 8.8.8.8). + #### Custom HTML, CSS, Javascript There are various ways in which you can inject custom HTML, CSS or Javascript into the configuration portal. The options are: From 3e9f9a103e3555de9961c8c7a32c2fcb03ad45a9 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 14 May 2020 21:55:47 -0500 Subject: [PATCH 17/40] #1050 prevent copy assignment of param constructor --- WiFiManager.cpp | 7 +++++++ WiFiManager.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index bd14602..69d07cd 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -68,6 +68,12 @@ WiFiManagerParameter::~WiFiManagerParameter() { _length=0; // setting length 0, ideally the entire parameter should be removed, or added to wifimanager scope so it follows } +// WiFiManagerParameter& WiFiManagerParameter::operator=(const WiFiManagerParameter& rhs){ +// Serial.println("copy assignment op called"); +// (*this->_value) = (*rhs._value); +// return *this; +// } + // @note debug is not available in wmparameter class void WiFiManagerParameter::setValue(const char *defaultValue, int length) { if(!_id){ @@ -89,6 +95,7 @@ void WiFiManagerParameter::setValue(const char *defaultValue, int length) { } } const char* WiFiManagerParameter::getValue() { + // Serial.println(printf("Address of _value is %p\n", (void *)_value)); return _value; } const char* WiFiManagerParameter::getID() { diff --git a/WiFiManager.h b/WiFiManager.h index b5189af..4fa1e6e 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -114,6 +114,7 @@ class WiFiManagerParameter { WiFiManagerParameter(const char *id, const char *label, const char *defaultValue, int length, const char *custom); WiFiManagerParameter(const char *id, const char *label, const char *defaultValue, int length, const char *custom, int labelPlacement); ~WiFiManagerParameter(); + // WiFiManagerParameter& operator=(const WiFiManagerParameter& rhs); const char *getID(); const char *getValue(); @@ -128,6 +129,7 @@ class WiFiManagerParameter { void init(const char *id, const char *label, const char *defaultValue, int length, const char *custom, int labelPlacement); private: + WiFiManagerParameter& operator=(const WiFiManagerParameter&); const char *_id; const char *_label; char *_value; From 0486034c6a4e027c3a84bd03287a130a81305391 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 14 May 2020 21:56:33 -0500 Subject: [PATCH 18/40] some comments etc --- WiFiManager.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 69d07cd..cfd9060 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -290,6 +290,8 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { connected = true; DEBUG_WM(F("AutoConnect: ESP Already Connected")); setSTAConfig(); + // @todo not sure if this check makes sense, causes dup setSTAConfig in connectwifi, + // and we have no idea WHAT we are connected to } if(connected || connectWifi("", "") == WL_CONNECTED){ @@ -305,12 +307,13 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { DEBUG_WM(DEBUG_DEV,"hostname: STA",WiFi.getHostname()); #endif } - return true; + + return true; // connected success } // possibly skip the config portal if (!_enableConfigPortal) { - return false; + return false; // not connected and not cp } DEBUG_WM(F("AutoConnect: FAILED")); @@ -2618,8 +2621,16 @@ void WiFiManager::debugPlatformInfo(){ 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()); + DEBUG_WM("Free heap: ", ESP.getFreeHeap()); + DEBUG_WM("ESP SDK version: ", ESP.getSdkVersion()); + // esp_chip_info_t chipInfo; + // esp_chip_info(&chipInfo); + // DEBUG_WM("Chip Info: Model: ",chipInfo.model); + // DEBUG_WM("Chip Info: Cores: ",chipInfo.cores); + // DEBUG_WM("Chip Info: Rev: ",chipInfo.revision); + // DEBUG_WM(printf("Chip Info: Model: %d, cores: %d, revision: %d", chipInfo.model.c_str(), chipInfo.cores, chipInfo.revision)); + // DEBUG_WM("Chip Rev: ",(String)ESP.getChipRevision()); + // core version is not avail #endif } From 01b909a1d2f05b9d991eb69a1d828285045706f9 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Mon, 18 May 2020 15:36:15 -0500 Subject: [PATCH 19/40] version alpha release --- WiFiManager.cpp | 3 ++- library.json | 2 +- library.properties | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index cfd9060..8501211 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2426,7 +2426,8 @@ void WiFiManager::setMenu(std::vector& menu){ /** * set params as sperate page not in wifi - * NOT COMPATIBLE WITH setMenu! @todo scan menuids and insert param after wifi or something + * NOT COMPATIBLE WITH setMenu! + * @todo scan menuids and insert param after wifi or something, same for ota * @param bool enable * @since $dev */ diff --git a/library.json b/library.json index 0ceb4c8..5eff70e 100644 --- a/library.json +++ b/library.json @@ -25,5 +25,5 @@ "espressif8266", "espressif32" ], - "version": "1.0.0" + "version": "2.0.1-alpha" } diff --git a/library.properties b/library.properties index 5ee6e46..9f2fa8d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WiFiManager -version=1.0.0 +version=2.0.1-alpha author=tzapu,tablatronix maintainer=tablatronix sentence=WiFi Configuration manager with web configuration portal for ESP boards From b67d1656d85dd68682eb29b0cefd801242ffe361 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Mon, 18 May 2020 15:46:44 -0500 Subject: [PATCH 20/40] Fix esp32 mdns --- .../NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino b/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino index b231cc3..3813356 100644 --- a/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino +++ b/examples/NonBlocking/OnDemandNonBlocking/onDemandNonBlocking.ino @@ -41,7 +41,9 @@ void setup() { } void loop() { + #ifdef ESP8266 MDNS.update(); + #endif doWiFiManager(); // put your main code here, to run repeatedly: } From 634fac4be0e4d14d6e4bd26fdbbfe13a17acd83c Mon Sep 17 00:00:00 2001 From: tablatronix Date: Mon, 18 May 2020 15:49:24 -0500 Subject: [PATCH 21/40] fix travis esp32 --- examples/Tests/AnonymousCB.ino | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/Tests/AnonymousCB.ino b/examples/Tests/AnonymousCB.ino index ff44976..f34d80f 100644 --- a/examples/Tests/AnonymousCB.ino +++ b/examples/Tests/AnonymousCB.ino @@ -4,7 +4,7 @@ bool _enteredConfigMode = false; void setup(){ Serial.begin(115200); -WiFiManager wifiManager; + WiFiManager wifiManager; // wifiManager.setAPCallback([this](WiFiManager* wifiManager) { wifiManager.setAPCallback([&](WiFiManager* wifiManager) { @@ -16,9 +16,11 @@ WiFiManager wifiManager; wifiManager.resetSettings(); if (!wifiManager.autoConnect()) { Serial.printf("*** Failed to connect and hit timeout\n"); - ESP.reset(); + ESP.restart(); delay(1000); } } -void loop(){} +void loop(){ + +} From f4a577bbc2d0132f149300c3210c0e854d9f100e Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 18 May 2020 16:31:13 -0500 Subject: [PATCH 22/40] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 34f19cb..1cf5703 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,11 @@ 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. -**This works with the ESP8266 Arduino platform with a recent stable release(2.0.0 or newer)** +**This works with the ESP8266 Arduino platform** [https://github.com/esp8266/Arduino](https://github.com/esp8266/Arduino) -**This works with the ESP32 Arduino platform with staging** +**This works with the ESP32 Arduino platform** [https://github.com/espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) From 95d116cea39420436e83d304a034b0dfae8024eb Mon Sep 17 00:00:00 2001 From: Shawn A Date: Mon, 18 May 2020 16:34:27 -0500 Subject: [PATCH 23/40] Update README.md :warning --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1cf5703..42d4e7f 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ # WiFiManager ESP8266 WiFi Connection manager with fallback web configuration portal +:warning: This Documentation is out of date for this branch, see notes below + [![Build Status](https://travis-ci.org/tzapu/WiFiManager.svg?branch=development)](https://travis-ci.org/tzapu/WiFiManager) ![ESP8266](https://img.shields.io/badge/ESP-8266-000000.svg?longCache=true&style=flat&colorA=CC101F) From d71a14194bfe00319ec7c263a4035335cfacd086 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 19 May 2020 10:58:10 -0500 Subject: [PATCH 24/40] Fix MDNS stupid c++ macros --- WiFiManager.cpp | 24 +++++++++++++----------- WiFiManager.h | 8 +++++--- strings_en.h | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 8501211..923b0f0 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -302,9 +302,9 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { if((String)_hostname != ""){ #ifdef ESP8266 - DEBUG_WM(DEBUG_DEV,"hostname: STA",WiFi.hostname()); + DEBUG_WM(DEBUG_DEV,"hostname: STA: ",WiFi.hostname()); #elif defined(ESP32) - DEBUG_WM(DEBUG_DEV,"hostname: STA",WiFi.getHostname()); + DEBUG_WM(DEBUG_DEV,"hostname: STA: ",WiFi.getHostname()); #endif } @@ -326,16 +326,17 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { } bool WiFiManager::setupHostname(bool restart){ - DEBUG_WM(DEBUG_VERBOSE,"Setting hostname:",_hostname); if((String)_hostname == "") { - DEBUG_WM(DEBUG_VERBOSE,"No Hostname to set"); + DEBUG_WM(DEBUG_DEV,"No Hostname to set"); return false; - } + } else DEBUG_WM(DEBUG_DEV,"setupHostname: ",_hostname); bool res = true; #ifdef ESP8266 + DEBUG_WM(DEBUG_VERBOSE,"Setting WiFi hostname"); res = WiFi.hostname(_hostname); - #ifdef ESP8266MDNS_H - DEBUG_WM(DEBUG_VERBOSE,"Setting MDNS hostname"); + // #ifdef ESP8266MDNS_H + #ifdef WM_MDNS + DEBUG_WM(DEBUG_VERBOSE,"Setting MDNS hostname, tcp 80"); if(MDNS.begin(_hostname)){ MDNS.addService("http", "tcp", 80); } @@ -344,8 +345,9 @@ bool WiFiManager::setupHostname(bool restart){ // @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"); + // #ifdef ESP32MDNS_H + #ifdef WM_MDNS + DEBUG_WM(DEBUG_VERBOSE,"Setting MDNS hostname, tcp 80"); if(MDNS.begin(_hostname)){ MDNS.addService("http", "tcp", 80); } @@ -431,7 +433,7 @@ bool WiFiManager::startAP(){ 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()); + DEBUG_WM(DEBUG_DEV,F("hostname: AP: "),WiFi.softAPgetHostname()); } #endif @@ -1343,7 +1345,7 @@ void WiFiManager::handleWiFiStatus(){ handleRequest(); String page; // String page = "{\"result\":true,\"count\":1}"; - #ifdef JSTEST + #ifdef WM_JSTEST page = FPSTR(HTTP_JS); #endif server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); diff --git a/WiFiManager.h b/WiFiManager.h index 4fa1e6e..17118b6 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -22,11 +22,14 @@ #include -// #define WM_MDNS // also set MDNS with sethostname +// #define WM_MDNS // includes MDNS, also set MDNS with sethostname // #define WM_FIXERASECONFIG // use erase flash fix // #define WM_ERASE_NVS // esp32 erase(true) will erase NVS // #define WM_RTC // esp32 info page will include reset reasons +// #define WM_JSTEST // build flag for enabling js xhr tests +// #define WIFI_MANAGER_OVERRIDE_STRINGS // build flag for using own strings include + #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 @@ -67,7 +70,7 @@ #include #else #include - // Forthcoming official ? + // Forthcoming official ? probably never happening // https://github.com/esp8266/ESPWebServer #endif #endif @@ -85,7 +88,6 @@ #include #endif - #else #endif diff --git a/strings_en.h b/strings_en.h index 2560ff0..882cf6b 100644 --- a/strings_en.h +++ b/strings_en.h @@ -124,7 +124,7 @@ const char HTTP_HELP[] PROGMEM = "" "

More information about WiFiManager at https://github.com/tzapu/WiFiManager."; -#ifdef JSTEST +#ifdef WM_JSTEST const char HTTP_JS[] PROGMEM = ""; From 2cedf7b368cd9ce37ab92a1ca521980179b498cf Mon Sep 17 00:00:00 2001 From: tablatronix Date: Sun, 24 May 2020 14:11:25 -0500 Subject: [PATCH 31/40] 2.0.2 --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 5eff70e..09f7315 100644 --- a/library.json +++ b/library.json @@ -25,5 +25,5 @@ "espressif8266", "espressif32" ], - "version": "2.0.1-alpha" + "version": "2.0.2-alpha" } diff --git a/library.properties b/library.properties index 9f2fa8d..1597544 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WiFiManager -version=2.0.1-alpha +version=2.0.2-alpha author=tzapu,tablatronix maintainer=tablatronix sentence=WiFi Configuration manager with web configuration portal for ESP boards From 9af72535efdff02c0b7b9e8594509a0d91adc9b9 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Mon, 25 May 2020 11:42:31 -0500 Subject: [PATCH 32/40] I messed up --- library.json | 2 +- library.properties | 2 +- strings_en.h | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/library.json b/library.json index 09f7315..96c4164 100644 --- a/library.json +++ b/library.json @@ -25,5 +25,5 @@ "espressif8266", "espressif32" ], - "version": "2.0.2-alpha" + "version": "2.0.3-alpha" } diff --git a/library.properties b/library.properties index 1597544..9ac084b 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=WiFiManager -version=2.0.2-alpha +version=2.0.3-alpha author=tzapu,tablatronix maintainer=tablatronix sentence=WiFi Configuration manager with web configuration portal for ESP boards diff --git a/strings_en.h b/strings_en.h index c409437..d56d0b1 100644 --- a/strings_en.h +++ b/strings_en.h @@ -20,7 +20,6 @@ const char HTTP_HEAD_START[] PROGMEM = ""; From 998243c60cfb146b0d4ff17ccd880b1b54848c88 Mon Sep 17 00:00:00 2001 From: Adrian Jost <22987140+adrianjost@users.noreply.github.com> Date: Sun, 7 Jun 2020 20:26:03 +0200 Subject: [PATCH 33/40] swap comments --- WiFiManager.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WiFiManager.h b/WiFiManager.h index 0834390..72041a5 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -323,10 +323,10 @@ class WiFiManager // check if the module has a saved ap to connect to bool getWiFiIsSaved(); - // helper to get saved ssid, if persistent get stored, else get current if connected + // helper to get saved password, if persistent get stored, else get current if connected String getWiFiPass(bool persistent = false); - // helper to get saved password, if persistent get stored, else get current if connected + // helper to get saved ssid, if persistent get stored, else get current if connected String getWiFiSSID(bool persistent = false); // debug output the softap config @@ -613,4 +613,4 @@ class WiFiManager #endif -#endif \ No newline at end of file +#endif From 994609f1e05b46a8a25c3f989cb3f66c0049f348 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 4 Aug 2020 23:24:28 -0500 Subject: [PATCH 34/40] add logging --- WiFiManager.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 1686a3e..718aedf 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -356,7 +356,6 @@ bool WiFiManager::setupHostname(bool restart){ if(!res)DEBUG_WM(DEBUG_ERROR,F("[ERROR] hostname: set failed!")); - // in sta mode restart , not sure about softap if(restart && (WiFi.status() == WL_CONNECTED)){ DEBUG_WM(DEBUG_VERBOSE,F("reconnecting to set new hostname")); // WiFi.reconnect(); // This does not reset dhcp @@ -838,6 +837,8 @@ bool WiFiManager::wifiConnectDefault(){ DEBUG_WM(F("Connecting to SAVED AP:"),WiFi_SSID(true)); DEBUG_WM(DEBUG_DEV,F("Using Password:"),WiFi_psk(true)); ret = WiFi_enableSTA(true,storeSTAmode); + delay(500); // THIS DELAY ? + DEBUG_WM(DEBUG_DEV,"Mode after delay: "+getModeString(WiFi.getMode())); if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi enableSta failed"); ret = WiFi.begin(); if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] wifi begin failed"); @@ -2785,14 +2786,14 @@ bool WiFiManager::WiFi_Disconnect() { #ifdef ESP8266 if((WiFi.getMode() & WIFI_STA) != 0) { bool ret; - DEBUG_WM(DEBUG_DEV,F("WIFI station disconnect")); + 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")); + DEBUG_WM(DEBUG_DEV,F("WiFi station disconnect")); return WiFi.disconnect(); // not persistent atm #endif return false; @@ -2800,7 +2801,7 @@ bool WiFiManager::WiFi_Disconnect() { // toggle STA without persistent bool WiFiManager::WiFi_enableSTA(bool enable,bool persistent) { - DEBUG_WM(DEBUG_DEV,F("WiFi station enable")); + DEBUG_WM(DEBUG_DEV,F("WiFi_enableSTA"),(String) enable? "enable" : "disable"); #ifdef ESP8266 WiFiMode_t newMode; WiFiMode_t currentMode = WiFi.getMode(); From fac59e1982aef5c1bcb5c1d5edbcab7aa4df7039 Mon Sep 17 00:00:00 2001 From: "David J. Fiddes" Date: Thu, 13 Aug 2020 18:19:55 +0100 Subject: [PATCH 35/40] Fix warning in WiFiManager::debugPlatformInfo for ESP32 This fixes an unused variable warning as the call to heap_caps_get_free_size() is not required. Tests: - Enable debug mode and verify free heap and ESP SDK version are correctly displayed - Cross check with the free heap reported via the captive portal info page --- WiFiManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 718aedf..6903c4f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2632,7 +2632,6 @@ void WiFiManager::debugPlatformInfo(){ 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: ", ESP.getFreeHeap()); DEBUG_WM("ESP SDK version: ", ESP.getSdkVersion()); // esp_chip_info_t chipInfo; From d1656421bb752d0581fb65b2b235d636b2ec3a2c Mon Sep 17 00:00:00 2001 From: tablatronix Date: Mon, 14 Sep 2020 10:23:00 -0500 Subject: [PATCH 36/40] remove getheapstats, not exist in 2.3.0 --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 718aedf..050345e 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2558,8 +2558,8 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { uint16_t max; uint8_t frag; #ifdef ESP8266 - ESP.getHeapStats(&free, &max, &frag); - _debugPort.printf("[MEM] free: %5d | max: %5d | frag: %3d%% \n", free, max, frag); + // ESP.getHeapStats(&free, &max, &frag);// @todo Does not exist in 2.3.0 + // _debugPort.printf("[MEM] free: %5d | max: %5d | frag: %3d%% \n", free, max, frag); #elif defined ESP32 // total_free_bytes; ///< Total free bytes in the heap. Equivalent to multi_free_heap_size(). // total_allocated_bytes; ///< Total bytes allocated to data in the heap. From 61916627ed79f764a2a94df8792ae8b428b03d44 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Mon, 14 Sep 2020 10:23:09 -0500 Subject: [PATCH 37/40] example compile issue --- 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 28d1447..dcfab8c 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -56,7 +56,7 @@ void saveWifiCallback(){ void configModeCallback (WiFiManager *myWiFiManager) { Serial.println("[CALLBACK] configModeCallback fired"); #ifdef ESP8266 - print_oled("WiFiManager Waiting\nIP: " + WiFi.softAPIP().toString() + "\nSSID: " + WiFi.softAPSSID(),1); + // print_oled("WiFiManager Waiting\nIP: " + WiFi.softAPIP().toString() + "\nSSID: " + WiFi.softAPSSID(),1); #endif // myWiFiManager->setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); // Serial.println(WiFi.softAPIP()); From 726bdfae4648306726cefb77ab74ef76d08cbbb6 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 15 Sep 2020 09:54:45 -0500 Subject: [PATCH 38/40] #1125 remove country from 2.3.0 --- WiFiManager.cpp | 9 ++++++--- WiFiManager.h | 1 + .../DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino | 2 +- strings_en.h | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 050345e..7416180 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2592,13 +2592,16 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { * @return {[type]} [description] */ void WiFiManager::debugSoftAPConfig(){ - wifi_country_t country; #ifdef ESP8266 softap_config config; wifi_softap_get_config(&config); - wifi_get_country(&country); + #if !defined(WM_NOCOUNTRY) + wifi_country_t country; + wifi_get_country(&country); + #endif #elif defined(ESP32) + wifi_country_t country; wifi_config_t conf_config; esp_wifi_get_config(WIFI_IF_AP, &conf_config); // == ESP_OK wifi_ap_config_t config = conf_config.ap; @@ -2745,7 +2748,7 @@ bool WiFiManager::WiFiSetCountry(){ else if(_wificountry == "CN") ret = esp_wifi_set_country(&WM_COUNTRY_CN) == ESP_OK; else DEBUG_WM(DEBUG_ERROR,"[ERROR] country code not found"); - #elif defined(ESP8266) + #elif defined(ESP8266) && !defined(WM_NOCOUNTRY) // if(WiFi.getMode() == WIFI_OFF); // exception if wifi not init! if(_wificountry == "US") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_US); else if(_wificountry == "JP") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_JP); diff --git a/WiFiManager.h b/WiFiManager.h index 72041a5..3e964af 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -33,6 +33,7 @@ #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 +#define WM_NOCOUNTRY // esp8266 no country #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. diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index dcfab8c..9b4bb78 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -290,7 +290,7 @@ void getTime() { } Serial.println(""); struct tm timeinfo; - gmtime_r(&now, &timeinfo); + gmtime_r(&now, &timeinfo); // @NOTE doesnt work in esp2.3.0 Serial.print("Current time: "); Serial.print(asctime(&timeinfo)); } diff --git a/strings_en.h b/strings_en.h index d56d0b1..903efe6 100644 --- a/strings_en.h +++ b/strings_en.h @@ -348,7 +348,7 @@ const char* const WIFI_MODES[] PROGMEM = { "NULL", "STA", "AP", "STA+AP" }; const wifi_country_t WM_COUNTRY_US{"US",1,11,CONFIG_ESP32_PHY_MAX_TX_POWER,WIFI_COUNTRY_POLICY_AUTO}; const wifi_country_t WM_COUNTRY_CN{"CN",1,13,CONFIG_ESP32_PHY_MAX_TX_POWER,WIFI_COUNTRY_POLICY_AUTO}; const wifi_country_t WM_COUNTRY_JP{"JP",1,14,CONFIG_ESP32_PHY_MAX_TX_POWER,WIFI_COUNTRY_POLICY_AUTO}; -#elif defined(ESP8266) +#elif defined(ESP8266) && !defined(WM_NOCOUNTRY) // typedef struct { // char cc[3]; /**< country code string */ // uint8_t schan; /**< start channel */ From 08efbfcfe72e5db4d385a0683177339334aa5689 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 15 Sep 2020 10:18:43 -0500 Subject: [PATCH 39/40] remove country debug --- WiFiManager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 7416180..e553e17 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2617,7 +2617,9 @@ void WiFiManager::debugSoftAPConfig(){ 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("country: "),(String)country.cc); + #if !defined(WM_NOCOUNTRY) + DEBUG_WM(F("country: "),(String)country.cc); + #endif DEBUG_WM(F("beacon_interval: "),(String)config.beacon_interval + "(ms)"); DEBUG_WM(FPSTR(D_HR)); } From e454c9969a327bcf1be221d19380381e08ca515c Mon Sep 17 00:00:00 2001 From: tablatronix Date: Sat, 17 Oct 2020 21:44:55 -0500 Subject: [PATCH 40/40] remove oled stuff --- .../OnDemandConfigPortal.ino | 62 +++---------------- 1 file changed, 7 insertions(+), 55 deletions(-) diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 9b4bb78..e86a39c 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -19,7 +19,6 @@ const char* modes[] = { "NULL", "STA", "AP", "STA+AP" }; unsigned long mtime = 0; - WiFiManager wm; // TEST OPTION FLAGS @@ -34,20 +33,6 @@ int ONDDEMANDPIN = 0; // gpio for button // char ssid[] = "*************"; // your network SSID (name) // char pass[] = "********"; // your network password -// OLED TEST , ssd1306 -// #define WM_OLED -#ifdef WM_OLED -#include -#include -#include -#define SCREEN_WIDTH 128 // OLED display width, in pixels -#define SCREEN_HEIGHT 32 // OLED display height, in pixels - -// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) -#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) -Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); -#endif - void saveWifiCallback(){ Serial.println("[CALLBACK] saveCallback fired"); } @@ -55,9 +40,6 @@ void saveWifiCallback(){ //gets called when WiFiManager enters configuration mode void configModeCallback (WiFiManager *myWiFiManager) { Serial.println("[CALLBACK] configModeCallback fired"); - #ifdef ESP8266 - // print_oled("WiFiManager Waiting\nIP: " + WiFi.softAPIP().toString() + "\nSSID: " + WiFi.softAPSSID(),1); - #endif // 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 @@ -91,12 +73,13 @@ void setup() { Serial.println("\n Starting"); // WiFi.setSleepMode(WIFI_NONE_SLEEP); // disable sleep, can improve ap stability - - #ifdef WM_OLED - init_oled(); - #endif - print_oled(F("Starting..."),2); + Serial.println("Error - TEST"); + Serial.println("Information- - TEST"); + + Serial.println("[ERROR] TEST"); + Serial.println("[INFORMATION] TEST"); + wm.debugPlatformInfo(); //reset settings - for testing @@ -201,10 +184,8 @@ void setup() { wifiInfo(); - print_oled(F("Connecting..."),2); if(!wm.autoConnect("WM_AutoConnectAP","12345678")) { Serial.println("failed to connect and hit timeout"); - print_oled("Not Connected",2); } else if(TEST_CP) { // start configportal always @@ -216,7 +197,6 @@ void setup() { else { //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); - print_oled("Connected\nIP: " + WiFi.localIP().toString() + "\nSSID: " + WiFi.SSID(),1); } wifiInfo(); @@ -225,6 +205,7 @@ void setup() { #ifdef USEOTA ArduinoOTA.begin(); #endif + } void wifiInfo(){ @@ -258,7 +239,6 @@ void loop() { else { //if you get here you have connected to the WiFi Serial.println("connected...yeey :)"); - print_oled("Connected\nIP: " + WiFi.localIP().toString() + "\nSSID: " + WiFi.SSID(),1); getTime(); } } @@ -317,31 +297,3 @@ void debugchipid(){ // 507726A4AE30 // ESP32 Chip ID = 507726A4AE30 } - -#ifdef WM_OLED -void init_oled(){ - if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32 - Serial.println(F("SSD1306 allocation failed")); - } - - display.clearDisplay(); - display.setTextSize(1); // Normal 1:1 pixepl scale - display.setTextColor(WHITE); // Draw white text - display.setCursor(0,0); // Start at top-left corner - display.display(); -} - -void print_oled(String str,uint8_t size){ - display.clearDisplay(); - display.setTextSize(size); - display.setTextColor(WHITE); - display.setCursor(0,0); - display.println(str); - display.display(); -} -#else - void print_oled(String str,uint8_t size){ - (void)str; - (void)size; - } -#endif