From 17808c3f14895837ee8e243c11788cbfb5508844 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 18 Oct 2022 09:55:02 +0200 Subject: [PATCH] examples: Update WiFi connect code. --- examples/micropython.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/micropython.py b/examples/micropython.py index 2ca99f3..2d05a50 100644 --- a/examples/micropython.py +++ b/examples/micropython.py @@ -87,8 +87,11 @@ def wifi_connect(): wlan = network.WLAN(network.STA_IF) wlan.active(True) - wlan.connect(WIFI_SSID, WIFI_PASS) - while (not wlan.isconnected()): + while not wlan.isconnected(): + try: + wlan.connect(WIFI_SSID, WIFI_PASS) + except Exception as e: + logging.error(f"Failed to connect to WiFi: {e}.") logging.info("Trying to connect. Note this may take a while...") time.sleep_ms(500) logging.info("WiFi Connected ", wlan.ifconfig())