Test four, handling loss of connection, AP being powered off -
That starts off okay, can't connect to my Pico W AP which is turned off, connects once it is turned on. And it eventually notes the disconnect some 10 seconds after the AP is turned off.
But, when it tries to connect again, it simply loops because 'wlan.status()' always reports '1', 'JOIN'.
And it stays that way even when the AP is turned on again, and off then on repeatedly.
So it does seem there is some issue with 'wlan.status()' when the connection is lost, and that prevents the disconnection trick from earlier working.
With the disconnect and wait for disconnect removed a 'connect' fails while the AP remains off, but with it turned on 'connect' tries but then fails with 'wlan.status()' as '1', that 'JOIN' from earlier perhaps, and sometimes '-3', 'BADAUTH' which isn't right, though maybe it's screwed the AP as well ?
There's more adventuring to be done.
Code:
import gcimport networkimport timewhile True: ssid, password = "mesh", "passmesh" print("Try {} {}".format(ssid, password)) wlan = network.WLAN(network.STA_IF) wlan.active(True) wlan.disconnect() while wlan.status() > 0: print(" Disconnect waiting", wlan.status()) time.sleep(1) wlan.connect(ssid, password) wait = 10 while wait > 0 and wlan.status() >= 0 and wlan.status() < 3: print(" Connect waiting", wlan.status()) wait -= 1 time.sleep(1) gc.collect() if wlan.status() == 3 : print(" Connected", wlan.ifconfig()) else : print(" Failed", wlan.status()) if wlan.status() == 3: while wlan.isconnected(): time.sleep(1) print(" Disconnected") else: time.sleep(5) print("")
Code:
Try mesh passmesh Connect waiting 1 Failed -2Try mesh passmesh Connect waiting 1 Connect waiting 1 Connect waiting 1 Connected ('192.168.4.16', '255.255.255.0', '192.168.4.1', '192.168.4.1') DisconnectedTry mesh passmesh Disconnect waiting 1 Disconnect waiting 1 etc
But, when it tries to connect again, it simply loops because 'wlan.status()' always reports '1', 'JOIN'.
And it stays that way even when the AP is turned on again, and off then on repeatedly.
So it does seem there is some issue with 'wlan.status()' when the connection is lost, and that prevents the disconnection trick from earlier working.
With the disconnect and wait for disconnect removed a 'connect' fails while the AP remains off, but with it turned on 'connect' tries but then fails with 'wlan.status()' as '1', that 'JOIN' from earlier perhaps, and sometimes '-3', 'BADAUTH' which isn't right, though maybe it's screwed the AP as well ?
There's more adventuring to be done.
Statistics: Posted by hippy — Sat Jan 27, 2024 4:31 pm