From 9a85b107fa264a5a3e2218f72b18dfab629b1260 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 26 Sep 2019 13:56:48 -0500 Subject: [PATCH 01/20] spiffs erase #949 --- WiFiManager.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index f3e94d9..854086f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1922,10 +1922,21 @@ bool WiFiManager::erase(bool opt){ DEBUG_WM(DEBUG_VERBOSE,"nvs_flash_erase: ", err!=ESP_OK ? (String)err : "Success"); return err == ESP_OK; } + #elif defined(ESP8266) && defined(spiffs_api_h) + if(opt){ + bool ret = false; + if(SPIFFS.begin()){ + DEBUG_WM("Erasing SPIFFS"); + bool ret = SPIFFS.format(); + DEBUG_WM(DEBUG_VERBOSE,"spiffs erase: ",ret ? "Success" : "ERROR"); + } else DEBUG_WM("[ERROR] Could not start SPIFFS"); + return ret; + } #else (void)opt; #endif + DEBUG_WM("Erasing WiFi Config"); return WiFi_eraseConfig(); } From 7d7e228b9ebb400a725c2f53788a93a1a4218b9f Mon Sep 17 00:00:00 2001 From: Brian vanderbusch Date: Sun, 27 Oct 2019 15:05:57 -0500 Subject: [PATCH 02/20] Add PlatformIO installation docs --- README.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fb03403..e28d960 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ First attempt at a library. Lots more changes and fixes to do. Contributions are - Installing - [Arduino - Through Library Manager](#install-through-library-manager) - [Arduino - From Github](#checkout-from-github) - - [PlatformIO] + - [PlatformIO](#install-using-platformio) - [Using](#using) - [Documentation](#documentation) - [Access Point Password](#password-protect-the-configuration-access-point) @@ -147,6 +147,31 @@ While in AP mode, connect to it then open a browser to the gateway IP, default 1 Also see [examples](https://github.com/tzapu/WiFiManager/tree/master/examples). +#### Install Using PlatformIO + +[PlatformIO](https://platformio.org/) is an emerging ecosystem for IoT development, and +is an alternative to using the Arduino IDE. Install `WiFiManager` +using the platformio [library manager](https://docs.platformio.org/en/latest/librarymanager/index.htm) in your editor, +or using the [PlatformIO Core CLI](https://docs.platformio.org/en/latest/userguide/demo.html#library-manager), +or by adding it to your `platformio.ini` as shown below (recommended approach). + +The simplest way is to open the `platformio.ini` file at the root of your project, and `WifiManager` to the common top-level env +`lib_deps` key like so: + +``` +[env] +lib_deps = + WiFiManager +``` + +If you want to install the development branch, then you'll need to use the `repository#tag` format instead: + +``` +[env] +lib_deps = + https://github.com/tzapu/WiFiManager.git#development +``` + ## Documentation #### Password protect the configuration Access Point From a2355889badb09c06f82d05349a4dd1c51ecd4c6 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Wed, 30 Oct 2019 08:55:24 -0500 Subject: [PATCH 03/20] fixes #956 Not tested, not sure if captive portal works with hidden ap, test please. adds wm.setWiFiAPHidden(bool); --- WiFiManager.cpp | 18 ++++++++++++++---- WiFiManager.h | 4 +++- .../OnDemandConfigPortal.ino | 3 +++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 854086f..a959836 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -371,20 +371,21 @@ bool WiFiManager::startAP(){ } // start soft AP with password or anonymous + // default channel is 1 here and in esplib, @todo just change to default remove conditionals if (_apPassword != "") { if(channel>0){ - ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(),channel); + ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(),channel,_apHidden); } else{ - ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str());//password option + ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(),1,_apHidden);//password option } } else { DEBUG_WM(DEBUG_VERBOSE,F("AP has anonymous access!")); if(channel>0){ - ret = WiFi.softAP(_apName.c_str(),"",channel); + ret = WiFi.softAP(_apName.c_str(),"",channel,_apHidden); } else{ - ret = WiFi.softAP(_apName.c_str()); + ret = WiFi.softAP(_apName.c_str(),"",1,_apHidden); } } @@ -2285,6 +2286,15 @@ void WiFiManager::setWiFiAPChannel(int32_t channel){ _apChannel = channel; } +/** + * set the soft ap hidden + * @param bool wifi ap hidden, default is false + */ +void WiFiManager::setWiFiAPHidden(bool hidden){ + _apHidden = hidden; +} + + /** * toggle showing erase wifi config button on info page * @param boolean enabled diff --git a/WiFiManager.h b/WiFiManager.h index b1728b7..e6fa349 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -257,7 +257,8 @@ class WiFiManager void setShowInfoErase(boolean enabled); // set ap channel void setWiFiAPChannel(int32_t channel); - + // set ap hidden + void setWiFiAPHidden(bool hidden); // default false // set custom menu // set custom menu items and order @@ -339,6 +340,7 @@ class WiFiManager bool _disableSTAConn = true; // disable sta when starting ap, if sta is not connected ( stability ) 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 #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 3044d8a..7b5e3ec 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -175,6 +175,9 @@ void setup() { // set channel wm.setWiFiAPChannel(13); + // set AP hidden + // wm.setAPHidden(true); + // set configrportal timeout wm.setConfigPortalTimeout(120); // wm.startConfigPortal("AutoConnectAP", "password"); From e45bdb1831c76da095ec7e5bc232879506c105c7 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 12 Nov 2019 22:54:45 -0600 Subject: [PATCH 04/20] Update WiFiManager.cpp adds more heap debug debug_level DEBUG_MAX to enable #961 #518 --- WiFiManager.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index a959836..f3bcf12 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2453,8 +2453,15 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { if(!_debug || _debugLevel < level) return; if(_debugLevel >= DEBUG_MAX){ - _debugPort.print("MEM: "); - _debugPort.println((String)ESP.getFreeHeap()); + _debugPort.println("MEM: "); + uint32_t free; + uint16_t max; + uint8_t frag; + ESP.getHeapStats(&free, &max, &frag); + _debugPort.printf("[MEM] free: %5d | max: %5d | frag: %3d%% \n", free, max, frag); + // _debugPort.print((String)ESP.getFreeHeap()); + // _debugPort.print((String)ESP.getMaxFreeBlockSize()); + // _debugPort.print((String)ESP.getHeapFragmentation()); } _debugPort.print("*WM: "); if(_debugLevel == DEBUG_DEV) _debugPort.print("["+(String)level+"] "); From 2447a3fd7408c5718997b3fce75cdbcca2b4ce0e Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 12 Nov 2019 22:56:46 -0600 Subject: [PATCH 05/20] oops double debug titles --- WiFiManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index f3bcf12..0c91b70 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2453,7 +2453,6 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { if(!_debug || _debugLevel < level) return; if(_debugLevel >= DEBUG_MAX){ - _debugPort.println("MEM: "); uint32_t free; uint16_t max; uint8_t frag; From fb29462e73ae922543b756a350d248eb5be9b39b Mon Sep 17 00:00:00 2001 From: tablatronix Date: Wed, 13 Nov 2019 09:12:23 -0600 Subject: [PATCH 06/20] add heap frag logging to esp32 --- WiFiManager.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 0c91b70..b62ab09 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2456,11 +2456,24 @@ void WiFiManager::DEBUG_WM(wm_debuglevel_t level,Generic text,Genericb textb) { uint32_t free; 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); + #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. + // largest_free_block; ///< Size of largest free block in the heap. This is the largest malloc-able size. + // minimum_free_bytes; ///< Lifetime minimum free heap size. Equivalent to multi_minimum_free_heap_size(). + // allocated_blocks; ///< Number of (variable size) blocks allocated in the heap. + // free_blocks; ///< Number of (variable size) free blocks in the heap. + // total_blocks; ///< Total number of (variable size) blocks in the heap. + multi_heap_info_t info; + heap_caps_get_info(&info, MALLOC_CAP_INTERNAL); + free = info.total_free_bytes; + max = info.largest_free_block; + frag = 100 - (max * 100) / free; _debugPort.printf("[MEM] free: %5d | max: %5d | frag: %3d%% \n", free, max, frag); - // _debugPort.print((String)ESP.getFreeHeap()); - // _debugPort.print((String)ESP.getMaxFreeBlockSize()); - // _debugPort.print((String)ESP.getHeapFragmentation()); + #endif } _debugPort.print("*WM: "); if(_debugLevel == DEBUG_DEV) _debugPort.print("["+(String)level+"] "); From 768ead409e6297f61e5a32bbae71226262b9f460 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Wed, 13 Nov 2019 22:47:55 -0600 Subject: [PATCH 07/20] add support for build debug flags WM_DEBUG_LEVEL WM_DEBUG_PORT closes #965 --- WiFiManager.cpp | 2 +- WiFiManager.h | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index b62ab09..5755ce4 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -184,7 +184,7 @@ WiFiManager::WiFiManager(Stream& consolePort):_debugPort(consolePort){ WiFiManagerInit(); } -WiFiManager::WiFiManager():WiFiManager(Serial) { +WiFiManager::WiFiManager() { } void WiFiManager::WiFiManagerInit(){ diff --git a/WiFiManager.h b/WiFiManager.h index e6fa349..ded1d4c 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -490,9 +490,22 @@ class WiFiManager } wm_debuglevel_t; boolean _debug = true; - uint8_t _debugLevel = DEBUG_DEV; - Stream& _debugPort; // debug output stream ref + // build debuglevel support + // @todo use DEBUG_ESP_x? + #ifdef WM_DEBUG_LEVEL + uint8_t _debugLevel = (uint8_t)WM_DEBUG_LEVEL; + #else + uint8_t _debugLevel = DEBUG_DEV; // default debug level + #endif + + // @todo use DEBUG_ESP_PORT ? + #ifdef WM_DEBUG_PORT + Stream& _debugPort = WM_DEBUG_PORT; + #else + Stream& _debugPort = Serial; // debug output stream ref + #endif + template void DEBUG_WM(Generic text); From a4993a8441f3062b7bd904dd85005cfc87ebf498 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Wed, 13 Nov 2019 23:10:43 -0600 Subject: [PATCH 08/20] comments --- WiFiManager.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WiFiManager.h b/WiFiManager.h index ded1d4c..57b6c00 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -483,13 +483,13 @@ class WiFiManager // debugging typedef enum { DEBUG_ERROR = 0, - DEBUG_NOTIFY = 1, // default + DEBUG_NOTIFY = 1, // default stable DEBUG_VERBOSE = 2, - DEBUG_DEV = 3, + DEBUG_DEV = 3, // default dev DEBUG_MAX = 4 } wm_debuglevel_t; - boolean _debug = true; + boolean _debug = true; // build debuglevel support // @todo use DEBUG_ESP_x? From d90f6854e97645ec07f5c477a4c9baff4e83b3fd Mon Sep 17 00:00:00 2001 From: tablatronix Date: Wed, 13 Nov 2019 23:11:05 -0600 Subject: [PATCH 09/20] Update OnDemandConfigPortal.ino adds ota to dev example suite --- .../OnDemandConfigPortal.ino | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 7b5e3ec..2591356 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -6,6 +6,14 @@ #include // https://github.com/tzapu/WiFiManager #include +#define USEOTA +// enable OTA +#ifdef USEOTA +#include +#include +bool otastarted = false; +#endif + #define TRIGGER_PIN 0 const char* modes[] = { "NULL", "STA", "AP", "STA+AP" }; @@ -60,10 +68,13 @@ void print_oled(String str,uint8_t size){ } WiFiManager wm; -bool TEST_CP = false; // always start the configportal -bool TEST_NET = true; // do a network test, get ntp time -char ssid[] = "*************"; // your network SSID (name) -char pass[] = "********"; // your network password + +// 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) + +// char ssid[] = "*************"; // your network SSID (name) +// char pass[] = "********"; // your network password void saveWifiCallback(){ Serial.println("[CALLBACK] saveCallback fired"); @@ -100,8 +111,12 @@ 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); + Serial1.begin(115200); + // Serial.setDebugOutput(true); - // delay(3000); + delay(1000); + Serial1.println("TXD1 Enabled"); + Serial.println("\n Starting"); // WiFi.setSleepMode(WIFI_NONE_SLEEP); // disable sleep, can improve ap stability @@ -173,7 +188,7 @@ void setup() { wm.setCountry("US"); // setting wifi country seems to improve OSX soft ap connectivity, may help others as well // set channel - wm.setWiFiAPChannel(13); + // wm.setWiFiAPChannel(13); // set AP hidden // wm.setAPHidden(true); @@ -205,9 +220,22 @@ void setup() { print_oled("Connected\nIP: " + WiFi.localIP().toString() + "\nSSID: " + WiFi.SSID(),1); } pinMode(TRIGGER_PIN, INPUT); + + #ifdef USEOTA + ArduinoOTA.begin(); + ArduinoOTA.onStart([]() { + otastarted = true; + Serial.println("\nOTA onStart"); + }); + #endif } void loop() { + + #ifdef USEOTA + ArduinoOTA.handle(); + if(otastarted)return; + #endif // is configuration portal requested? if ( digitalRead(TRIGGER_PIN) == LOW ) { delay(100); From f93d4449666ce953c6cc62a0124af091a3eef57c Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 14 Nov 2019 00:24:11 -0600 Subject: [PATCH 10/20] remove otaflag probably not needed --- examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino | 6 ------ 1 file changed, 6 deletions(-) diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 2591356..98a3a56 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -11,7 +11,6 @@ #ifdef USEOTA #include #include -bool otastarted = false; #endif #define TRIGGER_PIN 0 @@ -223,10 +222,6 @@ void setup() { #ifdef USEOTA ArduinoOTA.begin(); - ArduinoOTA.onStart([]() { - otastarted = true; - Serial.println("\nOTA onStart"); - }); #endif } @@ -234,7 +229,6 @@ void loop() { #ifdef USEOTA ArduinoOTA.handle(); - if(otastarted)return; #endif // is configuration portal requested? if ( digitalRead(TRIGGER_PIN) == LOW ) { From 22e35b2a03bc412deff395cf9b17d0a6047fa6d7 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 14 Nov 2019 00:37:41 -0600 Subject: [PATCH 11/20] #667 remove compile warning Still not sure what the issue was here. --- WiFiManager.cpp | 6 +++--- strings_en.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 5755ce4..cd31ff2 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2638,9 +2638,9 @@ bool WiFiManager::WiFiSetCountry(){ #elif defined(ESP8266) // if(WiFi.getMode() == WIFI_OFF); // exception if wifi not init! - if(_wificountry == "US") ret = wifi_set_country(&WM_COUNTRY_US); - else if(_wificountry == "JP") ret = wifi_set_country(&WM_COUNTRY_JP); - else if(_wificountry == "CN") ret = wifi_set_country(&WM_COUNTRY_CN); + 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); + else if(_wificountry == "CN") ret = wifi_set_country((wifi_country_t*)&WM_COUNTRY_CN); else DEBUG_WM(DEBUG_ERROR,"[ERROR] country code not found"); #endif diff --git a/strings_en.h b/strings_en.h index 1d17d90..f33dd60 100644 --- a/strings_en.h +++ b/strings_en.h @@ -353,9 +353,9 @@ const wifi_country_t WM_COUNTRY_JP{"JP",1,14,CONFIG_ESP32_PHY_MAX_TX_POWER,WIFI_ // uint8_t nchan; /**< total channel number */ // uint8_t policy; /**< country policy */ // } wifi_country_t; -static wifi_country_t WM_COUNTRY_US{"US",1,11,WIFI_COUNTRY_POLICY_AUTO}; -static wifi_country_t WM_COUNTRY_CN{"CN",1,13,WIFI_COUNTRY_POLICY_AUTO}; -static wifi_country_t WM_COUNTRY_JP{"JP",1,14,WIFI_COUNTRY_POLICY_AUTO}; +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 #endif \ No newline at end of file From 56ad40d083589f2438a3ebfd619197b2d9b17e2e Mon Sep 17 00:00:00 2001 From: tablatronix Date: Sun, 17 Nov 2019 12:20:30 -0600 Subject: [PATCH 12/20] Fixes #970 I broke constructor --- WiFiManager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index cd31ff2..6af090b 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -185,6 +185,7 @@ WiFiManager::WiFiManager(Stream& consolePort):_debugPort(consolePort){ } WiFiManager::WiFiManager() { + WiFiManagerInit(); } void WiFiManager::WiFiManagerInit(){ From 72bcbd8a807157d9a5db5ca0b0123be84dbcd1f5 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 29 Nov 2019 18:32:10 -0600 Subject: [PATCH 13/20] fixes #974 password placeholder showPassword() optional --- WiFiManager.cpp | 18 ++++++++++++++++++ WiFiManager.h | 3 +++ .../OnDemandConfigPortal.ino | 7 +++++-- strings_en.h | 4 ++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 6af090b..6844b27 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -974,6 +974,13 @@ void WiFiManager::handleWifi(boolean scan) { pitem = FPSTR(HTTP_FORM_WIFI); pitem.replace(FPSTR(T_v), WiFi_SSID()); + + if(_showPassword){ + pitem.replace(FPSTR(T_p), WiFi_psk()); + } + else { + pitem.replace(FPSTR(T_p),FPSTR(S_passph)); + } page += pitem; page += getStaticOut(); @@ -2195,6 +2202,17 @@ void WiFiManager::setShowDnsFields(boolean alwaysShow){ _staShowDns = alwaysShow ? 1 : 0; } +/** + * toggle showing password in wifi password field + * if not enabled, placeholder will be S_passph + * @since $dev + * @access public + * @param boolean alwaysShow [false] + */ +void WiFiManager::setShowPassword(boolean show){ + _showPassword = show; +} + /** * toggle captive portal * if enabled, then devices that use captive portal checks will be redirected to root diff --git a/WiFiManager.h b/WiFiManager.h index 57b6c00..9af9c03 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -239,6 +239,8 @@ class WiFiManager void setShowStaticFields(boolean alwaysShow); //if true, always show static dns, esle only show if set via setSTAStaticIPConfig void setShowDnsFields(boolean alwaysShow); + // toggle showing the saved wifi password in wifi form, could be a security issue. + void setShowPassword(boolean show); //if false, disable captive portal redirection void setCaptivePortalEnable(boolean enabled); //if false, timeout captive portal even if a STA client connected to softAP (false), suggest disabling if captiveportal is open @@ -355,6 +357,7 @@ class WiFiManager int _staShowStaticFields = 0; // ternary 1=always show static ip fields, 0=only if set, -1=never(cannot change ips via web!) int _staShowDns = 0; // ternary 1=always show dns, 0=only if set, -1=never(cannot change dns via web!) boolean _removeDuplicateAPs = true; // remove dup aps from wifiscan + boolean _showPassword = false; // show or hide saved password on wifi form, might be a security issue! boolean _shouldBreakAfterConfig = false; // stop configportal on save failure boolean _configPortalIsBlocking = true; // configportal enters blocking loop boolean _enableCaptivePortal = true; // enable captive portal redirection diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 98a3a56..1e37d80 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -192,6 +192,9 @@ void setup() { // set AP hidden // wm.setAPHidden(true); + // show password publicly! + // wm.setShowPassword(true); + // set configrportal timeout wm.setConfigPortalTimeout(120); // wm.startConfigPortal("AutoConnectAP", "password"); @@ -202,7 +205,7 @@ void setup() { //and goes into a blocking loop awaiting configuration print_oled(F("Connecting..."),2); - if(!wm.autoConnect("AutoConnectAP")) { + if(!wm.autoConnect("WM_AutoConnectAP")) { Serial.println("failed to connect and hit timeout"); print_oled("Not Connected",2); } @@ -211,7 +214,7 @@ void setup() { Serial.println("TEST_CP ENABLED"); // start configportal always wm.setConfigPortalTimeout(60); - wm.startConfigPortal(); + wm.startConfigPortal("WM_ConnectAP"); } else { //if you get here you have connected to the WiFi diff --git a/strings_en.h b/strings_en.h index f33dd60..d138770 100644 --- a/strings_en.h +++ b/strings_en.h @@ -47,7 +47,7 @@ const char HTTP_ITEM[] PROGMEM = "
{v} {R} {r}% {q} {e}
"; // test all tokens const char HTTP_FORM_START[] PROGMEM = "
"; -const char HTTP_FORM_WIFI[] PROGMEM = "
"; +const char HTTP_FORM_WIFI[] PROGMEM = "
"; const char HTTP_FORM_WIFI_END[] PROGMEM = ""; const char HTTP_FORM_STATIC_HEAD[] PROGMEM = "

"; const char HTTP_FORM_END[] PROGMEM = "

"; @@ -189,7 +189,7 @@ const char S_disable[] PROGMEM = "Disabled"; const char S_GET[] PROGMEM = "GET"; const char S_POST[] PROGMEM = "POST"; const char S_NA[] PROGMEM = "Unknown"; - +const char S_passph[] PROGMEM = "********"; const char S_titlewifisaved[] PROGMEM = "Credentials Saved"; const char S_titlewifi[] PROGMEM = "Config ESP"; const char S_titleinfo[] PROGMEM = "Info"; From 9d6ce13b92f889c803cf9fe6b5d9ea90dce269cc Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 29 Nov 2019 19:29:56 -0600 Subject: [PATCH 14/20] fix for #740 confusion --- WiFiManager.cpp | 12 +++++++++--- .../OnDemandConfigPortal/OnDemandConfigPortal.ino | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 6844b27..a34a28a 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -624,7 +624,7 @@ uint8_t WiFiManager::processConfigPortal(){ // skip wifi if no ssid if(_ssid == ""){ - DEBUG_WM(DEBUG_VERBOSE,F("No ssid, skipping wifi")); + DEBUG_WM(DEBUG_VERBOSE,F("No ssid, skipping wifi save")); } else{ // attempt sta connection to submitted _ssid, _pass @@ -1335,8 +1335,6 @@ void WiFiManager::handleWifiSave() { _ssid = server->arg(F("s")).c_str(); _pass = server->arg(F("p")).c_str(); - if(_paramsInWifi) doParamSave(); - if (server->arg(FPSTR(S_ip)) != "") { //_sta_static_ip.fromString(server->arg(FPSTR(S_ip)); String ip = server->arg(FPSTR(S_ip)); @@ -1359,6 +1357,14 @@ void WiFiManager::handleWifiSave() { DEBUG_WM(DEBUG_DEV,F("static DNS:"),dns); } + if(_paramsInWifi){ + if(_ssid == ""){ + handleParamSave(); // send param save result and not wifi connect if no wifi creds + return; + } + else doParamSave(); + } + String page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved page += FPSTR(HTTP_SAVED); page += FPSTR(HTTP_END); diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 1e37d80..d9582d4 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -199,6 +199,8 @@ void setup() { wm.setConfigPortalTimeout(120); // wm.startConfigPortal("AutoConnectAP", "password"); + // 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 //here "AutoConnectAP" From 7882c0e9a9af6e5b814c2449fb72016675125258 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 29 Nov 2019 19:54:02 -0600 Subject: [PATCH 15/20] fixes #975 --- WiFiManager.cpp | 14 +++++++++++++- WiFiManager.h | 3 +++ .../OnDemandConfigPortal/OnDemandConfigPortal.ino | 4 +++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index a34a28a..90b2d41 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1031,7 +1031,7 @@ String WiFiManager::getMenuOut(){ String page; for(auto menuId :_menuIds ){ - if(((String)menuId == "param") && (_paramsCount == 0)) continue; // no params set, omit params + if(((String)menuId == "param") && (_paramsCount == 0)) continue; // no params set, omit params from menu, @todo this may be undesired by someone page += HTTP_PORTAL_MENU[menuId]; } @@ -2375,6 +2375,18 @@ 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 + * @param bool enable + * @since $dev + */ +void WiFiManager::setParamsPage(bool enable){ + _paramsInWifi= false; + _menuIdsDefault = {"wifi","param","info","exit"}; + setMenu(_menuIdsDefault); +} + // GETTERS /** diff --git a/WiFiManager.h b/WiFiManager.h index 9af9c03..9691135 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -266,6 +266,9 @@ class WiFiManager // set custom menu items and order void setMenu(std::vector& menu); void setMenu(const char* menu[], uint8_t size); + + // add params to its own menu page and remove from wifi, NOT TO BE COMBINED WITH setMenu! + void setParamsPage(bool enable); // get last connection result, includes autoconnect and wifisave uint8_t getLastConxResult(); diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index d9582d4..4eff3b7 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -172,8 +172,10 @@ 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 + // set static sta ip // wm.setSTAStaticIPConfig(IPAddress(10,0,1,99), IPAddress(10,0,1,1), IPAddress(255,255,255,0)); // wm.setShowStaticFields(false); From 636027cabcff391411397b99e7e0606e1a939e77 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 29 Nov 2019 20:04:31 -0600 Subject: [PATCH 16/20] rework #974 make compatible with params page --- WiFiManager.cpp | 20 ++++++++++--------- .../OnDemandConfigPortal.ino | 4 ++-- strings_en.h | 1 + 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 90b2d41..ce72e44 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1335,6 +1335,8 @@ void WiFiManager::handleWifiSave() { _ssid = server->arg(F("s")).c_str(); _pass = server->arg(F("p")).c_str(); + if(_paramsInWifi) doParamSave(); + if (server->arg(FPSTR(S_ip)) != "") { //_sta_static_ip.fromString(server->arg(FPSTR(S_ip)); String ip = server->arg(FPSTR(S_ip)); @@ -1357,16 +1359,16 @@ void WiFiManager::handleWifiSave() { DEBUG_WM(DEBUG_DEV,F("static DNS:"),dns); } - if(_paramsInWifi){ - if(_ssid == ""){ - handleParamSave(); // send param save result and not wifi connect if no wifi creds - return; - } - else doParamSave(); - } + String page; - String page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved - page += FPSTR(HTTP_SAVED); + if(_ssid == ""){ + page = getHTTPHead(FPSTR(S_titlewifisettings)); // @token titleparamsaved + page += FPSTR(HTTP_PARAMSAVED); + } + else { + String page = getHTTPHead(FPSTR(S_titlewifisaved)); // @token titlewifisaved + page += FPSTR(HTTP_SAVED); + } page += FPSTR(HTTP_END); server->sendHeader(FPSTR(HTTP_HEAD_CL), String(page.length())); diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index 4eff3b7..2276596 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -172,9 +172,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 + // 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)); diff --git a/strings_en.h b/strings_en.h index d138770..bce2ebd 100644 --- a/strings_en.h +++ b/strings_en.h @@ -191,6 +191,7 @@ const char S_POST[] PROGMEM = "POST"; const char S_NA[] PROGMEM = "Unknown"; const char S_passph[] PROGMEM = "********"; const char S_titlewifisaved[] PROGMEM = "Credentials Saved"; +const char S_titlewifisettings[] PROGMEM = "Settings Saved"; const char S_titlewifi[] PROGMEM = "Config ESP"; const char S_titleinfo[] PROGMEM = "Info"; const char S_titleparam[] PROGMEM = "Setup"; From 0fd0c332229ab82cce060d7318c42def65a549b5 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Fri, 29 Nov 2019 20:06:41 -0600 Subject: [PATCH 17/20] remove serial1 --- 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 2276596..bc0ea84 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -110,11 +110,11 @@ 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); - Serial1.begin(115200); + // Serial1.begin(115200); // Serial.setDebugOutput(true); delay(1000); - Serial1.println("TXD1 Enabled"); + // Serial1.println("TXD1 Enabled"); Serial.println("\n Starting"); // WiFi.setSleepMode(WIFI_NONE_SLEEP); // disable sleep, can improve ap stability From 351761b9a76b470ded364a9743234c4c3794ac89 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 3 Dec 2019 22:15:03 -0600 Subject: [PATCH 18/20] travis failing shrug `home/travis/.arduino15/packages/esp8266/hardware/esp8266/2.6.0/cores/esp8266/debug.h:8:26: error: '::printf' has not been declared` --- 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 bc0ea84..da0f8f7 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -5,10 +5,12 @@ */ #include // https://github.com/tzapu/WiFiManager #include +#include #define USEOTA // enable OTA #ifdef USEOTA +#include #include #include #endif From 12fde678e51547126f48b7d071704ef1e92e1632 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 3 Dec 2019 22:55:59 -0600 Subject: [PATCH 19/20] bump arduino ide --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7da81e4..cc63c55 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,9 @@ before_install: - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16" - sleep 3 - export DISPLAY=:1.0 - - wget http://downloads.arduino.cc/arduino-1.8.8-linux64.tar.xz - - tar xf arduino-1.8.8-linux64.tar.xz - - sudo mv arduino-1.8.8 /usr/local/share/arduino + - wget http://downloads.arduino.cc/arduino-1.8.10-linux64.tar.xz + - tar xf arduino-1.8.10-linux64.tar.xz + - sudo mv arduino-1.8.10 /usr/local/share/arduino - sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino install: From c9665adfaf4ef604e1926ab9a672cce2f485627a Mon Sep 17 00:00:00 2001 From: tablatronix Date: Tue, 3 Dec 2019 23:00:40 -0600 Subject: [PATCH 20/20] oops remove mdns test --- examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino index da0f8f7..58f5e9e 100644 --- a/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/DEV/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -10,7 +10,6 @@ #define USEOTA // enable OTA #ifdef USEOTA -#include #include #include #endif