-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
esp32/modnetwork.c: Fix for isconnected() for static IP config. #3838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
esp32/modnetwork.c: Fix for isconnected() for static IP config. #3838
Conversation
Currently <WLAN>.isconnected() always returns True if a static IP is set, regardless of the state of the connection. This breaks the commonly documented wifi connection workflow: import network sta_if = network.WLAN(network.STA_IF) sta_if.active(True) sta_if.ifconfig( ('192.168.1.101', '255.255.255.0', '192.168.1.1', '8.8.8.8')) sta_if.connect('ssid', 'password') while not sta_if.isconnected(): pass This patch introduces a new flag 'wifi_sta_connected' which is set in event_handler() when GOT_IP event is received and reset when DISCONNECTED event is received (unless re-connect is successful). isconnected() now simply returns the status of this flag (for STA_IF). The pre-existing flag misleadingly named 'wifi_sta_connected" is also renamed to 'wifi_sta_connect_requested'. Fixes issue #3837
Thanks for the patch. Is the GOT_IP event fired even if a static IP address is set? |
FYI, there is also this older patch: micropython/micropython-esp32#217 which uses the |
Thanks for the quick response. Yes, the GOT_IP event is fired even for static IP - after connected to AP. For dhcp I think it is better to wait for GOT_IP, rather than just STA_CONNECTED as the interface is then fully configured. This also means the behaviour is unchanged for dhcp connections. |
Thanks Damien. I checked out micropython/micropython-esp32#217. I included the code from that patch which prints the log message for Accordingly I think it is more robust to test for GOT_IP to ensure the interface is fully configured. NOTE: I also picked up a logic error in my patch caused by the DISCONNECT event issued as we attempt to connect. I will follow up with another commit to fix that. I also find the log message for I am trying to save that 1 second on wake from deepsleep - hence my interest in static IPs
|
Fix for isconnected() logic error triggered by DISCONNECTED event which is generated before the CONNECTED event on first connect to wifi. Also included code from #217 to log CONNECTED events.
Yes I agree. Then this patch will have the same behaviour as before for DHCP (because before it was waiting for a non-zero IP address). And thanks for the further testing. I think this patch is now good to merge.
Yeah, waking and reconnecting can be slow. There is an interesting discussion about that here: espressif/esp-idf#799 |
Thanks for the pointer to the discussion on esp-idf and thanks for accepting for merge. I note that the CI check failed - though I can't work out why. Any tips? |
I'm trying to fix that right now: #3846 |
Excellent - thanks. Busy I see :-). |
Ok, rebased and merged in 039f196 |
Update devices.h
Currently
<WLAN>.isconnected()
always returns True if a staticIP is set, regardless of the state of the connection. This breaks
the commonly documented wifi connection workflow:
This patch introduces a new flag
wifi_sta_connected
which is set inevent_handler()
when GOT_IP event is received and reset whenDISCONNECTED event is received (unless re-connect is successful).
<WLAN>.isconnected()
now simply returns the status of this flag (for STA_IF).The pre-existing flag misleadingly named
wifi_sta_connected
is alsorenamed to
wifi_sta_connect_requested
.Fixes issue #3837