My PICO W hangs sometimes after calling deinit(). I'm using Micropython v1.25.0 (2025-04-15)
Please see this example script:
import network
import time
from time import sleep
import urequests
import gc
WLAN_SSID = 'MYSSID'
WLAN_PASSWORD = '123'
wlan = network.WLAN(network.STA_IF)
counter = 1
while True:
print('Start round {}'.format(counter))
wlan.active(True)
wlan.connect(WLAN_SSID, WLAN_PASSWORD)
for i in range(20):
if wlan.isconnected():
break
print('Trying to connect... Status is: ', wlan.status())
time.sleep(1)
if wlan.isconnected():
response = urequests.get('https://www.google.com')
response.close()
print('Deactivate WLAN...')
print('Memory alloc {}'.format(gc.mem_alloc()))
print('Memory free {}'.format(gc.mem_free()))
wlan.disconnect()
wlan.active(False)
wlan.deinit()
print('Sleeping...')
time.sleep(5)
counter += 1
This script works for 5-30 times until it suddenly hangs on print('Deactivate WLAN...').
Reason is the call to deinit()
I need to call deinit(), since I want to put the PICO into deepsleep mode afterwards.
Any ideas what's going wrong here?
Thanks!
.disconnect(), setting.active(False)and callingdeinit()anyway. I don't use micropython, but it would be worth checking to determine the consequence of making those calls if a connection wasn't established. Simply wrapping those calls in anotherif wlan.isconnected():would protect against that case. You can added error output within thatifblock to provide a diagnostic as well.printfto find the exact point of failure. You can see if micropython offers anything (IP received, etc..) that you can verify. Pico W is a great little board, and a fun challenge with WiFi.:(They have had a few issues with recent changes. Trying to buildpicotoolyesterday, we found bug #2552 (uint8_tdoes not name a type). Likewise, it was also fixed -- you just had to switch to the "develop" branch of the Pico-SDK git repository....