diff --git a/WiFiManager.cpp b/WiFiManager.cpp index e15b8d5..35a3d5b 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -193,13 +193,26 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { // set hostname before stating if((String)_hostname != ""){ + DEBUG_WM("Setting hostname:",_hostname); bool res = true; #ifdef ESP8266 res = WiFi.hostname(_hostname); + #ifdef ESP8266MDNS_H + DEBUG_WM("Setting MDNS hostname"); + if(MDNS.begin(_hostname)){ + 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 ESP32MDNS_H + DEBUG_WM("Setting MDNS hostname"); + if(MDNS.begin(_hostname)){ + MDNS.addService("http", "tcp", 80); + } + #endif #endif if(!res)DEBUG_WM(F("hostname: set failed!")); @@ -1990,10 +2003,10 @@ bool WiFiManager::WiFi_enableSTA(bool enable) { bool WiFiManager::WiFi_eraseConfig(void) { #ifdef ESP8266 - #ifndef FIXERASECONFIG + #ifndef WM_FIXERASECONFIG return ESP.eraseConfig(); - #else - // erase config BUG polyfill + #else + // erase config BUG replacement // https://github.com/esp8266/Arduino/pull/3635 const size_t cfgSize = 0x4000; size_t cfgAddr = ESP.getFlashChipSize() - cfgSize; diff --git a/WiFiManager.h b/WiFiManager.h index ce615ce..c463062 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -13,7 +13,9 @@ #ifndef WiFiManager_h #define WiFiManager_h -#define WEBSERVERSHIM // use webserver shim lib +#define WM_WEBSERVERSHIM // use webserver shim lib +// #define WM_MDNS // use MDNS +// #define WM_FIXERASECONFIG // use erase flash fix #ifdef ESP8266 @@ -23,6 +25,10 @@ #include #include + #ifdef WM_MDNS + #include + #endif + #define WIFI_getChipId() ESP.getChipId() #define WIFI_AUTH_OPEN ENC_TYPE_NONE @@ -36,7 +42,7 @@ #ifndef WEBSERVER_H #warning "WEBSERVER not implemented in espressif/esp32, see readme notes" - #ifdef WEBSERVERSHIM + #ifdef WM_WEBSERVERSHIM #include #else #include @@ -45,6 +51,9 @@ #endif #endif + #ifdef WM_MDNS + #include + #endif #else #endif @@ -222,6 +231,7 @@ class WiFiManager // defaults const byte DNS_PORT = 53; + const byte HTTP_PORT = 80; String _apName = "no-net"; String _apPassword = ""; String _ssid = "";