← index #4425PR #18956
Off-topic · high · value 4.559
QUERY · ISSUE

esp8266 recvfrom() gives ap address instead of source

openby pmp-popened 2019-01-24updated 2019-05-13
port-esp8266

on esp8266 with master :
STA 192.168.4.2 send packet to AP with sendto( data, ('192.168.4.1',port) )

on ap data, adrr = recvfrom() gives addr[0] == '192.168.4.1' source address instead of '192.168.4.2'

CANDIDATE · PULL REQUEST

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

openby agattiopened 2026-03-20updated 2026-03-20
port-esp32

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.

<hr>

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.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied