From 7335b64a69115d3f64d58ef5dd61b40e50cbef9d Mon Sep 17 00:00:00 2001 From: Gabriel Sieben Date: Tue, 24 Feb 2026 20:04:40 +0100 Subject: [PATCH] Implement hostname setting for ESP32 WiFi Add hostname configuration for WiFi connection based on cmDNS. --- wled00/wled.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) 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)))