From 7612126f68ed7a5103f91c41138df276f3308a52 Mon Sep 17 00:00:00 2001 From: Jiri Praus Date: Mon, 29 Nov 2021 15:17:24 +0100 Subject: [PATCH] signalling wifi connecting state --- platformio/floower/src/connect/WifiConnect.cpp | 11 +++++++++-- platformio/floower/src/connect/WifiConnect.h | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/platformio/floower/src/connect/WifiConnect.cpp b/platformio/floower/src/connect/WifiConnect.cpp index 9ca4f83..d2bc912 100644 --- a/platformio/floower/src/connect/WifiConnect.cpp +++ b/platformio/floower/src/connect/WifiConnect.cpp @@ -61,6 +61,7 @@ void WifiConnect::enable() { WiFi.begin(config->wifiSsid.c_str(), config->wifiPassword.c_str()); ESP_LOGI(LOG_TAG, "WiFi on: %s", config->wifiSsid.c_str()); wifiOn = true; + wifiFailed = false; } enabled = true; } @@ -93,6 +94,7 @@ bool WifiConnect::isConnected() { void WifiConnect::reconnect() { if (enabled) { if (wifiOn) { + wifiFailed = false; WiFi.begin(config->wifiSsid.c_str(), config->wifiPassword.c_str()); ESP_LOGI(LOG_TAG, "WiFi reconnecting: %s", config->wifiSsid); } @@ -131,8 +133,11 @@ uint8_t WifiConnect::getStatus() { else if (authorizationFailed) { return WIFI_STATUS_FLOUD_UNAUTHORIZED; } - else { // failure - return WIFI_STATUS_NOT_CONNECTED; + else if (wifiFailed) { + return WIFI_STATUS_FAILED; + } + else { + return WIFI_STATUS_CONNECTING; } } @@ -354,6 +359,7 @@ void WifiConnect::onWifiDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) { if (!wifiConnected) { ESP_LOGI(LOG_TAG, "Failed to connect WiFi"); reconnectTime = millis() + CONNECT_RETRY_INTERVAL_MS; + wifiFailed = true; } else { ESP_LOGI(LOG_TAG, "Wifi lost: %d", info.disconnected.reason); @@ -371,6 +377,7 @@ void WifiConnect::onWifiGotIp(WiFiEvent_t event, WiFiEventInfo_t info) { ESP_LOGI(LOG_TAG, "Wifi got IP"); reconnectTime = 0; wifiConnected = true; + wifiFailed = false; } // OTA diff --git a/platformio/floower/src/connect/WifiConnect.h b/platformio/floower/src/connect/WifiConnect.h index ad67a25..dc96640 100644 --- a/platformio/floower/src/connect/WifiConnect.h +++ b/platformio/floower/src/connect/WifiConnect.h @@ -13,7 +13,8 @@ // network status #define WIFI_STATUS_DISABLED 0 #define WIFI_STATUS_NOT_CONFIGURED 1 -#define WIFI_STATUS_NOT_CONNECTED 2 +#define WIFI_STATUS_FAILED 2 +#define WIFI_STATUS_CONNECTING 5 #define WIFI_STATUS_FLOUD_UNAUTHORIZED 3 #define WIFI_STATUS_FLOUD_CONNECTED 4 @@ -62,6 +63,7 @@ class WifiConnect { bool enabled = false; bool wifiOn = false; bool wifiConnected = false; + bool wifiFailed = false; uint8_t mode; uint8_t state;