ESP32 / modnetwork / .status() is not reliable
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:

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.
network: status codes/constants not unified across ports
Working with latest builds (20230422-unstable-v1.19.1-1019) of micropython I found some discrepancies:
ESP32 generic does not have STAT_CONNECT_FAIL in network module.
I noticed that status code value for connecting is 1 in rp2w and 1001 in ESP32.
If we should use constants from documentation then they should be implemented in all ports (please).
Some examples use codes (which is bad) that means they do not work correctly over ports