From f2967862b62f03040933ef57448efa844904a220 Mon Sep 17 00:00:00 2001 From: Matthias Mitscherlich Date: Mon, 16 Jan 2023 12:19:33 +0100 Subject: [PATCH] updated wifi module for static behaviour --- code/main/inc/wifi.h | 8 ++++++-- code/main/src/wifi.cpp | 17 ++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/code/main/inc/wifi.h b/code/main/inc/wifi.h index 9c87ce9..5397694 100644 --- a/code/main/inc/wifi.h +++ b/code/main/inc/wifi.h @@ -70,10 +70,14 @@ class Wifi void start_client(void); - static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data); - private: + static EventGroupHandle_t s_wifi_event_group; + static int s_retry_num; + static const char *TAG; + + static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data); + }; diff --git a/code/main/src/wifi.cpp b/code/main/src/wifi.cpp index 0c8228a..cd4ccca 100644 --- a/code/main/src/wifi.cpp +++ b/code/main/src/wifi.cpp @@ -45,9 +45,6 @@ // File-scope variables // -------------------------------------------------------------------------------------------------------------------- -static EventGroupHandle_t s_wifi_event_group; -static int s_retry_num; -static const char *TAG = "wifi station"; static const char* ssid = "Kowalski"; static const char* pass = "madagascar"; @@ -63,9 +60,13 @@ static const char* pass = "madagascar"; // -------------------------------------------------------------------------------------------------------------------- +int Wifi::s_retry_num = 0; +const char* Wifi::TAG = "wifi station"; +EventGroupHandle_t Wifi::s_wifi_event_group = xEventGroupCreate(); + Wifi::Wifi() { - s_retry_num = 0; + } @@ -77,7 +78,7 @@ void Wifi::event_handler(void *arg, esp_event_base_t event_base, int32_t event_i } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { - if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) + if (Wifi::s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) { esp_wifi_connect(); s_retry_num++; @@ -100,8 +101,6 @@ void Wifi::event_handler(void *arg, esp_event_base_t event_base, int32_t event_i void Wifi::start_client(void) { - s_wifi_event_group = xEventGroupCreate(); - ESP_ERROR_CHECK(esp_netif_init()); ESP_ERROR_CHECK(esp_event_loop_create_default()); @@ -112,8 +111,8 @@ void Wifi::start_client(void) esp_event_handler_instance_t instance_any_id; esp_event_handler_instance_t instance_got_ip; - ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &Wifi::event_handler, NULL, &instance_any_id)); - ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &Wifi::event_handler, NULL, &instance_got_ip)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, &instance_any_id)); + ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, &instance_got_ip)); wifi_config_t wifi_config;