Tue, 26 Nov 2024 19:46:36 +0100
Improved the CircuitPython device class and fixed som issues in the MPy REPL and main widget.
9828 | 1 | try: |
2 | from secrets 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(): |
9828 | 5 | import wifi |
6 | ||
9836 | 7 | print("Connecting WiFi to '{0}' ...".format(secrets["ssid"])) |
10153 | 8 | |
9 | if secrets["hostname"]: | |
10 | wifi.radio.hostname = secrets["hostname"] | |
11 | ||
9828 | 12 | wifi.radio.start_station() |
13 | try: | |
14 | wifi.radio.connect( | |
15 | secrets["ssid"], | |
16 | "" if secrets["password"] is None else secrets["password"] | |
17 | ) | |
18 | except Exception as exc: | |
19 | print("WiFi connection failed:", str(exc)) | |
20 | if wifi.radio.ipv4_address is None: | |
21 | print("WiFi connection failed") | |
22 | else: | |
23 | print("WiFi connected:", wifi.radio.ipv4_address) | |
24 | ||
9890
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9836
diff
changeset
|
25 | connect_wifi() |
9828 | 26 | except ImportError: |
27 | print("WiFi secrets are kept in 'secrets.py', please add them there!") |