16 wifi = network.WLAN(network.STA_IF) |
16 wifi = network.WLAN(network.STA_IF) |
17 wifi.active(False) |
17 wifi.active(False) |
18 wifi.active(True) |
18 wifi.active(True) |
19 wifi.connect(secrets.WIFI_SSID, secrets.WIFI_KEY if secrets.WIFI_KEY else None) |
19 wifi.connect(secrets.WIFI_SSID, secrets.WIFI_KEY if secrets.WIFI_KEY else None) |
20 max_wait = 140 |
20 max_wait = 140 |
21 while max_wait: |
21 while max_wait and wifi.status() != network.STAT_GOT_IP: |
22 if wifi.status() < 0 or wifi.status() >= 3: |
|
23 break |
|
24 max_wait -= 1 |
22 max_wait -= 1 |
25 sleep(0.1) |
23 sleep(0.1) |
26 if wifi.isconnected(): |
24 if wifi.isconnected(): |
27 print("WiFi connected:", wifi.ifconfig()) |
25 print("WiFi connected:", wifi.ifconfig()) |
28 else: |
26 else: |