From 14aeb7575f04225feb826badfc85c9fb4ceebc5d Mon Sep 17 00:00:00 2001 From: tablatronix <807787+tablatronix@users.noreply.github.com> Date: Fri, 24 Jun 2022 23:44:03 -0500 Subject: [PATCH] Fix hostname for esp8266, needs to run after sta ughh --- WiFiManager.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index bff08a1..6ca3018 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -277,9 +277,11 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { // sethostname before wifi ready // https://github.com/tzapu/WiFiManager/issues/1403 + #ifdef ESP32 if(_hostname != ""){ setupHostname(true); } + #endif // attempt to connect using saved settings, on fail fallback to AP config portal if(!WiFi.enableSTA(true)){ @@ -303,10 +305,11 @@ boolean WiFiManager::autoConnect(char const *apName, char const *apPassword) { // so we must force it on else, if not connectimeout then waitforconnectionresult gets stuck endless loop WiFi_autoReconnect(); - // set hostname before stating - // if(_hostname != ""){ - // setupHostname(true); - // } + #ifdef ESP8266 + if(_hostname != ""){ + setupHostname(true); + } + #endif // if already connected, or try stored connect // @note @todo ESP32 has no autoconnect, so connectwifi will always be called unless user called begin etc before