Problem connecting after power cycle
Posted: Fri Apr 05, 2019 9:58 am
My main.py has a single line importing the file below:
I'm testing on an SF6W with a WBUS-DIP28 and connecting via USB-FS. Firmware is yesterday's (14th April) build and mboot is updated.
Running rshell the script is reliable if I press ctrl-d after it's already connected. However on the first ctrl-d it sometimes hangs with the red LED lit. I can always get it to connect quickly on the second and subsequent soft reset.
Behaviour is poor if I quit rshell and plug the board into my PC (or another known good source of USB power). It occasionally connects, but more commonly does not. If after a failure I subsequently press the reset button it does not usually connect.
In my actual application I've tried various strategies including trying again to connect if isconnected() returns False for too long, but so far I've not identified a reliable way to connect after a power cycle or reset. Am I missing something or is there a firmware issue?
As an aside it would be good if network supported STAT_CONNECTING because we could use the same code for Pyboard D as for ESP8266 and ESP32. The following terminates on success or failure without needing arbitrary timeouts to detect the fail state.
Code: Select all
import pyb, network, time
red = pyb.LED(1)
green = pyb.LED(2)
green.on()
time.sleep(4) # Give things a chance to settle down
green.off()
s = network.WLAN(network.STA_IF)
s.active(True)
s.connect('redacted', 'REDACTED')
red.on()
time.sleep(0.2) # Brief red flash if already connected
while not s.isconnected():
time.sleep(1)
red.off()
green.on()
Running rshell the script is reliable if I press ctrl-d after it's already connected. However on the first ctrl-d it sometimes hangs with the red LED lit. I can always get it to connect quickly on the second and subsequent soft reset.
Behaviour is poor if I quit rshell and plug the board into my PC (or another known good source of USB power). It occasionally connects, but more commonly does not. If after a failure I subsequently press the reset button it does not usually connect.
In my actual application I've tried various strategies including trying again to connect if isconnected() returns False for too long, but so far I've not identified a reliable way to connect after a power cycle or reset. Am I missing something or is there a firmware issue?
As an aside it would be good if network supported STAT_CONNECTING because we could use the same code for Pyboard D as for ESP8266 and ESP32. The following terminates on success or failure without needing arbitrary timeouts to detect the fail state.
Code: Select all
while s.status() == network.STAT_CONNECTING: # Break out on fail or success. Check once per sec.
await asyncio.sleep(1)