diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 79fdf6b..5c14823 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -181,14 +181,17 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { // set hostname before stating if(_hostname != ""){ + bool res = true; #ifdef ESP8266 - WiFi.hostname(_hostname); + res = WiFi.hostname(_hostname); #elif defined(ESP32) // @note hostname must be set after STA_START delay(200); // do not remove, give time for STA_START - WiFi.setHostname(_hostname); + res = WiFi.setHostname(_hostname); #endif + if(!res)DEBUG_WM(F("hostname: set failed!")); + if(WiFi.status() == WL_CONNECTED){ DEBUG_WM(F("reconnecting to set new hostname")); // WiFi.reconnect(); // This does not reset dhcp @@ -203,8 +206,17 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { //connected DEBUG_WM(F("IP Address:"),WiFi.localIP()); _lastconxresult = WL_CONNECTED; + + if(_hostname != ""){ + #ifdef ESP8266 + DEBUG_WM("hostname: STA",WiFi.hostname()); + #elif defined(ESP32) + DEBUG_WM("hostname: STA",WiFi.getHostname()); + #endif + } return true; } + // not connected start configportal return startConfigPortal(apName, apPassword); } @@ -238,8 +250,9 @@ bool WiFiManager::startAP(){ // set ap hostname #ifdef ESP32 if(ret && _hostname != ""){ - WiFi.softAPsetHostname(_hostname); - DEBUG_WM(F("aphostname: "),WiFi.softAPgetHostname()); + bool res = WiFi.softAPsetHostname(_hostname); + if(!res)DEBUG_WM(F("hostname: AP set failed!")); + DEBUG_WM(F("hostname: AP"),WiFi.softAPgetHostname()); } #endif @@ -247,7 +260,7 @@ bool WiFiManager::startAP(){ if ( _apcallback != NULL) { _apcallback(this); } - + return ret; } diff --git a/WiFiManager.h b/WiFiManager.h index d6811a8..73bc94f 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -230,7 +230,7 @@ class WiFiManager boolean _cpClientCheck = false; // keep cp alive if cp have station boolean _webClientCheck = true; // keep cp alive if web have client boolean _scanDispOptions = false; // show percentage in scans not icons - const char * _hostname = ""; + const char * _hostname = "wmtest"; const char* _customHeadElement = ""; // store custom head element html from user