updated wifi module for static behaviour

This commit is contained in:
Matthias Mitscherlich
2023-01-16 12:19:33 +01:00
parent d2167ecde3
commit f2967862b6
2 changed files with 14 additions and 11 deletions
+6 -2
View File
@@ -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);
};
+8 -9
View File
@@ -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;