Fix wifi reconnect
authorEmmanuel Lacour <elacour@easter-eggs.com>
Tue, 5 Apr 2022 16:27:04 +0000 (18:27 +0200)
committerEmmanuel Lacour <elacour@easter-eggs.com>
Tue, 5 Apr 2022 16:27:04 +0000 (18:27 +0200)
garage/garage.ino

index a6c20cc..44f2c49 100644 (file)
@@ -63,9 +63,14 @@ void setup() {
   
   WiFi.mode(WIFI_STA);
   WiFi.begin(WIFI_SSID, WIFI_PASS);
-
+  delay(500);
+  
   while (WiFi.status() != WL_CONNECTED) {
+    WiFi.begin(wifi_ssid, wifi_pass);
     delay(500);
+    if (WiFi.status() != WL_CONNECTED) {
+      delay(2000);
+    }
   }
 
   sensors.begin();
@@ -82,14 +87,12 @@ void loop() {
     fulldata = true;
     previousMillis = millis();   
   
-  // Check wifi connexion
-    if ( WiFi.status() != WL_CONNECTED ) {
-        int retry = 0;
-        WiFi.mode(WIFI_STA);
+    // Reconnect if needed
+    while (WiFi.status() != WL_CONNECTED) {
         WiFi.begin(WIFI_SSID, WIFI_PASS);
-        while (retry < 10 || WiFi.status() != WL_CONNECTED) {
-            retry++;
-            delay(500);
+        delay(500);
+        if (WiFi.status() != WL_CONNECTED) {
+          delay(2000);
         }
     }