Skip to content

Commit

Permalink
signalling wifi connecting state
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraus committed Nov 29, 2021
1 parent 238e8b5 commit 7612126
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions platformio/floower/src/connect/WifiConnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion platformio/floower/src/connect/WifiConnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -62,6 +63,7 @@ class WifiConnect {
bool enabled = false;
bool wifiOn = false;
bool wifiConnected = false;
bool wifiFailed = false;

uint8_t mode;
uint8_t state;
Expand Down

0 comments on commit 7612126

Please sign in to comment.