various bug fixes
This commit is contained in:
@@ -21,6 +21,7 @@ static EventGroupHandle_t s_wifi_group = NULL;
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
|
||||
static int s_retry_count = 0;
|
||||
static char s_sta_ip[20] = "No Wi-Fi";
|
||||
|
||||
static void wifi_event_handler(void *arg, esp_event_base_t base, int32_t id, void *data)
|
||||
{
|
||||
@@ -30,6 +31,7 @@ static void wifi_event_handler(void *arg, esp_event_base_t base, int32_t id, voi
|
||||
ESP_LOGI(TAG, "station started, connecting...");
|
||||
esp_wifi_connect();
|
||||
} else if (base == WIFI_EVENT && id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
strncpy(s_sta_ip, "No Wi-Fi", sizeof(s_sta_ip));
|
||||
if (s_retry_count < WIFI_RETRY_MAX) {
|
||||
ESP_LOGW(TAG, "disconnected (%d), retrying in %d ms", s_retry_count, WIFI_RECONNECT_DELAY_MS);
|
||||
xEventGroupClearBits(s_wifi_group, WIFI_CONNECTED_BIT);
|
||||
@@ -39,12 +41,21 @@ static void wifi_event_handler(void *arg, esp_event_base_t base, int32_t id, voi
|
||||
}
|
||||
} else if (base == IP_EVENT && id == IP_EVENT_STA_GOT_IP) {
|
||||
ip_event_got_ip_t *event = (ip_event_got_ip_t *)data;
|
||||
ESP_LOGI(TAG, "connected, IP: " IPSTR, IP2STR(&event->ip_info.ip));
|
||||
snprintf(s_sta_ip, sizeof(s_sta_ip), IPSTR, IP2STR(&event->ip_info.ip));
|
||||
ESP_LOGI(TAG, "connected, IP: %s", s_sta_ip);
|
||||
s_retry_count = 0;
|
||||
xEventGroupSetBits(s_wifi_group, WIFI_CONNECTED_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
const char *wifi_manager_get_ip(void)
|
||||
{
|
||||
if (!wifi_manager_connected()) {
|
||||
return "No Wi-Fi";
|
||||
}
|
||||
return s_sta_ip;
|
||||
}
|
||||
|
||||
esp_err_t wifi_manager_init(void)
|
||||
{
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
|
||||
Reference in New Issue
Block a user