diff --git a/src/config.default.h b/src/config.default.h index d0dbe8c..a170c2f 100644 --- a/src/config.default.h +++ b/src/config.default.h @@ -22,6 +22,8 @@ #define WIFI_SSID "" // Wi-Fi password (required) #define WIFI_PASSWORD "" +// Wi-Fi hostname (for DHCP, uncomment if non-default desired) +// #define WIFI_HOSTNAME "my_host_name" // Wi-Fi static IPv4 address enabled or disabled (disable for DHCPv4) #define WIFI_IPV4_STATIC false // Wi-Fi static IPv4 address diff --git a/src/src.ino b/src/src.ino index 1bd045c..e7c5046 100644 --- a/src/src.ino +++ b/src/src.ino @@ -44,6 +44,7 @@ void setup_dht_sensor() { } void setup_wifi() { + WiFi.mode(WIFI_STA); char message[128]; snprintf(message, 128, "Wi-Fi SSID: %s", WIFI_SSID); log(message); @@ -70,6 +71,18 @@ void setup_wifi() { } log("Wi-Fi connecting ..."); + #ifdef WIFI_HOSTNAME + snprintf(message, 128, "Initial hostname: %s", WiFi.hostname().c_str()); + log(message); + log("Requesting hostname " WIFI_HOSTNAME); + if (!WiFi.hostname(WIFI_HOSTNAME)) { + log("Hostname request failed"); + } else { + log("Hostname request succeeded"); + } + snprintf(message, 128, "New hostname: %s", WiFi.hostname().c_str()); + log(message); + #endif WiFi.begin(WIFI_SSID, WIFI_PASSWORD); while (WiFi.status() != WL_CONNECTED) { log("Wi-Fi waiting ...", LogLevel::DEBUG);