mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
Add ability to set custom titles, change page header titles
Replaces root WiFiManager title with cusotm as well as page title, Also swaps headers, title first then domain - ip
This commit is contained in:
+24
-10
@@ -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);
|
||||
|
||||
+9
-1
@@ -317,6 +317,9 @@ class WiFiManager
|
||||
void setMenu(std::vector<const char*>& 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> 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
|
||||
|
||||
|
||||
+4
-2
@@ -32,7 +32,7 @@ const char HTTP_SCRIPT[] PROGMEM = "<script>function c(l){"
|
||||
const char HTTP_HEAD_END[] PROGMEM = "</head><body class='{c}'><div class='wrap'>"; // {c} = _bodyclass
|
||||
// example of embedded logo, base64 encoded inline, No styling here
|
||||
// const char HTTP_ROOT_MAIN[] PROGMEM = "<img title=' alt=' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAADQElEQVRoQ+2YjW0VQQyE7Q6gAkgFkAogFUAqgFQAVACpAKiAUAFQAaECQgWECggVGH1PPrRvn3dv9/YkFOksoUhhfzwz9ngvKrc89JbnLxuA/63gpsCmwCADWwkNEji8fVNgotDM7osI/x777x5l9F6JyB8R4eeVql4P0y8yNsjM7KGIPBORp558T04A+CwiH1UVUItiUQmZ2XMReSEiAFgjAPBeVS96D+sCYGaUx4cFbLfmhSpnqnrZuqEJgJnd8cQplVLciAgX//Cf0ToIeOB9wpmloLQAwpnVmAXgdf6pwjpJIz+XNoeZQQZlODV9vhc1Tuf6owrAk/8qIhFbJH7eI3eEzsvydQEICqBEkZwiALfF70HyHPpqScPV5HFjeFu476SkRA0AzOfy4hYwstj2ZkDgaphE7m6XqnoS7Q0BOPs/sw0kDROzjdXcCMFCNwzIy0EcRcOvBACfh4k0wgOmBX4xjfmk4DKTS31hgNWIKBCI8gdzogTgjYjQWFMw+o9LzJoZ63GUmjWm2wGDc7EvDDOj/1IVMIyD9SUAL0WEhpriRlXv5je5S+U1i2N88zdPuoVkeB+ls4SyxCoP3kVm9jsjpEsBLoOBNC5U9SwpGdakFkviuFP1keblATkTENTYcxkzgxTKOI3jyDxqLkQT87pMA++H3XvJBYtsNbBN6vuXq5S737WqHkW1VgMQNXJ0RshMqbbT33sJ5kpHWymzcJjNTeJIymJZtSQd9NHQHS1vodoFoTMkfbJzpRnLzB2vi6BZAJxWaCr+62BC+jzAxVJb3dmmiLzLwZhZNPE5e880Suo2AZgB8e8idxherqUPnT3brBDTlPxO3Z66rVwIwySXugdNd+5ejhqp/+NmgIwGX3Py3QBmlEi54KlwmjkOytQ+iJrLJj23S4GkOeecg8G091no737qvRRdzE+HLALQoMTBbJgBsCj5RSWUlUVJiZ4SOljb05eLFWgoJ5oY6yTyJp62D39jDANoKKcSocPJD5dQYzlFAFZJflUArgTPZKZwLXAnHmerfJquUkKZEgyzqOb5TuDt1P3nwxobqwPocZA11m4A1mBx5IxNgRH21ti7KbAGiyNn3HoF/gJ0w05A8xclpwAAAABJRU5ErkJggg==' /><h1>{v}</h1><h3>WiFiManager</h3>";
|
||||
const char HTTP_ROOT_MAIN[] PROGMEM = "<h1>{v}</h1><h3>WiFiManager</h3>";
|
||||
const char HTTP_ROOT_MAIN[] PROGMEM = "<h1>{t}</h1><h3>{v}</h3>";
|
||||
const char * const HTTP_PORTAL_MENU[] PROGMEM = {
|
||||
"<form action='/wifi' method='get'><button>Configure WiFi</button></form><br/>\n", // MENU_WIFI
|
||||
"<form action='/0wifi' method='get'><button>Configure WiFi (No Scan)</button></form><br/>\n", // MENU_WIFINOSCAN
|
||||
@@ -201,7 +201,9 @@ const char HTTP_INFO_stamac[] PROGMEM = "<dt>Station MAC</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_conx[] PROGMEM = "<dt>Connected</dt><dd>{1}</dd>";
|
||||
const char HTTP_INFO_autoconx[] PROGMEM = "<dt>Autoconnect</dt><dd>{1}</dd>";
|
||||
|
||||
// Strings
|
||||
|
||||
const char S_brand[] PROGMEM = "WiFiManager";
|
||||
const char S_debugPrefix[] PROGMEM = "*wm:";
|
||||
const char S_y[] PROGMEM = "Yes";
|
||||
const char S_n[] PROGMEM = "No";
|
||||
const char S_enable[] PROGMEM = "Enabled";
|
||||
|
||||
Reference in New Issue
Block a user