From 1654753bbbbd966e4dda5f0429a3f1f04767d9de Mon Sep 17 00:00:00 2001 From: Bob Date: Sun, 9 Nov 2025 21:01:11 +0000 Subject: [PATCH] Add RSSI and enhanced network info to WiFi connection logs Show signal strength (RSSI in dBm) when connected to AP Show gateway and netmask in addition to IP address Useful for debugging WiFi connectivity in multi-device deployments --- main/main.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/main/main.c b/main/main.c index 0179473..ca14cee 100644 --- a/main/main.c +++ b/main/main.c @@ -32,6 +32,15 @@ static void event_handler(void* arg, esp_event_base_t event_base, { if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { esp_wifi_connect(); + } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_CONNECTED) { + wifi_event_sta_connected_t* event = (wifi_event_sta_connected_t*) event_data; + + // Get RSSI + wifi_ap_record_t ap_info; + esp_wifi_sta_get_ap_info(&ap_info); + + ESP_LOGI(TAG, "Connected to AP SSID:%s, BSSID:" MACSTR " Channel:%d RSSI:%d dBm", + event->ssid, MAC2STR(event->bssid), event->channel, ap_info.rssi); } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { if (s_retry_num < WIFI_MAXIMUM_RETRY) { esp_wifi_connect(); @@ -43,7 +52,10 @@ static void event_handler(void* arg, esp_event_base_t event_base, ESP_LOGI(TAG,"connect to the AP fail"); } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; - ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip)); + ESP_LOGI(TAG, "got ip:" IPSTR " gw:" IPSTR " netmask:" IPSTR, + IP2STR(&event->ip_info.ip), + IP2STR(&event->ip_info.gw), + IP2STR(&event->ip_info.netmask)); s_retry_num = 0; xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); } @@ -110,7 +122,7 @@ void wifi_init_sta(void) portMAX_DELAY); if (bits & WIFI_CONNECTED_BIT) { - ESP_LOGI(TAG, "connected to ap SSID:%s", WIFI_SSID); + ESP_LOGI(TAG, "WiFi connection successful"); } else if (bits & WIFI_FAIL_BIT) { ESP_LOGI(TAG, "Failed to connect to SSID:%s", WIFI_SSID); } else {