32 wifi = network.WLAN(network.STA_IF) |
52 wifi = network.WLAN(network.STA_IF) |
33 wifi.active(False) |
53 wifi.active(False) |
34 wifi.active(True) |
54 wifi.active(True) |
35 wifi.connect(ssid, password) |
55 wifi.connect(ssid, password) |
36 max_wait = 140 |
56 max_wait = 140 |
37 while max_wait and wifi.status() == network.STAT_CONNECTING: |
57 while max_wait and wifi.status() != network.STAT_GOT_IP: |
38 max_wait -= 1 |
58 max_wait -= 1 |
39 sleep(0.1) |
59 sleep(0.1) |
40 print("Connection status:", wifi.isconnected()) |
60 if wifi.isconnected(): |
|
61 print("WiFi connected:", wifi.ifconfig()[0]) |
|
62 if has_ntp(): |
|
63 set_ntp_time("pool.ntp.org", 0, 10) |
|
64 print("Time snchronized to network time (UTC).") |
|
65 else: |
|
66 print("WiFi connection failed. Status:", wifi.status()) |
41 except: |
67 except: |
42 print("WiFi secrets are kept in NVM. Please store them there!") |
68 print("WiFi secrets are kept in NVM. Please store them there!") |
43 |
69 |
44 connect_wifi() |
70 connect_wifi() |