esp32/network_wlan: Look up IP addresses for the stations list.#18956
Open
agatti wants to merge 1 commit intomicropython:masterfrom
Open
esp32/network_wlan: Look up IP addresses for the stations list.#18956agatti wants to merge 1 commit intomicropython:masterfrom
agatti wants to merge 1 commit intomicropython:masterfrom
Conversation
|
Code size report: |
cd94311 to
9a09b89
Compare
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]>
9a09b89 to
8cf3fa5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Nonewill 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.