From 278c57b4ecc7c8c96160d6463a32e3b2d6bfd548 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Mon, 28 Mar 2022 08:23:16 -0500 Subject: [PATCH 1/4] fixes #1379 --- WiFiManager.cpp | 1 + WiFiManager.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 1f1629a..703283e 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -516,6 +516,7 @@ bool WiFiManager::startAP(){ */ void WiFiManager::startWebPortal() { if(configPortalActive || webPortalActive) return; + connect = abort = false; setupConfigPortal(); webPortalActive = true; } diff --git a/WiFiManager.h b/WiFiManager.h index 15e48e7..9e696c8 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -646,8 +646,8 @@ class WiFiManager String getInfoData(String id); // flags - boolean connect; - boolean abort; + boolean connect = false; + boolean abort = false; boolean reset = false; boolean configPortalActive = false; boolean webPortalActive = false; From ea4ee025f2bd221610aaaab54042d581905b8d2f Mon Sep 17 00:00:00 2001 From: John Date: Mon, 28 Mar 2022 21:41:08 -0400 Subject: [PATCH 2/4] Output "Unknown" if Arduino/ESP-IDF version is unknown (#1382) Closes #1381 --- WiFiManager.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.h b/WiFiManager.h index 9e696c8..54affb6 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -66,10 +66,10 @@ // #pragma message "ESP_ARDUINO_VERSION_PATCH = " STRING(ESP_ARDUINO_VERSION_PATCH) #define VER_ARDUINO_STR STRING(ESP_ARDUINO_VERSION_MAJOR) "." STRING(ESP_ARDUINO_VERSION_MINOR) "." STRING(ESP_ARDUINO_VERSION_PATCH) #else - #include + // #include // #pragma message "ESP_ARDUINO_VERSION_GIT = " STRING(ARDUINO_ESP32_GIT_VER)// 0x46d5afb1 // #pragma message "ESP_ARDUINO_VERSION_DESC = " STRING(ARDUINO_ESP32_GIT_DESC) // 1.0.6 - #define VER_ARDUINO_STR STRING(ARDUINO_ESP32_GIT_DESC) + #define VER_ARDUINO_STR "Unknown" // #pragma message "ESP_ARDUINO_VERSION_REL = " STRING(ARDUINO_ESP32_RELEASE) //"1_0_6" #endif From 88b97c7caab44926e21d789495e55bcf7e19b333 Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Tue, 29 Mar 2022 13:31:41 -0500 Subject: [PATCH 3/4] #1383 fix --- WiFiManager.cpp | 2 +- WiFiManager.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 703283e..16676f2 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -3674,7 +3674,7 @@ void WiFiManager::WiFi_autoReconnect(){ DEBUG_WM(DEBUG_VERBOSE,F("ESP32 event handler enabled")); #endif using namespace std::placeholders; - wm_event_id = WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2)); + if(wm_event_id !=0) wm_event_id = WiFi.onEvent(std::bind(&WiFiManager::WiFiEvent,this,_1,_2)); // } #endif } diff --git a/WiFiManager.h b/WiFiManager.h index 9e696c8..cb88c40 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -481,7 +481,7 @@ class WiFiManager bool _allowExit = true; // allow exit non blocking #ifdef ESP32 - wifi_event_id_t wm_event_id; + wifi_event_id_t wm_event_id = 0; static uint8_t _lastconxresulttmp; // tmp var for esp32 callback #endif From 6a85acdf8531ca8745391d6b15cdd1130076acac Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Tue, 29 Mar 2022 13:34:58 -0500 Subject: [PATCH 4/4] add customMenuHTML --- WiFiManager.cpp | 20 ++++++++++++++++--- WiFiManager.h | 10 +++++++--- .../OnDemandConfigPortal.ino | 15 +++++++++++--- strings_en.h | 7 ++++--- 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 16676f2..2cf0464 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -1383,6 +1383,10 @@ String WiFiManager::getMenuOut(){ for(auto menuId :_menuIds ){ if((String)_menutokens[menuId] == "param" && _paramsCount == 0) continue; // no params set, omit params from menu, @todo this may be undesired by someone, use only menu to force? + if((String)_menutokens[menuId] == "custom" && _customMenuHTML!=NULL){ + page += _customMenuHTML; + continue; + } page += HTTP_PORTAL_MENU[menuId]; } @@ -2733,12 +2737,22 @@ void WiFiManager::setPreOtaUpdateCallback( std::function func ) { /** * set custom head html - * custom element will be added to head, eg. new style tag etc. + * custom element will be added to head, eg. new meta,style,script tag etc. * @access public * @param char element */ -void WiFiManager::setCustomHeadElement(const char* element) { - _customHeadElement = element; +void WiFiManager::setCustomHeadElement(const char* html) { + _customHeadElement = html; +} + +/** + * set custom menu html + * custom element will be added to menu under custom menu item. + * @access public + * @param char element + */ +void WiFiManager::setCustomMenuHTML(const char* html) { + _customMenuHTML = html; } /** diff --git a/WiFiManager.h b/WiFiManager.h index cb88c40..edf7b8d 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -295,9 +295,12 @@ class WiFiManager // setConfigPortalTimeout is ignored in this mode, user is responsible for closing configportal void setConfigPortalBlocking(boolean shouldBlock); + //add custom html at inside for all pages + void setCustomHeadElement(const char* html); + //if this is set, customise style - void setCustomHeadElement(const char* element); - + void setCustomMenuHTML(const char* html); + //if this is true, remove duplicated Access Points - defaut true void setRemoveDuplicateAPs(boolean removeDuplicates); @@ -510,7 +513,8 @@ class WiFiManager boolean _enableConfigPortal = true; // use config portal if autoconnect failed String _hostname = ""; // hostname for esp8266 for dhcp, and or MDNS - const char* _customHeadElement = ""; // store custom head element html from user + const char* _customHeadElement = ""; // store custom head element html from user isnide + const char* _customMenuHTML = ""; // store custom head element html from user inside <> String _bodyClass = ""; // class to add to body String _title = FPSTR(S_brand); // app title - default WiFiManager diff --git a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino index be43158..8456639 100644 --- a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -23,7 +23,7 @@ WiFiManager wm; // TEST OPTION FLAGS -bool TEST_CP = false; // always start the configportal, even if ap found +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) @@ -90,6 +90,7 @@ void setup() { // wm.erase(); // setup some parameters + 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); @@ -143,6 +144,14 @@ void setup() { custom_html.setValue("test",4); custom_token.setValue("test",4); + // set custom html head content , inside + const char* headhtml = ""; + wm.setCustomHeadElement(headhtml); + + // set custom html menu content , inside + const char* menuhtml = "

\n"; + wm.setCustomMenuHTML(menuhtml); + // invert theme, dark wm.setDarkMode(true); @@ -155,7 +164,7 @@ void setup() { wm.setMenu(menu,9); // custom menu array must provide length */ - std::vector menu = {"wifi","wifinoscan","info","param","close","sep","erase","update","restart","exit"}; + std::vector menu = {"wifi","wifinoscan","info","param","custom","close","sep","erase","update","restart","exit"}; wm.setMenu(menu); // custom menu, pass vector // wm.setParamsPage(true); // move params to seperate page, not wifi, do not combine with setmenu! @@ -242,7 +251,7 @@ void setup() { delay(1000); Serial.println("TEST_CP ENABLED"); wm.setConfigPortalTimeout(TESP_CP_TIMEOUT); - wm.startConfigPortal("WM_ConnectAP"); + wm.startConfigPortal("WM_ConnectAP","12345678"); } else { //if you get here you have connected to the WiFi diff --git a/strings_en.h b/strings_en.h index 12e63bb..c37c38c 100644 --- a/strings_en.h +++ b/strings_en.h @@ -259,8 +259,8 @@ const char D_HR[] PROGMEM = "--------------------"; // ----------------------------------------------------------------------------------------------- // DO NOT EDIT BELOW THIS LINE -const uint8_t _nummenutokens = 10; -const char * const _menutokens[10] PROGMEM = { +const uint8_t _nummenutokens = 11; +const char * const _menutokens[_nummenutokens] PROGMEM = { "wifi", "wifinoscan", "info", @@ -270,7 +270,8 @@ const char * const _menutokens[10] PROGMEM = { "exit", "erase", "update", - "sep" + "sep", + "custom" }; const char R_root[] PROGMEM = "/";