Skip to content

Commit

Permalink
WiFi lost STA fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroKorniienko committed Nov 26, 2020
1 parent 768bb7a commit d7917ef
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions EmbUI/wi-fi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,15 @@ void EmbUI::wifi_init(){
} else {
LOG(println, F("STA mode"));
WiFi.mode(WIFI_STA); // we start in STA mode, esp32 can't set client's hotname in ap/sta

LOG(println, F("UI WiFi: STA reconecting..."));
#ifdef ESP8266
WiFi.hostname(hn);
WiFi.begin(); // use internaly stored last known credentials for connection
if(WiFi.begin()!=WL_CONNECTED){ // use internaly stored last known credentials for connection
LOG(println, F("UI WiFi: Can't connect in STA, starting AP..."));
WiFi.disconnect(); // something wrong... starting in AP mode
WiFi.mode(WIFI_AP);
WiFi.begin();
}
#elif defined ESP32
/* this is a weird hack to mitigate DHCP hostname issue
* order of initialization does matter, pls keep it like this till fixed in upstream
Expand All @@ -165,7 +170,6 @@ void EmbUI::wifi_init(){
if (!WiFi.setHostname(hn.c_str()))
LOG(println, F("UI WiFi: Failed to set hostname :("));
#endif
LOG(println, F("UI WiFi: STA reconecting..."));
}
}

Expand Down

0 comments on commit d7917ef

Please sign in to comment.