Open mikejc58 opened 3 years ago
The more elaborate test and its output: elaborate.txt
ESP32SPI .disconnect
simply calls disconnect
in the NINA firmware, which uses the Arduino function WiFi.disconnect()
. Similarly, ESP32SPI .connect
calls into NINA, which does a WiFi.begin(ssid, pass)
. So I think we'd have to dig into the ESP32 implementation of the Arduino functions.
I suspect WiFiNINA would behave similarly, it would be interesting if it was different.
If you can incur the <1 second penalty of esp.reset()
, that's probably the best workaround.
I am writing an application on a PyPortal that needs to talk to two access points. After connecting to the first and communicating via socket with a host there, I close the socket and do an esp.disconnect() to disconnect from the access point. This seems to work. The esp's status goes to WL_DISCONNECTED. I then connect to the second access point with the esp's status going back to WL_CONNECTED. But, at that point the ESP seems to be in a bad state. Any function requiring communication with the AP fails, in one way or another. I wrote a simple test case that demonstrates the problem:
The output is:
Everything works for the first access point, and seems to work for the second until the attempt to connect the socket. It also fails in the same way if I re-connect to the first access point instead. Other functions also fail. For example, esp.get_host_by_name(host) fails with RuntimeError: Failed to request hostname.
A more elaborate test shows that after connecting to the second access point, the ESP32's internal state is inconsistent. Asking the ESP32 for the bssid and ssid that it is connected to show the second access point, but asking the ESP32 for its 'network data', gives back the ip address, and gateway of the first access point.
If I change the timeout in _wait_for_ready, I find that the socket.connect request actual finishes after 18 seconds (waiting for the response, the normal timeout is 10). But, when the socket.connect finishes, it is with a RuntimeError: Expected 01 but got 00, which is what you get when the connection fails.
If you do an esp.reset(), everything works again.