diff --git a/ampel-firmware/src/lib/IotWebConf/src/IotWebConf.cpp b/ampel-firmware/src/lib/IotWebConf/src/IotWebConf.cpp index cacbf071cd16fcdd034942952cffc94344c8d8ec..7ade73d0f3f5bd70bb566c61613625fb6e7d2df6 100644 --- a/ampel-firmware/src/lib/IotWebConf/src/IotWebConf.cpp +++ b/ampel-firmware/src/lib/IotWebConf/src/IotWebConf.cpp @@ -93,13 +93,7 @@ bool IotWebConf::init() this->_apTimeoutMs = atoi(this->_apTimeoutStr) * 1000; // -- Setup mdns -#ifdef ESP8266 - WiFi.hostname(this->_thingName); -#elif defined(ESP32) - WiFi.setHostname(this->_thingName); -#endif #ifdef IOTWEBCONF_CONFIG_USE_MDNS - //TODO: What is _thingName set to at this point?? MDNS.begin(this->_thingName); MDNS.addService("http", "tcp", IOTWEBCONF_CONFIG_USE_MDNS); #endif @@ -729,6 +723,9 @@ void IotWebConf::stateChanged(NetworkState oldState, NetworkState newState) #endif this->_wifiConnectionStart = millis(); WiFi.mode(WIFI_STA); + // Hostname must be set right before WiFi.begin in order to work reliably, + // and will be set only once WiFi.begin has been called. + WiFi.setHostname(this->_thingName); this->_wifiConnectionHandler( this->_wifiAuthInfo.ssid, this->_wifiAuthInfo.password); break;