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] 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 = "/";