Fix wifi reconnect
authorEmmanuel Lacour <elacour@easter-eggs.com>
Wed, 22 Dec 2021 21:01:44 +0000 (22:01 +0100)
committerEmmanuel Lacour <elacour@easter-eggs.com>
Wed, 22 Dec 2021 21:01:44 +0000 (22:01 +0100)
station-meteo/station-meteo.ino

index 589c4bb..5a96ba8 100644 (file)
@@ -73,10 +73,15 @@ void setup(void)
   Serial.println(wifi_ssid);
   // Connect to WPA/WPA2 network
   WiFi.begin(wifi_ssid, wifi_pass);
+  delay(500);
 
   // attempt to connect to Wifi network:
   while (WiFi.status() != WL_CONNECTED) {
+    WiFi.begin(wifi_ssid, wifi_pass);
     delay(500);
+    if (WiFi.status() != WL_CONNECTED) {
+        delay(2000);
+    }
   }
 
   Serial.println("Connected to wifi");
@@ -92,13 +97,12 @@ void loop(void)
 { 
   delay(POLL_INT);
   
-  // Check wifi connexion
-  if ( WiFi.status() != WL_CONNECTED ) {
-      int retry = 0;
+  // 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);
       }
   }