Sun, 16 Mar 2025 12:53:12 +0100
Added the Adafruit Feather nRF52840 to the list of known NRF52 boards and changed the list of known CircuitPython boards to be more explicit with respect to Adafruit boards (i.e. VID 0x239A).
9836 | 1 | try: |
2 | import secrets | |
3 | ||
9890
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9836
diff
changeset
|
4 | def connect_wifi(): |
9836 | 5 | import network |
6 | from time import sleep | |
7 | ||
8 | print("Connecting WiFi to '{0}' ...".format(secrets.WIFI_SSID)) | |
10153 | 9 | |
10 | if secrets.WIFI_HOSTNAME: | |
11 | try: | |
12 | network.hostname(secrets.WIFI_HOSTNAME) | |
13 | except AttributeError: | |
14 | pass | |
15 | ||
9836 | 16 | wifi = network.WLAN(network.STA_IF) |
17 | wifi.active(False) | |
18 | wifi.active(True) | |
19 | wifi.connect(secrets.WIFI_SSID, secrets.WIFI_KEY if secrets.WIFI_KEY else None) | |
20 | max_wait = 140 | |
21 | while max_wait: | |
22 | if wifi.status() < 0 or wifi.status() >= 3: | |
23 | break | |
24 | max_wait -= 1 | |
25 | sleep(0.1) | |
26 | if wifi.isconnected(): | |
27 | print("WiFi connected:", wifi.ifconfig()) | |
28 | else: | |
29 | print("WiFi connection failed") | |
30 | ||
9890
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9836
diff
changeset
|
31 | connect_wifi() |
9836 | 32 | except ImportError: |
33 | print("WiFi secrets are kept in 'secrets.py', please add them there!") |