diff --git a/wled00/wled.cpp b/wled00/wled.cpp index d67f784078..4e831f4469 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -865,6 +865,17 @@ void WLED::handleConnection() #endif const bool wifiConfigured = WLED_WIFI_CONFIGURED; + // The DNS name of the ESP must be set before the first connection to the DHCP server. Otherwise, the esp default name, such as “esp32s3-267D0C,” will be used. GG + #ifdef ARDUINO_ARCH_ESP32 + // Use cmDNS (this is the buffer that holds your name) + if (cmDNS && cmDNS[0] != '\0') { + WiFi.setHostname(cmDNS); + } else { + // Fallback to DEVICE_NAME if cmDNS is still empty + WiFi.setHostname(WLED_HOST_NAME); + } + #endif + // ignore connection handling if WiFi is configured and scan still running // or within first 2s if WiFi is not configured or AP is always active if ((wifiConfigured && multiWiFi.size() > 1 && WiFi.scanComplete() < 0) || (now < 2000 && (!wifiConfigured || apBehavior == AP_BEHAVIOR_ALWAYS)))