-
I am attempting to put in place code that will allow for a soft reboot or a machine reset of ESP32. What I want to do is setup a wifi connection, if not already connected, via a list of ssids and passwords. I am happy with most of my code except for handling a machine reset: `
wlan = network.WLAN(network.STA_IF)
` If it is a soft reboot and I already have a connection, all is fine. I get a nice "Already connected" message and everything continues. However, a machine reset causes a "Internal wifi error" on the first "if wlan.isconnected():" statement. Given that the wifi for the esp32 has been reset, I am not sure how to combine these separate tests in logic that will not just fail after a machine reset. I know that my later code will connect with the ssid list as I have commented out the initial connection test and machine reset with this altered code. I do realise that the "for ssid" loop will return a successful connection if it is a soft reboot and a connection already exists. However, that will seem to be a successful connection for the first ssid on my list, even if that ssid text entry is complete rubbish, so I am then not able to trust the current ssid on the list to be the one connected. I do want to record which ssid it is connecting to so do want a separate "Already connected" check first. If I am recording the connections correctly, I will have that info from the previous machine reboot/reset. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Follow any disconnect with: sta_if.disconnect() Start any connect sequence with: sta_if.active(True)
# seems more reliable to start with a fresh connect()
if sta_if.isconnected():
sta_if.disconnect()
print (f'started in the connected state, but now disconnected')
else:
print (f'started in the disconnected state')
utime.sleep(0.1) or better still try using this:
|
Beta Was this translation helpful? Give feedback.
-
Thanks. `def wificonnectarray():
` Perfect thank you |
Beta Was this translation helpful? Give feedback.
Follow any disconnect with:
Start any connect sequence with:
or better still try using this:
https://github.com/glenn20/micropython-espnow-utils/blob/main/src/wifi.py