Closed uxp closed 3 years ago
An interesting observation I just made: Swapping the library for the source .py version on my PyPortal device does not exhibit this issue. Keeping the "compiled" .mpy version of the library does show this issue.
I've also tried various firmware versions, such as adafruit-circuitpython-pyportal-en_US-7.0.0-alpha.1
with the library as taken from adafruit-circuitpython-bundle-7.x-mpy-20210410.zip
, as well as adafruit-circuitpython-pyportal-en_US-6.2.0
with the libraries taken from adafruit-circuitpython-bundle-6.x-mpy-20210409.zip
, which all exhibit this issue.
Maybe this isn't as clear as waiting for the network to initialize, as I'm a bit more confused why the source version behaves differently now.
Issue resolved: forums.adafruit.com/viewtopic.php?t=177959 forums.adafruit.com/viewtopic.php?t=177980
Fixed via #109. Thank you @Neradoc
I'm opening this as an issue before attempting a fix.
tl;dr: the object PyPortal doesnt properly initialize the network before attempting to use it. Should this be fixed?
I've been going through some of the examples on the Adafruit Learn site with the PyPortal and I keep on running into an issue resulting in a stacktrace when instantiating a
PyPortal
object like this:Taken from https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/master/PyPortal_Quotes/quote.py
This can be attributed to the line
if self.esp.is_connected:
in the constructor ofWiFi
:which is called from
Network
's constructor:which is called from the
PyPortal
constructor:So, the ultimate reason for the error is because the default constructor for
PyPortal
propagates a None value for the esp parameter intoNetwork
, which propagates it toWiFi
, which seemingly instantiates it correctly, but doesnt give time for theesp
object to properly connect to the network.An additional Learn article, https://learn.adafruit.com/adafruit-pyportal/internet-connect, lists a more complete example of connecting to a wireless network for the PyPortal product, which is copied here:
which simply checks for the ESP's status and will attempt to connect to the SSID with the given secrets as per the standard
secrets.py
file containing the secrets dictionary.There seems to be two possible solutions here:
esp
object that has already been configured and connected to the network.The first seems more user friendly and would allow people to continue to use the vast amounts of example code that already construct a
PyPortal
object without setting up a network connection, though the second option appears like a less invasive approach, though would continue to make all the example code on the Learn site and github broken by default.