From c0781ef35a65ce2d419f6606e14cdf733b8df75f Mon Sep 17 00:00:00 2001 From: Brett Christensen Date: Tue, 6 Feb 2024 07:28:19 +1100 Subject: [PATCH 1/9] potential fix for wifi issues --- Software/src/devboard/webserver/webserver.cpp | 116 ++++++++---------- Software/src/devboard/webserver/webserver.h | 9 ++ 2 files changed, 62 insertions(+), 63 deletions(-) diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 039257a6..07354eef 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -36,9 +36,6 @@ const char index_html[] PROGMEM = R"rawliteral( )rawliteral"; -String wifi_state; -bool wifi_connected; - // Wifi connect time declarations and definition unsigned long wifi_connect_start_time; unsigned long wifi_connect_current_time; @@ -46,6 +43,10 @@ unsigned long wifi_connect_timeout = 5000; // Timeout for WiFi connect in mi unsigned long wifi_monitor_loop_time = 30000; // Will check if WiFi is connected and try reconnect every x milliseconds unsigned long last_wifi_monitor_run = 0; +enum WiFiState { DISCONNECTED, CONNECTING, CONNECTED }; + +WiFiState wifi_state = DISCONNECTED; + void init_webserver() { // Configure WiFi if (AccessPointEnabled) { @@ -249,79 +250,54 @@ void init_webserver() { #endif } +// Function to handle WiFi connection void WiFi_monitor_loop() { unsigned long currentMillis = millis(); if (currentMillis - last_wifi_monitor_run > wifi_monitor_loop_time) { last_wifi_monitor_run = currentMillis; - if (WiFi.status() != WL_CONNECTED && wifi_state != "Connecting") { - wifi_connected = false; - wifi_state = "Not connected"; - Serial.print("Wifi disconnected. Attempting reconnection"); - init_WiFi_STA(ssid, password); - } else if (WiFi.status() == WL_CONNECTED && wifi_state != "Connected") { - wifi_connected = true; - wifi_state = "Connected"; + if (WiFi.status() != WL_CONNECTED) { + handle_WiFi_reconnection(currentMillis); + } else if (wifi_state != CONNECTED) { + wifi_state = CONNECTED; Serial.println("Wifi reconnected"); } } } -void init_WiFi_AP() { - Serial.print("Creating Access Point: "); - Serial.println(ssidAP); - Serial.print("With password: "); - Serial.println(passwordAP); - - WiFi.softAP(ssidAP, passwordAP); - - IPAddress IP = WiFi.softAPIP(); - Serial.println("Access Point created."); - Serial.print("IP address: "); - Serial.println(IP); +// Function to handle WiFi disconnection +void handle_WiFi_reconnection(unsigned long currentMillis) { + if (wifi_state == CONNECTING && currentMillis - wifi_connect_start_time > wifi_connect_timeout) { + wifi_state = DISCONNECTED; + Serial.println("Failed to connect to WiFi network: " + String(ssid)); + Serial.println("Please check WiFi network name and password, and if WiFi network is available."); + Serial.println("Will try again in " + String((wifi_monitor_loop_time - (millis() - last_wifi_monitor_run)) / 1000) + + " seconds."); + } else if (wifi_state != CONNECTING) { + wifi_state = DISCONNECTED; + Serial.println("Wifi disconnected. Attempting reconnection"); + init_WiFi_STA(ssid, password); + } } +// Function to initialize WiFi in Station Mode void init_WiFi_STA(const char* ssid, const char* password) { - // If we're already connected, there's nothing to do - if (WiFi.status() == WL_CONNECTED) { - if (wifi_state != "Connected") { - wifi_connected = true; - wifi_state = "Connected"; - // Print local IP address and start web server - Serial.println(""); - Serial.print("Connected to WiFi network: "); - Serial.println(ssid); - Serial.print("IP address: "); - Serial.println(WiFi.localIP()); - } - return; - } - - // If we're not currently trying to connect, start the connection process - if (wifi_state != "Connecting") { - Serial.print("Connecting to: "); - Serial.println(ssid); - WiFi.begin(ssid, password); - wifi_state = "Connecting"; - wifi_connect_start_time = millis(); - return; - } - - // If we've been trying to connect for more than 5000ms, give up - if (millis() - wifi_connect_start_time > wifi_connect_timeout) { - wifi_state = "Not connected"; - Serial.print("Failed to connect to WiFi network: "); - Serial.println(ssid); - Serial.println("Please check WiFi network name and password, and if WiFi network is available."); - Serial.print("Will try again in "); - Serial.print((wifi_monitor_loop_time - (millis() - last_wifi_monitor_run)) / 1000); - Serial.println(" seconds."); - return; - } + Serial.println("Connecting to: " + String(ssid)); + WiFi.begin(ssid, password); + wifi_state = CONNECTING; + wifi_connect_start_time = millis(); +} - // Otherwise, just print a dot to indicate that we're still trying to connect - Serial.print("."); +// Function to initialize WiFi in Access Point Mode +void init_WiFi_AP() { + Serial.println("Creating Access Point: " + String(ssidAP)); + Serial.println("With password: " + String(passwordAP)); + WiFi.softAP(ssidAP, passwordAP); + IPAddress IP = WiFi.softAPIP(); + Serial.println("Access Point created."); + Serial.println("IP address: " + IP.toString()); } +// Function to initialize ElegantOTA void init_ElegantOTA() { ElegantOTA.begin(&server); // Start ElegantOTA // ElegantOTA callbacks @@ -330,6 +306,20 @@ void init_ElegantOTA() { ElegantOTA.onEnd(onOTAEnd); } +// Function to convert WiFiState enum to String +String wifi_state_to_string(WiFiState state) { + switch (state) { + case DISCONNECTED: + return "Disconnected"; + case CONNECTING: + return "Connecting"; + case CONNECTED: + return "Connected"; + default: + return "Unknown"; + } +} + String processor(const String& var) { if (var == "PLACEHOLDER") { String content = ""; @@ -367,8 +357,8 @@ String processor(const String& var) { } // Display ssid of network connected to and, if connected to the WiFi, its own IP content += "

SSID: " + String(ssid) + "

"; - content += "

Wifi status: " + wifi_state + "

"; - if (wifi_connected == true) { + content += "

Wifi status: " + wifi_state_to_string(wifi_state) + "

"; + if (WiFi.status() == WL_CONNECTED) { content += "

IP: " + WiFi.localIP().toString() + "

"; // Get and display the signal strength (RSSI) content += "

Signal Strength: " + String(WiFi.RSSI()) + " dBm

"; diff --git a/Software/src/devboard/webserver/webserver.h b/Software/src/devboard/webserver/webserver.h index f9043c6f..f70f53e2 100644 --- a/Software/src/devboard/webserver/webserver.h +++ b/Software/src/devboard/webserver/webserver.h @@ -90,6 +90,15 @@ void init_WiFi_STA(const char* ssid, const char* password); */ void WiFi_monitor_loop(); +/** + * @brief Function to handle WiFi reconnection. + * + * @param[in] void + * + * @return void + */ +void handle_WiFi_reconnection(unsigned long currentMillis); + /** * @brief Initialization function for ElegantOTA. * From 6f72d0bc401830b05c6b28e3aef20ed4defe83d6 Mon Sep 17 00:00:00 2001 From: Brett Christensen Date: Tue, 6 Feb 2024 07:41:50 +1100 Subject: [PATCH 2/9] drop wifi monitor loop time to 1000 ms --- Software/src/devboard/webserver/webserver.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 07354eef..8f83b199 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -38,9 +38,8 @@ const char index_html[] PROGMEM = R"rawliteral( // Wifi connect time declarations and definition unsigned long wifi_connect_start_time; -unsigned long wifi_connect_current_time; unsigned long wifi_connect_timeout = 5000; // Timeout for WiFi connect in milliseconds -unsigned long wifi_monitor_loop_time = 30000; // Will check if WiFi is connected and try reconnect every x milliseconds +unsigned long wifi_monitor_loop_time = 1000; // Will check if WiFi is connected and try reconnect every x milliseconds unsigned long last_wifi_monitor_run = 0; enum WiFiState { DISCONNECTED, CONNECTING, CONNECTED }; @@ -264,7 +263,7 @@ void WiFi_monitor_loop() { } } -// Function to handle WiFi disconnection +// Function to handle WiFi reconnection void handle_WiFi_reconnection(unsigned long currentMillis) { if (wifi_state == CONNECTING && currentMillis - wifi_connect_start_time > wifi_connect_timeout) { wifi_state = DISCONNECTED; From c485d7a2dedf0dc7473357cb33a9267e0612f2bb Mon Sep 17 00:00:00 2001 From: Brett Christensen Date: Tue, 6 Feb 2024 12:04:57 +1100 Subject: [PATCH 3/9] make it bulletproof --- Software/src/devboard/webserver/webserver.cpp | 138 ++++++++++++------ Software/src/devboard/webserver/webserver.h | 16 +- 2 files changed, 105 insertions(+), 49 deletions(-) diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 8f83b199..22e16038 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -37,14 +37,17 @@ const char index_html[] PROGMEM = R"rawliteral( )rawliteral"; // Wifi connect time declarations and definition -unsigned long wifi_connect_start_time; -unsigned long wifi_connect_timeout = 5000; // Timeout for WiFi connect in milliseconds -unsigned long wifi_monitor_loop_time = 1000; // Will check if WiFi is connected and try reconnect every x milliseconds +const unsigned long MAX_WIFI_RECONNECT_BACKOFF_TIME = 60000; // Maximum backoff time of 1 minute +const unsigned long DEFAULT_WIFI_RECONNECT_BACKOFF_TIME = 1000; // Default wifi reconnect backoff time. Start with 1 second +const unsigned long WIFI_CONNECT_TIMEOUT = 5000; // Timeout for WiFi connect in milliseconds +const unsigned long WIFI_MONITOR_LOOP_TIME = 1000; // Will check if WiFi is connected and try reconnect every x milliseconds unsigned long last_wifi_monitor_run = 0; +unsigned long wifi_connect_start_time; +unsigned long wifi_reconnect_backoff_time = DEFAULT_WIFI_RECONNECT_BACKOFF_TIME; -enum WiFiState { DISCONNECTED, CONNECTING, CONNECTED }; +enum WiFiState { DISCONNECTED, CONNECTING, CONNECTED }; -WiFiState wifi_state = DISCONNECTED; +WiFiState wifi_state = DISCONNECTED; //the esp library has no specific state to indicate if its connecting (only WL_IDLE_STATUS) so we keep track of it here void init_webserver() { // Configure WiFi @@ -249,36 +252,89 @@ void init_webserver() { #endif } -// Function to handle WiFi connection -void WiFi_monitor_loop() { - unsigned long currentMillis = millis(); - if (currentMillis - last_wifi_monitor_run > wifi_monitor_loop_time) { - last_wifi_monitor_run = currentMillis; - if (WiFi.status() != WL_CONNECTED) { - handle_WiFi_reconnection(currentMillis); - } else if (wifi_state != CONNECTED) { - wifi_state = CONNECTED; - Serial.println("Wifi reconnected"); - } +void print_wifi_status_message(wl_status_t status) { + switch (status) { + case WL_CONNECTED: + Serial.println("Connected to WiFi network: " + String(ssid)); + Serial.println("IP address: " + WiFi.localIP().toString()); + Serial.println("Signal Strength: " + String(WiFi.RSSI()) + " dBm"); + break; + case WL_CONNECT_FAILED: + Serial.println("Failed to connect to WiFi network: " + String(ssid)); + break; + case WL_CONNECTION_LOST: + Serial.println("Connection to WiFi network: " + String(ssid) + " lost"); + break; + case WL_DISCONNECTED: + Serial.println("Disconnected from WiFi network: " + String(ssid)); + break; + case WL_NO_SSID_AVAIL: + Serial.println("Could not find network with SSID: " + String(ssid)); + break; + case WL_IDLE_STATUS: + Serial.println("WiFi is in idle status. This can indicate it is currently trying to connect."); + break; + case WL_SCAN_COMPLETED: + Serial.println("WiFi scan completed"); + break; + case WL_NO_SHIELD: + Serial.println("No WiFi shield detected"); + break; + default: + Serial.println("Unknown WiFi status: " + String(status)); + break; } } -// Function to handle WiFi reconnection -void handle_WiFi_reconnection(unsigned long currentMillis) { - if (wifi_state == CONNECTING && currentMillis - wifi_connect_start_time > wifi_connect_timeout) { - wifi_state = DISCONNECTED; - Serial.println("Failed to connect to WiFi network: " + String(ssid)); - Serial.println("Please check WiFi network name and password, and if WiFi network is available."); - Serial.println("Will try again in " + String((wifi_monitor_loop_time - (millis() - last_wifi_monitor_run)) / 1000) + - " seconds."); - } else if (wifi_state != CONNECTING) { +// Function to handle WiFi reconnection. Use some timeouts and backoffs here to avoid flooding reconnection attempts/spamming the serial console +void handle_WiFi_reconnection(unsigned long currentMillis, wl_status_t status) { + if (wifi_state == CONNECTING && currentMillis - wifi_connect_start_time > WIFI_CONNECT_TIMEOUT) { + // we are here if we were trying to connect to wifi, but it took too long (more than configured timeout) + Serial.println("Failed to connect to WiFi network before timeout"); + print_wifi_status_message(status); + WiFi.disconnect(); //disconnect to clear any previous settings wifi_state = DISCONNECTED; - Serial.println("Wifi disconnected. Attempting reconnection"); + wifi_connect_start_time = currentMillis; //reset the start time to now so backoff is respected on next try + // We use a backoff time before trying to connect again. Increase backoff time, up to a maximum + wifi_reconnect_backoff_time = min(wifi_reconnect_backoff_time * 2, MAX_WIFI_RECONNECT_BACKOFF_TIME); + Serial.println("Will try again in " + String(wifi_reconnect_backoff_time / 1000) + " seconds."); + } else if (wifi_state != CONNECTING && currentMillis - wifi_connect_start_time > wifi_reconnect_backoff_time) { + // we are here if the connection failed for some reason and the backoff time has now passed + wifi_state = DISCONNECTED; //set to disconnected for good measure, although it should already be + print_wifi_status_message(status); init_WiFi_STA(ssid, password); } } -// Function to initialize WiFi in Station Mode +// Function to handle WiFi connection +void WiFi_monitor_loop() { + unsigned long currentMillis = millis(); + if (currentMillis - last_wifi_monitor_run > WIFI_MONITOR_LOOP_TIME) { + last_wifi_monitor_run = currentMillis; + wl_status_t status = WiFi.status(); + switch (status) { + case WL_CONNECTED: + if (wifi_state != CONNECTED) { //we need to update our own wifi state to indicate we are connected + wifi_reconnect_backoff_time = DEFAULT_WIFI_RECONNECT_BACKOFF_TIME; // Reset backoff time after maintaining connection + wifi_state = CONNECTED; + print_wifi_status_message(status); + } + break; + case WL_CONNECT_FAILED: + case WL_CONNECTION_LOST: + case WL_DISCONNECTED: + case WL_NO_SSID_AVAIL: + handle_WiFi_reconnection(currentMillis, status); + break; + case WL_IDLE_STATUS: //this means the wifi is not ready to process any commands. do nothing + case WL_SCAN_COMPLETED: //this will only be set when scanning for networks. We don't do that yet + case WL_NO_SHIELD: //should not happen, this means no wifi chip detected, so we can't do much + break; + } + } +} + +// Function to initialize WiFi in Station Mode (i.e. connect to another access point) void init_WiFi_STA(const char* ssid, const char* password) { Serial.println("Connecting to: " + String(ssid)); WiFi.begin(ssid, password); @@ -286,6 +342,20 @@ void init_WiFi_STA(const char* ssid, const char* password) { wifi_connect_start_time = millis(); } +// Function to convert WiFiState enum to String +String wifi_state_to_string(WiFiState state) { + switch (state) { + case DISCONNECTED: + return "Disconnected"; + case CONNECTING: + return "Connecting"; + case CONNECTED: + return "Connected"; + default: + return "Unknown"; + } +} + // Function to initialize WiFi in Access Point Mode void init_WiFi_AP() { Serial.println("Creating Access Point: " + String(ssidAP)); @@ -305,20 +375,6 @@ void init_ElegantOTA() { ElegantOTA.onEnd(onOTAEnd); } -// Function to convert WiFiState enum to String -String wifi_state_to_string(WiFiState state) { - switch (state) { - case DISCONNECTED: - return "Disconnected"; - case CONNECTING: - return "Connecting"; - case CONNECTED: - return "Connected"; - default: - return "Unknown"; - } -} - String processor(const String& var) { if (var == "PLACEHOLDER") { String content = ""; diff --git a/Software/src/devboard/webserver/webserver.h b/Software/src/devboard/webserver/webserver.h index f70f53e2..fc7ab143 100644 --- a/Software/src/devboard/webserver/webserver.h +++ b/Software/src/devboard/webserver/webserver.h @@ -90,14 +90,14 @@ void init_WiFi_STA(const char* ssid, const char* password); */ void WiFi_monitor_loop(); -/** - * @brief Function to handle WiFi reconnection. - * - * @param[in] void - * - * @return void - */ -void handle_WiFi_reconnection(unsigned long currentMillis); +// /** +// * @brief Function to handle WiFi reconnection. +// * +// * @param[in] void +// * +// * @return void +// */ +// void handle_WiFi_reconnection(unsigned long currentMillis); /** * @brief Initialization function for ElegantOTA. From 6d10cbc517200009c2aec934f9b91801474a678b Mon Sep 17 00:00:00 2001 From: Brett Christensen Date: Tue, 6 Feb 2024 12:38:21 +1100 Subject: [PATCH 4/9] Update webserver.cpp --- Software/src/devboard/webserver/webserver.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 22e16038..25f0d9eb 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -39,7 +39,7 @@ const char index_html[] PROGMEM = R"rawliteral( // Wifi connect time declarations and definition const unsigned long MAX_WIFI_RECONNECT_BACKOFF_TIME = 60000; // Maximum backoff time of 1 minute const unsigned long DEFAULT_WIFI_RECONNECT_BACKOFF_TIME = 1000; // Default wifi reconnect backoff time. Start with 1 second -const unsigned long WIFI_CONNECT_TIMEOUT = 5000; // Timeout for WiFi connect in milliseconds +const unsigned long WIFI_CONNECT_TIMEOUT = 10000; // Timeout for WiFi connect in milliseconds const unsigned long WIFI_MONITOR_LOOP_TIME = 1000; // Will check if WiFi is connected and try reconnect every x milliseconds unsigned long last_wifi_monitor_run = 0; unsigned long wifi_connect_start_time; @@ -300,7 +300,6 @@ void handle_WiFi_reconnection(unsigned long currentMillis, wl_status_t status) { Serial.println("Will try again in " + String(wifi_reconnect_backoff_time / 1000) + " seconds."); } else if (wifi_state != CONNECTING && currentMillis - wifi_connect_start_time > wifi_reconnect_backoff_time) { // we are here if the connection failed for some reason and the backoff time has now passed - wifi_state = DISCONNECTED; //set to disconnected for good measure, although it should already be print_wifi_status_message(status); init_WiFi_STA(ssid, password); } @@ -326,7 +325,8 @@ void WiFi_monitor_loop() { case WL_NO_SSID_AVAIL: handle_WiFi_reconnection(currentMillis, status); break; - case WL_IDLE_STATUS: //this means the wifi is not ready to process any commands. do nothing + case WL_IDLE_STATUS: //this means the wifi is not ready to process any commands (it's probably trying to connect). do nothing + case WL_SCAN_COMPLETED: //this will only be set when scanning for networks. We don't do that yet case WL_NO_SHIELD: //should not happen, this means no wifi chip detected, so we can't do much break; @@ -337,8 +337,9 @@ void WiFi_monitor_loop() { // Function to initialize WiFi in Station Mode (i.e. connect to another access point) void init_WiFi_STA(const char* ssid, const char* password) { Serial.println("Connecting to: " + String(ssid)); - WiFi.begin(ssid, password); wifi_state = CONNECTING; + WiFi.begin(ssid, password); + WiFi.setAutoReconnect(true); wifi_connect_start_time = millis(); } From 5cae926ebf3d2b3cfb3b79e89bc26820e137f716 Mon Sep 17 00:00:00 2001 From: rjsc Date: Wed, 7 Feb 2024 11:57:06 +0000 Subject: [PATCH 5/9] make clang happy --- Software/src/devboard/webserver/webserver.cpp | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 25f0d9eb..d581911f 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -37,17 +37,20 @@ const char index_html[] PROGMEM = R"rawliteral( )rawliteral"; // Wifi connect time declarations and definition -const unsigned long MAX_WIFI_RECONNECT_BACKOFF_TIME = 60000; // Maximum backoff time of 1 minute -const unsigned long DEFAULT_WIFI_RECONNECT_BACKOFF_TIME = 1000; // Default wifi reconnect backoff time. Start with 1 second -const unsigned long WIFI_CONNECT_TIMEOUT = 10000; // Timeout for WiFi connect in milliseconds -const unsigned long WIFI_MONITOR_LOOP_TIME = 1000; // Will check if WiFi is connected and try reconnect every x milliseconds +const unsigned long MAX_WIFI_RECONNECT_BACKOFF_TIME = 60000; // Maximum backoff time of 1 minute +const unsigned long DEFAULT_WIFI_RECONNECT_BACKOFF_TIME = + 1000; // Default wifi reconnect backoff time. Start with 1 second +const unsigned long WIFI_CONNECT_TIMEOUT = 10000; // Timeout for WiFi connect in milliseconds +const unsigned long WIFI_MONITOR_LOOP_TIME = + 1000; // Will check if WiFi is connected and try reconnect every x milliseconds unsigned long last_wifi_monitor_run = 0; unsigned long wifi_connect_start_time; unsigned long wifi_reconnect_backoff_time = DEFAULT_WIFI_RECONNECT_BACKOFF_TIME; enum WiFiState { DISCONNECTED, CONNECTING, CONNECTED }; -WiFiState wifi_state = DISCONNECTED; //the esp library has no specific state to indicate if its connecting (only WL_IDLE_STATUS) so we keep track of it here +WiFiState wifi_state = + DISCONNECTED; //the esp library has no specific state to indicate if its connecting (only WL_IDLE_STATUS) so we keep track of it here void init_webserver() { // Configure WiFi @@ -292,9 +295,9 @@ void handle_WiFi_reconnection(unsigned long currentMillis, wl_status_t status) { // we are here if we were trying to connect to wifi, but it took too long (more than configured timeout) Serial.println("Failed to connect to WiFi network before timeout"); print_wifi_status_message(status); - WiFi.disconnect(); //disconnect to clear any previous settings + WiFi.disconnect(); //disconnect to clear any previous settings wifi_state = DISCONNECTED; - wifi_connect_start_time = currentMillis; //reset the start time to now so backoff is respected on next try + wifi_connect_start_time = currentMillis; //reset the start time to now so backoff is respected on next try // We use a backoff time before trying to connect again. Increase backoff time, up to a maximum wifi_reconnect_backoff_time = min(wifi_reconnect_backoff_time * 2, MAX_WIFI_RECONNECT_BACKOFF_TIME); Serial.println("Will try again in " + String(wifi_reconnect_backoff_time / 1000) + " seconds."); @@ -313,8 +316,8 @@ void WiFi_monitor_loop() { wl_status_t status = WiFi.status(); switch (status) { case WL_CONNECTED: - if (wifi_state != CONNECTED) { //we need to update our own wifi state to indicate we are connected - wifi_reconnect_backoff_time = DEFAULT_WIFI_RECONNECT_BACKOFF_TIME; // Reset backoff time after maintaining connection + if (wifi_state != CONNECTED) { //we need to update our own wifi state to indicate we are connected + wifi_reconnect_backoff_time = DEFAULT_WIFI_RECONNECT_BACKOFF_TIME; // Reset backoff time after maintaining connection wifi_state = CONNECTED; print_wifi_status_message(status); } @@ -325,10 +328,10 @@ void WiFi_monitor_loop() { case WL_NO_SSID_AVAIL: handle_WiFi_reconnection(currentMillis, status); break; - case WL_IDLE_STATUS: //this means the wifi is not ready to process any commands (it's probably trying to connect). do nothing + case WL_IDLE_STATUS: //this means the wifi is not ready to process any commands (it's probably trying to connect). do nothing - case WL_SCAN_COMPLETED: //this will only be set when scanning for networks. We don't do that yet - case WL_NO_SHIELD: //should not happen, this means no wifi chip detected, so we can't do much + case WL_SCAN_COMPLETED: //this will only be set when scanning for networks. We don't do that yet + case WL_NO_SHIELD: //should not happen, this means no wifi chip detected, so we can't do much break; } } From 008ddcf5625a47dfd5f38cbe230b88551e70ec26 Mon Sep 17 00:00:00 2001 From: rjsc Date: Wed, 7 Feb 2024 11:58:08 +0000 Subject: [PATCH 6/9] make clang happy --- Software/src/devboard/webserver/webserver.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/src/devboard/webserver/webserver.h b/Software/src/devboard/webserver/webserver.h index fc7ab143..79ac2646 100644 --- a/Software/src/devboard/webserver/webserver.h +++ b/Software/src/devboard/webserver/webserver.h @@ -94,7 +94,7 @@ void WiFi_monitor_loop(); // * @brief Function to handle WiFi reconnection. // * // * @param[in] void -// * +// * // * @return void // */ // void handle_WiFi_reconnection(unsigned long currentMillis); From ea0a70e339f70d727e7c2e4b8e501e99f48f97f4 Mon Sep 17 00:00:00 2001 From: rjsc Date: Wed, 7 Feb 2024 12:27:23 +0000 Subject: [PATCH 7/9] make clang happy --- Software/src/devboard/webserver/webserver.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index d581911f..d048598e 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -38,18 +38,18 @@ const char index_html[] PROGMEM = R"rawliteral( // Wifi connect time declarations and definition const unsigned long MAX_WIFI_RECONNECT_BACKOFF_TIME = 60000; // Maximum backoff time of 1 minute -const unsigned long DEFAULT_WIFI_RECONNECT_BACKOFF_TIME = - 1000; // Default wifi reconnect backoff time. Start with 1 second +const unsigned long DEFAULT_WIFI_RECONNECT_BACKOFF_TIME = + 1000; // Default wifi reconnect backoff time. Start with 1 second const unsigned long WIFI_CONNECT_TIMEOUT = 10000; // Timeout for WiFi connect in milliseconds -const unsigned long WIFI_MONITOR_LOOP_TIME = +const unsigned long WIFI_MONITOR_LOOP_TIME = 1000; // Will check if WiFi is connected and try reconnect every x milliseconds unsigned long last_wifi_monitor_run = 0; unsigned long wifi_connect_start_time; unsigned long wifi_reconnect_backoff_time = DEFAULT_WIFI_RECONNECT_BACKOFF_TIME; -enum WiFiState { DISCONNECTED, CONNECTING, CONNECTED }; +enum WiFiState { DISCONNECTED, CONNECTING, CONNECTED }; -WiFiState wifi_state = +WiFiState wifi_state = DISCONNECTED; //the esp library has no specific state to indicate if its connecting (only WL_IDLE_STATUS) so we keep track of it here void init_webserver() { @@ -317,7 +317,8 @@ void WiFi_monitor_loop() { switch (status) { case WL_CONNECTED: if (wifi_state != CONNECTED) { //we need to update our own wifi state to indicate we are connected - wifi_reconnect_backoff_time = DEFAULT_WIFI_RECONNECT_BACKOFF_TIME; // Reset backoff time after maintaining connection + wifi_reconnect_backoff_time = + DEFAULT_WIFI_RECONNECT_BACKOFF_TIME; // Reset backoff time after maintaining connection wifi_state = CONNECTED; print_wifi_status_message(status); } @@ -331,7 +332,7 @@ void WiFi_monitor_loop() { case WL_IDLE_STATUS: //this means the wifi is not ready to process any commands (it's probably trying to connect). do nothing case WL_SCAN_COMPLETED: //this will only be set when scanning for networks. We don't do that yet - case WL_NO_SHIELD: //should not happen, this means no wifi chip detected, so we can't do much + case WL_NO_SHIELD: //should not happen, this means no wifi chip detected, so we can't do much break; } } From ae200bdeb5eecb27bad0fa6e1f4b7281dd0303fa Mon Sep 17 00:00:00 2001 From: rjsc Date: Wed, 7 Feb 2024 12:29:38 +0000 Subject: [PATCH 8/9] make clang happy --- Software/src/devboard/webserver/webserver.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index d048598e..d5b28496 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -39,13 +39,13 @@ const char index_html[] PROGMEM = R"rawliteral( // Wifi connect time declarations and definition const unsigned long MAX_WIFI_RECONNECT_BACKOFF_TIME = 60000; // Maximum backoff time of 1 minute const unsigned long DEFAULT_WIFI_RECONNECT_BACKOFF_TIME = - 1000; // Default wifi reconnect backoff time. Start with 1 second + 1000; // Default wifi reconnect backoff time. Start with 1 second const unsigned long WIFI_CONNECT_TIMEOUT = 10000; // Timeout for WiFi connect in milliseconds const unsigned long WIFI_MONITOR_LOOP_TIME = 1000; // Will check if WiFi is connected and try reconnect every x milliseconds unsigned long last_wifi_monitor_run = 0; unsigned long wifi_connect_start_time; -unsigned long wifi_reconnect_backoff_time = DEFAULT_WIFI_RECONNECT_BACKOFF_TIME; +unsigned long wifi_reconnect_backoff_time = DEFAULT_WIFI_RECONNECT_BACKOFF_TIME; enum WiFiState { DISCONNECTED, CONNECTING, CONNECTED }; From 923a18e5c10cfdd867eaa0d847b0a6aa6488e891 Mon Sep 17 00:00:00 2001 From: rjsc Date: Wed, 7 Feb 2024 12:33:05 +0000 Subject: [PATCH 9/9] make clang happy --- Software/src/devboard/webserver/webserver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index d5b28496..bfb1318c 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -50,7 +50,7 @@ unsigned long wifi_reconnect_backoff_time = DEFAULT_WIFI_RECONNECT_BACKOFF_TIME; enum WiFiState { DISCONNECTED, CONNECTING, CONNECTED }; WiFiState wifi_state = - DISCONNECTED; //the esp library has no specific state to indicate if its connecting (only WL_IDLE_STATUS) so we keep track of it here + DISCONNECTED; //the esp library has no specific state to indicate if its connecting (only WL_IDLE_STATUS) so we keep track of it here void init_webserver() { // Configure WiFi