diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 1f1a3d6..2013694 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -326,11 +326,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { if((String)_hostname != ""){ #ifdef WM_DEBUG_LEVEL - #ifdef ESP8266 - DEBUG_WM(DEBUG_DEV,F("hostname: STA: "),WiFi.hostname()); - #elif defined(ESP32) - DEBUG_WM(DEBUG_DEV,F("hostname: STA: "),WiFi.getHostname()); - #endif + DEBUG_WM(DEBUG_DEV,F("hostname: STA: "),getWiFiHostname()); #endif } return true; // connected success @@ -1196,9 +1192,10 @@ void WiFiManager::handleRoot() { #endif if (captivePortal()) return; // If captive portal redirect instead of displaying the page handleRequest(); - String page = getHTTPHead(FPSTR(S_options)); // @token options @todo replace options with title - String str = FPSTR(HTTP_ROOT_MAIN); - str.replace(FPSTR(T_v),configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading + String page = getHTTPHead(_title); // @token options @todo replace options with title + String str = FPSTR(HTTP_ROOT_MAIN); // @todo custom title + str.replace(FPSTR(T_t),_title); + str.replace(FPSTR(T_v),configPortalActive ? _apName : (getWiFiHostname() + " - " + WiFi.localIP().toString())); // use ip if ap is not active for heading @todo use hostname? page += str; page += FPSTR(HTTP_PORTAL_OPTIONS); page += getMenuOut(); @@ -2805,6 +2802,23 @@ bool WiFiManager::getWebPortalActive(){ return webPortalActive; } + +String WiFiManager::getWiFiHostname(){ + #ifdef ESP32 + return (String)WiFi.getHostname(); + #else + return (String)WiFi.hostname(); + #endif +} + +/** + * [setTitle description] + * @param String title, set app title + */ +void WiFiManager::setTitle(String title){ + _title = title; +} + /** * set menu items and order * if param is present in menu , params will be removed from wifi page automatically @@ -3489,9 +3503,9 @@ void WiFiManager::handleUpdate() { DEBUG_WM(DEBUG_VERBOSE,F("<- Handle update")); #endif if (captivePortal()) return; // If captive portal redirect instead of displaying the page - String page = getHTTPHead(FPSTR(S_options)); // @token options + String page = getHTTPHead(_title); // @token options String str = FPSTR(HTTP_ROOT_MAIN); - str.replace(FPSTR(T_v), configPortalActive ? _apName : WiFi.localIP().toString()); // use ip if ap is not active for heading + str.replace(FPSTR(T_v), configPortalActive ? _apName : (getWiFiHostname() + " - " + WiFi.localIP().toString())); // use ip if ap is not active for heading page += str; page += FPSTR(HTTP_UPDATE); diff --git a/WiFiManager.h b/WiFiManager.h index 94f764b..9729fab 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -317,6 +317,9 @@ class WiFiManager void setMenu(std::vector& menu); void setMenu(const char* menu[], uint8_t size); + // set the webapp title, default WiFiManager + void setTitle(String title); + // add params to its own menu page and remove from wifi, NOT TO BE COMBINED WITH setMenu! void setParamsPage(bool enable); @@ -371,6 +374,10 @@ class WiFiManager // to preload autoconnect for test fixtures or other uses that skip esp sta config bool preloadWiFi(String ssid, String pass); + // get hostname helper + String getWiFiHostname(); + + std::unique_ptr dnsServer; #if defined(ESP32) && defined(WM_WEBSERVERSHIM) @@ -462,6 +469,7 @@ class WiFiManager const char* _customHeadElement = ""; // store custom head element html from user String _bodyClass = ""; // class to add to body + String _title = FPSTR(S_brand); // app title - default WiFiManager // internal options @@ -600,7 +608,7 @@ class WiFiManager } wm_debuglevel_t; boolean _debug = true; - String _debugPrefix = "*wm:"; + String _debugPrefix = FPSTR(S_debugPrefix); wm_debuglevel_t debugLvlShow = DEBUG_VERBOSE; // at which level start showing [n] level tags diff --git a/strings_en.h b/strings_en.h index 39c725e..995cec6 100644 --- a/strings_en.h +++ b/strings_en.h @@ -32,7 +32,7 @@ const char HTTP_SCRIPT[] PROGMEM = "