add customMenuHTML

This commit is contained in:
tablatronix
2022-03-29 13:34:58 -05:00
parent 88b97c7caa
commit 6a85acdf85
4 changed files with 40 additions and 12 deletions
+17 -3
View File
@@ -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<void()> 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;
}
/**
+7 -3
View File
@@ -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 <head> 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 <head>
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
@@ -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("<p style=\"color:pink;font-weight:Bold;\">This Is Custom HTML</p>"); // 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 <head>
const char* headhtml = "<meta name='color-scheme' content='dark light'><style></style><script></script>";
wm.setCustomHeadElement(headhtml);
// set custom html menu content , inside <head>
const char* menuhtml = "<form action='/custom' method='get'><button>Custom</button></form><br/>\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<const char *> menu = {"wifi","wifinoscan","info","param","close","sep","erase","update","restart","exit"};
std::vector<const char *> 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
+4 -3
View File
@@ -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 = "/";