From 2131d86224b9d0b558d908d9ec5c6a1de61d23eb Mon Sep 17 00:00:00 2001 From: pcniatic Date: Sun, 28 Apr 2019 03:19:33 -0400 Subject: [PATCH] [ESP8266/ESP32] Problem setting hostname while on dynamic ip. (#17) 20 - Device does not change from static IP mode correctly 21 - DHCP hostname is not correctly configured (ESP32 & esp8266) --- src/WiFiSettingsService.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/WiFiSettingsService.cpp b/src/WiFiSettingsService.cpp index 05292c8..a9c1296 100644 --- a/src/WiFiSettingsService.cpp +++ b/src/WiFiSettingsService.cpp @@ -64,15 +64,17 @@ void WiFiSettingsService::reconfigureWiFiConnection() { // configure static ip config for station mode (if set) if (_staticIPConfig) { WiFi.config(_localIP, _gatewayIP, _subnetMask, _dnsIP1, _dnsIP2); + } else { // else setting dynamic ip config and hostname +#if defined(ESP8266) + WiFi.config(INADDR_ANY, INADDR_ANY, INADDR_ANY); + WiFi.hostname(_hostname); +#elif defined(ESP_PLATFORM) + WiFi.config(INADDR_NONE, INADDR_NONE, INADDR_NONE); + WiFi.setHostname(_hostname.c_str()); +#endif } // connect to the network -#if defined(ESP8266) - WiFi.hostname(_hostname); -#elif defined(ESP_PLATFORM) - WiFi.setHostname(_hostname.c_str()); -#endif - WiFi.begin(_ssid.c_str(), _password.c_str()); }