make clang happy

This commit is contained in:
rjsc 2024-02-07 11:57:06 +00:00 committed by GitHub
parent 6d10cbc517
commit 5cae926ebf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;
}
}