diff --git a/WiFiManager.cpp b/WiFiManager.cpp index ce67e71..2fc81c6 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; } @@ -1382,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 +2738,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; } /** @@ -3674,7 +3689,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 15e48e7..74d678b 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 @@ -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); @@ -481,7 +484,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 @@ -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 @@ -646,8 +650,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; diff --git a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino index 8b44fa3..169a8af 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 = "/";