Skip to content

esp32/network_wlan: Look up IP addresses for the stations list.#18956

Open
agatti wants to merge 1 commit intomicropython:masterfrom
agatti:esp32-ap-mode-provide-station-ip
Open

esp32/network_wlan: Look up IP addresses for the stations list.#18956
agatti wants to merge 1 commit intomicropython:masterfrom
agatti:esp32-ap-mode-provide-station-ip

Conversation

@agatti
Copy link
Contributor

@agatti agatti commented Mar 20, 2026

Summary

This PR extends the output of WLAN.status('stations') to also include the IP address of WiFi stations connected to the device if in AP mode.

The ESP32 port is brought up to parity with most ports in this regard (primarily with the ESP8266). This functionality depends on the DHCP server provided by ESP-IDF, which is automatically run on the WiFi interface if the device is put in AP mode. Currently the ESP32 port cannot run with said DHCP server disabled, so if a device does not request a static IP it may either have the wrong IP address returned (since the DHCP server assigned an address which is then discarded by the client), or it won't have any (ie. "0.0.0.0"). In the latter case None will be returned as the station's address instead.

This implements #9203.


ESP-IDF was probably always able to pull this off by performing the manual MAC→IP match via LWIP's DHCPS functions, but I guess that was not done to save on code space.

ESP-IDF 5.0 introduced a function that performs just that with little code (esp_wifi_ap_get_sta_list_with_ip), so now this can be safely added.

Testing

This was tested on an ESP32C3 running on git master and ESP-IDF 5.5.1, by connecting and disconnecting several devices to the device put in AP mode beforehand.

The original behaviour (returning a tuple with just the MAC address) is preserved for boards that use WiFi hosted mode (namely the ESP32P4). I do not have one of those boards myself so I wasn't able to test that specific use case, although the ifdef guards seem to be properly placed at least.

Trade-offs and Alternatives

There is currently no provision for the ESP32 port to run without DHCPS on the WiFi interface when put in AP mode, so I have no idea on the effective behaviour of a client connection without a DHCP server being present.

Generative AI

I did not use generative AI tools when creating this PR.

@github-actions
Copy link

github-actions bot commented Mar 20, 2026

Code size report:

Reference:  LICENSE,docs: Update copyright year range to include 2026. [e0beace]
Comparison: esp32/network_wlan: Look up IP addresses for the stations list. [merge of 8cf3fa5]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:  +384 +0.022% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@agatti agatti force-pushed the esp32-ap-mode-provide-station-ip branch 2 times, most recently from cd94311 to 9a09b89 Compare March 20, 2026 08:41
This commit extends the output of `WLAN.status('stations')` to also
include the IP address of WiFi stations connected to the device if in AP
mode.

IP address lookup is currently not available on targets that use hosted
WiFi (eg. ESP32P4), as the hosted API does not yet support performing
the MAC->IP lookup on the WiFi MCU end.

The ESP32 port is brought up to parity with most ports in this regard
(primarily with the ESP8266).  This functionality depends on the DHCP
server provided by ESP-IDF, which is automatically run on the WiFi
interface if the device is put in AP mode.  Currently the ESP32 port
cannot run with said DHCP server disabled, so if a device does not
request a static IP it may either have the wrong IP address returned
(since the DHCP server assigned an address which is then discarded by
the client), or it won't have any (ie. "0.0.0.0").  In the latter case
`None` will be returned as the station's address instead.

This implements micropython#9203.

Signed-off-by: Alessandro Gatti <[email protected]>
@agatti agatti force-pushed the esp32-ap-mode-provide-station-ip branch from 9a09b89 to 8cf3fa5 Compare March 20, 2026 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant