← index #10913Issue #305
Related · medium · value 1.130
QUERY · ISSUE

ESP32 / modnetwork / .status() is not reliable

openby pulkinopened 2023-03-03updated 2024-09-01
bugneeds-info

HW: ESP32 device

SW:

>>> os.uname()
(sysname='esp32', nodename='esp32', release='1.19.1', version='v1.19.1 on 2022-06-18', machine='ESP32 module (spiram) with ESP32')

Issue: polling WLAN(STA_IF).status() does not always provide an adequate response. Example:

>>> import socket
>>> s = socket.socket()
>>> s.connect(("192.168.1.136", 33567))
>>> WLAN(STA_IF).status()
1001
>>> s.read(18)
b'NBDMAGICIHAVEOPT\x00\x03'
>>> WLAN(STA_IF).status()
1001

In other words, sockets operate just fine while .status() == 1001 == STAT_CONNECTING. Instead, it should return .status() == 1010 == STAT_CONNECTED. Sniffing the router shows that ESP is, at least, aware of its assigned IP:
image
I expect that the flag wifi_sta_connected is not set properly.
https://github.com/micropython/micropython/blob/2bcd88d55645f2ea702ff70336b33be4661c97a8/ports/esp32/network_wlan.c#L280-L302

Reproducing: loop over connecting and disconnecting to the same wireless network. At some point the issue pops up.

CANDIDATE · ISSUE

Network Status ESP32

closedby fernandomorseopened 2018-09-04updated 2018-09-05

ESP32
version 1.9.4

network.status()

always return None

2 comments
dpgeorge · 2018-09-05

This was recently implemented here: https://github.com/micropython/micropython/commit/385fa5180663221bbec033c54c37fb38f589579b

fernandomorse · 2018-09-05

@dpgeorge

I checked that

from network import WLAN
wlan = WLAN ()
wlan.status ()
wlan.isconnected ()
wlan.isconfig ()

result:

1010
True
('10 .1.2.141 ',' 255.255.255.0 ', '10 .1.2.1', '10 .1.2.1 ')

turn off my router

result:

1010
True
('0.0.0.0', '0.0.0.0', '0.0.0.0', '10 .1.2.1 ')

status() e isconnected() not changed.

thanks

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