Skip to content

Commit d7917ef

Browse files
WiFi lost STA fix
1 parent 768bb7a commit d7917ef

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

EmbUI/wi-fi.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,15 @@ void EmbUI::wifi_init(){
151151
} else {
152152
LOG(println, F("STA mode"));
153153
WiFi.mode(WIFI_STA); // we start in STA mode, esp32 can't set client's hotname in ap/sta
154-
154+
LOG(println, F("UI WiFi: STA reconecting..."));
155155
#ifdef ESP8266
156156
WiFi.hostname(hn);
157-
WiFi.begin(); // use internaly stored last known credentials for connection
157+
if(WiFi.begin()!=WL_CONNECTED){ // use internaly stored last known credentials for connection
158+
LOG(println, F("UI WiFi: Can't connect in STA, starting AP..."));
159+
WiFi.disconnect(); // something wrong... starting in AP mode
160+
WiFi.mode(WIFI_AP);
161+
WiFi.begin();
162+
}
158163
#elif defined ESP32
159164
/* this is a weird hack to mitigate DHCP hostname issue
160165
* order of initialization does matter, pls keep it like this till fixed in upstream
@@ -165,7 +170,6 @@ void EmbUI::wifi_init(){
165170
if (!WiFi.setHostname(hn.c_str()))
166171
LOG(println, F("UI WiFi: Failed to set hostname :("));
167172
#endif
168-
LOG(println, F("UI WiFi: STA reconecting..."));
169173
}
170174
}
171175

0 commit comments

Comments
 (0)