From 368538652d35b2752c2c5e1ee6d80c1b8dc049ea Mon Sep 17 00:00:00 2001 From: Emmanuel Lacour Date: Wed, 22 Dec 2021 22:01:44 +0100 Subject: [PATCH] Fix wifi reconnect --- station-meteo/station-meteo.ino | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/station-meteo/station-meteo.ino b/station-meteo/station-meteo.ino index 589c4bb..5a96ba8 100644 --- a/station-meteo/station-meteo.ino +++ b/station-meteo/station-meteo.ino @@ -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); } } -- 2.11.0