In my main processing loop seen below, I check between every loop iteration to verify there is a valid Wi-Fi connection:
Code: Select all
async def main_loop():
sta_if = network.WLAN(network.STA_IF)
sock = None
poller = None
while True:
try:
# This continuously try to create a Wi-Fi connection
while not sta_if.isconnected():
# connect to wifi
# This loop continuously tries to initialize the socket and poller
while sta_if.isconnected() and (sock is None or poller is None):
# initialize sock
# initialize poller
# This continuously polls the socket
while sta_if.isconnected() and sock and poller:
await uasyncio.sleep(0)
events = poller.poll(10)
for s, flags in events:
# process event
except Exception as e:
# handle error
Code: Select all
#7 ets_task(4020f4d0, 28, 3fff9038, 10)
connecting to the manseekingknowledge_test Wi-Fi network
running for 4658 seconds: connected to the manseekingknowledge_test Wi-Fi network
#8 ets_task(4020f4d0, 28, 3fff9038, 10)
connecting to the manseekingknowledge_test Wi-Fi network
running for 6605 seconds: connected to the manseekingknowledge_test Wi-Fi network
#9 ets_task(4020f4d0, 28, 3fff9038, 10)
connecting to the manseekingknowledge_test Wi-Fi network
running for 6910 seconds: connected to the manseekingknowledge_test Wi-Fi network
#10 ets_task(4020f4d0, 28, 3fff9038, 10)
connecting to the manseekingknowledge_test Wi-Fi network
running for 7806 seconds: connected to the manseekingknowledge_test Wi-Fi network
#11 ets_task(4020f4d0, 28, 3fff9038, 10)
connecting to the manseekingknowledge_test Wi-Fi network
running for 21411 seconds: connected to the manseekingknowledge_test Wi-Fi network
#12 ets_task(4020f4d0, 28, 3fff9038, 10)
connecting to the manseekingknowledge_test Wi-Fi network
running for 35288 seconds: connected to the manseekingknowledge_test Wi-Fi network
#13 ets_task(4020f4d0, 28, 3fff9038, 10)
connecting to the manseekingknowledge_test Wi-Fi network
running for 36769 seconds: connected to the manseekingknowledge_test Wi-Fi network
#14 ets_task(4020f4d0, 28, 3fff9038, 10)
connecting to the manseekingknowledge_test Wi-Fi network
running for 39043 seconds: connected to the manseekingknowledge_test Wi-Fi network
#15 ets_task(4020f4d0, 28, 3fff9038, 10)
connecting to the manseekingknowledge_test Wi-Fi network
running for 52228 seconds: connected to the manseekingknowledge_test Wi-Fi network
#16 ets_task(4020f4d0, 28, 3fff9038, 10)
connecting to the manseekingknowledge_test Wi-Fi network
running for 55125 seconds: connected to the manseekingknowledge_test Wi-Fi network