|
1 try: |
|
2 from secrets import secrets |
|
3 |
|
4 def connectWiFi(): |
|
5 import wifi |
|
6 |
|
7 wifi.radio.start_station() |
|
8 try: |
|
9 wifi.radio.connect( |
|
10 secrets["ssid"], |
|
11 "" if secrets["password"] is None else secrets["password"] |
|
12 ) |
|
13 except Exception as exc: |
|
14 print("WiFi connection failed:", str(exc)) |
|
15 if wifi.radio.ipv4_address is None: |
|
16 print("WiFi connection failed") |
|
17 else: |
|
18 print("WiFi connected:", wifi.radio.ipv4_address) |
|
19 |
|
20 connectWiFi() |
|
21 except ImportError: |
|
22 print("WiFi secrets are kept in 'secrets.py', please add them there!") |