From c1349c3b44327b5a50438b0b193db0cfbdf57503 Mon Sep 17 00:00:00 2001 From: davidchatting-bot Date: Wed, 5 Aug 2026 17:05:32 +0000 Subject: [PATCH] Fix ESP32 station-IP lookup with the real esp_netif API, not a guessed rename The first attempt (esp_netif_get_sta_list()/esp_netif_sta_list_t) was wrong - CI failed with the same shape of error ('esp_netif_sta_list_t' does not name a type). That name doesn't exist; I'd guessed it as a same-shaped rename of tcpip_adapter_get_sta_list() without verifying against the actual ESP-IDF source. Verified against espressif/esp-idf v5.1 source this time: - esp_wifi_ap_get_sta_list() only returns MAC addresses, no IPs - The real replacement is esp_netif_dhcps_get_clients_by_mac(), which looks up each MAC's IP from the AP's DHCP server lease table - a differently-shaped API (caller pre-fills an array of MACs, function fills in the IPs), not a drop-in rename like the old single call - Needs an esp_netif_t* handle for the AP interface, obtained via esp_netif_get_handle_from_ifkey("WIFI_AP_DEF") - the ifkey Arduino's WiFi.softAP()/esp_netif_create_default_wifi_ap() registers under Also decouples adapter_sta_list from any ESP-IDF struct entirely: promoted this library's own wifi_sta.h shim (previously ESP8266-only, since ESP8266 never had real tcpip_adapter types) to a shared YoYoStaInfo/YoYoStaList type used on both platforms, so a future ESP-IDF rename can't break this again the same way. Still not hardware/toolchain-tested (no ESP32 SDK available in this environment) - verified against ESP-IDF source this time rather than guessed, but relying on CI to confirm compilation. Co-Authored-By: Claude Sonnet 5 --- src/YoYoWiFiManager.cpp | 19 +++++++++++++++++-- src/YoYoWiFiManager.h | 8 +++----- src/YoYoWiFiManager/wifi_sta.h | 11 +++++++---- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/YoYoWiFiManager.cpp b/src/YoYoWiFiManager.cpp index df83310..b147f74 100644 --- a/src/YoYoWiFiManager.cpp +++ b/src/YoYoWiFiManager.cpp @@ -1395,7 +1395,6 @@ int YoYoWiFiManager::updateClientList() { adapter_sta_list.num = count; int n=0; - tcpip_adapter_sta_info_t station; while (count > 0 && stat_info != NULL) { memcpy(adapter_sta_list.sta[n].mac, stat_info->bssid, sizeof(stat_info->bssid[0])*6); adapter_sta_list.sta[n].ip = stat_info->ip; @@ -1406,8 +1405,24 @@ int YoYoWiFiManager::updateClientList() { wifi_softap_free_station_info(); #elif defined(ESP32) + //tcpip_adapter_get_sta_list() was removed from current ESP-IDF - unlike the old single call, + //esp_wifi only gives MAC addresses (esp_wifi_ap_get_sta_list()); each station's IP has to be + //looked up separately from the AP's DHCP server lease table by MAC (esp_netif_dhcps_get_clients_by_mac()): esp_wifi_ap_get_sta_list(&wifi_sta_list); - esp_netif_get_sta_list(&wifi_sta_list, &adapter_sta_list); //tcpip_adapter_get_sta_list() was removed from current ESP-IDF - this is its documented esp_netif replacement + + esp_netif_pair_mac_ip_t mac_ip_pair[ESP_WIFI_MAX_CONN_NUM]; + for (int n = 0; n < wifi_sta_list.num; n++) { + memcpy(mac_ip_pair[n].mac, wifi_sta_list.sta[n].mac, 6); + } + + esp_netif_t *apNetif = esp_netif_get_handle_from_ifkey("WIFI_AP_DEF"); + esp_netif_dhcps_get_clients_by_mac(apNetif, wifi_sta_list.num, mac_ip_pair); + + adapter_sta_list.num = wifi_sta_list.num; + for (int n = 0; n < wifi_sta_list.num; n++) { + memcpy(adapter_sta_list.sta[n].mac, mac_ip_pair[n].mac, 6); + memcpy(&(adapter_sta_list.sta[n].ip), &(mac_ip_pair[n].ip), sizeof(adapter_sta_list.sta[n].ip)); + } count = adapter_sta_list.num; #endif } diff --git a/src/YoYoWiFiManager.h b/src/YoYoWiFiManager.h index 0a34a47..664baee 100644 --- a/src/YoYoWiFiManager.h +++ b/src/YoYoWiFiManager.h @@ -10,17 +10,17 @@ #include #include //not currently available via Library Manager > https://github.com/me-no-dev/ESPAsyncTCP #include - #include "YoYoWiFiManager/wifi_sta.h" #elif defined(ESP32) #include #include #include #include - #include //esp_netif_get_sta_list()/esp_netif_sta_list_t - replaces the removed tcpip_adapter_get_sta_list()/tcpip_adapter_sta_list_t + #include //esp_netif_get_handle_from_ifkey()/esp_netif_dhcps_get_clients_by_mac() - used to resolve each AP station's IP, replacing the removed tcpip_adapter_get_sta_list() #include #include #endif +#include "YoYoWiFiManager/wifi_sta.h" //this library's own station-list type, used on both platforms - see #61 //#include #include //https://www.arduino.cc/en/Reference/SD + https://github.com/arduino-libraries/SD #include @@ -180,10 +180,8 @@ class YoYoWiFiManager : public AsyncWebHandler { #if defined(ESP32) wifi_sta_list_t wifi_sta_list; - esp_netif_sta_list_t adapter_sta_list; - #elif defined(ESP8266) - tcpip_adapter_sta_list_t adapter_sta_list; #endif + YoYoStaList adapter_sta_list; int POST(const char *server, const char *path, const char *payload, char *contentType, char *response = NULL); int GET(const char *server, const char *path, char *response); diff --git a/src/YoYoWiFiManager/wifi_sta.h b/src/YoYoWiFiManager/wifi_sta.h index da457fb..4203857 100644 --- a/src/YoYoWiFiManager/wifi_sta.h +++ b/src/YoYoWiFiManager/wifi_sta.h @@ -3,14 +3,17 @@ #define ESP_WIFI_MAX_CONN_NUM (10) //TODO: is this right? This is the max for ESP32 +//This library's own station-list shape, used on both ESP8266 and ESP32 - deliberately +//not tied to any particular SDK struct, since ESP-IDF has already removed/renamed its +//own equivalent (tcpip_adapter_sta_list_t) once - see #61: typedef struct { uint8_t mac[6]; ip4_addr_t ip; -} tcpip_adapter_sta_info_t; +} YoYoStaInfo; typedef struct { - tcpip_adapter_sta_info_t sta[ESP_WIFI_MAX_CONN_NUM]; + YoYoStaInfo sta[ESP_WIFI_MAX_CONN_NUM]; int num; -} tcpip_adapter_sta_list_t; +} YoYoStaList; -#endif \ No newline at end of file +#endif