From 7cf5ef49a54741676f0c0d296df5ceb85f1520cd Mon Sep 17 00:00:00 2001 From: Morgan Allen Date: Fri, 21 Sep 2018 22:33:38 -0700 Subject: [PATCH] go IDLE after all APs have been attempted --- include/esp32-wifi-manager.h | 1 + main/esp32-wifi-manager.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/esp32-wifi-manager.h b/include/esp32-wifi-manager.h index d98dae2..3544022 100644 --- a/include/esp32-wifi-manager.h +++ b/include/esp32-wifi-manager.h @@ -10,6 +10,7 @@ void wifi_manager_reset_store(); #define WIFI_CONNECTED (BIT0) #define WIFI_CONNECTING (BIT1) #define AP_AVAILABLE (BIT2) +#define WIFI_IDLE (BIT3) uint8_t wifi_manager_ap_count(); uint8_t wifi_manager_add_ap(char *essid, char *password); diff --git a/main/esp32-wifi-manager.c b/main/esp32-wifi-manager.c index fee96e7..086dff2 100644 --- a/main/esp32-wifi-manager.c +++ b/main/esp32-wifi-manager.c @@ -42,8 +42,6 @@ typedef struct ap_store_base { ap_store_t ap_store; static EventGroupHandle_t wm_event_group; -void wifi_manager_connect(); - uint8_t wifi_manager_ap_count() { return ap_store.count; }; @@ -69,13 +67,18 @@ static esp_err_t wifi_event_handler(void *ctx, system_event_t *event) { vTaskDelay(CONFIG_WIFI_MANAGER_CONNECTION_DELAY / portTICK_PERIOD_MS); + // inc to the next ap, if it's the last one go IDLE + // else attempt to connect ap_store.last++; if(ap_store.count == ap_store.last) { ap_store.last = 0; - } - wifi_manager_connect(); - ESP_ERROR_CHECK(esp_wifi_connect()); + xEventGroupSetBits(wm_event_group, WIFI_IDLE); + break; + } else { + wifi_manager_connect(); + ESP_ERROR_CHECK(esp_wifi_connect()); + } break; default: break;