Skip to content

Commit

Permalink
Reverted WiFi_connect method
Browse files Browse the repository at this point in the history
  • Loading branch information
gskjold committed Oct 17, 2022
1 parent f446dff commit 8ac1e03
Showing 1 changed file with 9 additions and 28 deletions.
37 changes: 9 additions & 28 deletions src/AmsToMqttBridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -991,34 +991,17 @@ void debugPrint(byte *buffer, int start, int length) {
Debug.println("");
}

unsigned long wifiTimeout = WIFI_CONNECTION_TIMEOUT;
unsigned long lastWifiRetry = -WIFI_CONNECTION_TIMEOUT;
void WiFi_connect() {
if(millis() - lastWifiRetry < wifiTimeout) {
delay(50);
return;
}
lastWifiRetry = millis();

if (WiFi.status() != WL_CONNECTED) {
if(WiFi.status() == WL_DISCONNECTED) {
if(millis() - lastWifiRetry < WIFI_CONNECTION_TIMEOUT) {
return;
}
}
if(WiFi.getMode() != WIFI_OFF) {
switch(WiFi.status()) {
case WL_NO_SSID_AVAIL:
debugE("WiFi error, no SSID available");
break;
case WL_CONNECT_FAILED:
debugE("WiFi error, connection failed");
break;
case WL_CONNECTION_LOST:
debugE("WiFi error, connection lost");
break;
#if defined(ESP8266)
case WL_WRONG_PASSWORD:
debugE("WiFi error, wrong password");
break;
#endif
default:
debugE("WiFi error, %d", WiFi.status());
break;
}
if(wifiReconnectCount > 3) {
ESP.restart();
return;
Expand Down Expand Up @@ -1052,13 +1035,11 @@ void WiFi_connect() {
WiFi.softAPdisconnect(true);
WiFi.enableAP(false);
WiFi.mode(WIFI_OFF);
#if defined(ESP8266)
WiFi.forceSleepBegin();
#endif
yield();
wifiTimeout = 5000;
return;
}
lastWifiRetry = millis();
wifiTimeout = WIFI_CONNECTION_TIMEOUT;

WiFiConfig wifi;
if(!config.getWiFiConfig(wifi) || strlen(wifi.ssid) == 0) {
Expand Down

0 comments on commit 8ac1e03

Please sign in to comment.