mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
#1348 just change _hostname to string ?
This commit is contained in:
+31
-15
@@ -298,7 +298,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
||||
WiFi_autoReconnect();
|
||||
|
||||
// set hostname before stating
|
||||
if((String)_hostname != ""){
|
||||
if(_hostname != ""){
|
||||
setupHostname(true);
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
||||
#endif
|
||||
_lastconxresult = WL_CONNECTED;
|
||||
|
||||
if((String)_hostname != ""){
|
||||
if(_hostname != ""){
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_DEV,F("hostname: STA: "),getWiFiHostname());
|
||||
#endif
|
||||
@@ -358,7 +358,7 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) {
|
||||
}
|
||||
|
||||
bool WiFiManager::setupHostname(bool restart){
|
||||
if((String)_hostname == "") {
|
||||
if(_hostname == "") {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_DEV,F("No Hostname to set"));
|
||||
#endif
|
||||
@@ -366,34 +366,39 @@ bool WiFiManager::setupHostname(bool restart){
|
||||
}
|
||||
else {
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_DEV,F("setupHostname: "),_hostname);
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Setting Hostnames: "),_hostname);
|
||||
#endif
|
||||
}
|
||||
bool res = true;
|
||||
#ifdef ESP8266
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Setting WiFi hostname"));
|
||||
#endif
|
||||
res = WiFi.hostname(_hostname);
|
||||
res = WiFi.hostname(_hostname.c_str());
|
||||
// #ifdef ESP8266MDNS_H
|
||||
#ifdef WM_MDNS
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Setting MDNS hostname, tcp 80"));
|
||||
#endif
|
||||
if(MDNS.begin(_hostname)){
|
||||
if(MDNS.begin(_hostname.c_str())){
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
}
|
||||
#endif
|
||||
#elif defined(ESP32)
|
||||
// @note hostname must be set after STA_START
|
||||
delay(200); // do not remove, give time for STA_START
|
||||
res = WiFi.setHostname(_hostname);
|
||||
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Setting WiFi hostname"));
|
||||
#endif
|
||||
|
||||
res = WiFi.setHostname(_hostname.c_str());
|
||||
// #ifdef ESP32MDNS_H
|
||||
#ifdef WM_MDNS
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Setting MDNS hostname, tcp 80"));
|
||||
#endif
|
||||
if(MDNS.begin(_hostname)){
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("Setting MDNS hostname, tcp 80"));
|
||||
#endif
|
||||
if(MDNS.begin(_hostname.c_str())){
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
}
|
||||
#endif
|
||||
@@ -491,8 +496,8 @@ bool WiFiManager::startAP(){
|
||||
|
||||
// set ap hostname
|
||||
#ifdef ESP32
|
||||
if(ret && (String)_hostname != ""){
|
||||
bool res = WiFi.softAPsetHostname(_hostname);
|
||||
if(ret && _hostname != ""){
|
||||
bool res = WiFi.softAPsetHostname(_hostname.c_str());
|
||||
#ifdef WM_DEBUG_LEVEL
|
||||
DEBUG_WM(DEBUG_VERBOSE,F("setting softAP Hostname:"),_hostname);
|
||||
if(!res)DEBUG_WM(DEBUG_ERROR,F("[ERROR] hostname: AP set failed!"));
|
||||
@@ -2848,6 +2853,12 @@ void WiFiManager::setEnableConfigPortal(boolean enable)
|
||||
* @return bool false if hostname is not valid
|
||||
*/
|
||||
bool WiFiManager::setHostname(const char * hostname){
|
||||
//@todo max length 32
|
||||
_hostname = String(hostname);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WiFiManager::setHostname(String hostname){
|
||||
//@todo max length 32
|
||||
_hostname = hostname;
|
||||
return true;
|
||||
@@ -3020,6 +3031,11 @@ bool WiFiManager::getWiFiIsSaved(){
|
||||
return WiFi_hasAutoConnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* getDefaultAPName
|
||||
* @since $dev
|
||||
* @return string
|
||||
*/
|
||||
String WiFiManager::getDefaultAPName(){
|
||||
String hostString = String(WIFI_getChipId(),HEX);
|
||||
hostString.toUpperCase();
|
||||
|
||||
+2
-1
@@ -318,6 +318,7 @@ class WiFiManager
|
||||
|
||||
// set a custom hostname, sets sta and ap dhcp client id for esp32, and sta for esp8266
|
||||
bool setHostname(const char * hostname);
|
||||
bool setHostname(String hostname);
|
||||
|
||||
// show erase wifi onfig button on info page, true
|
||||
void setShowInfoErase(boolean enabled);
|
||||
@@ -492,7 +493,7 @@ class WiFiManager
|
||||
boolean _showInfoUpdate = true; // info page update button
|
||||
boolean _showBack = false; // show back button
|
||||
boolean _enableConfigPortal = true; // use config portal if autoconnect failed
|
||||
const char * _hostname = ""; // hostname for esp8266 for dhcp, and or MDNS
|
||||
String _hostname = ""; // hostname for esp8266 for dhcp, and or MDNS
|
||||
|
||||
const char* _customHeadElement = ""; // store custom head element html from user
|
||||
String _bodyClass = ""; // class to add to body
|
||||
|
||||
@@ -151,7 +151,8 @@ void setup() {
|
||||
wm.setCountry("US");
|
||||
|
||||
// set Hostname
|
||||
wm.setHostname("WIFIMANAGERTESTING");
|
||||
|
||||
wm.setHostname(("WM_"+wm.getDefaultAPName()).c_str());
|
||||
|
||||
// set custom channel
|
||||
// wm.setWiFiAPChannel(13);
|
||||
|
||||
Reference in New Issue
Block a user