Sat, 15 Apr 2023 18:22:09 +0200
MicroPython
- Added a package installer for devices lacking network connectivity and the `mip` package manager.
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"])) |
9828 | 8 | wifi.radio.start_station() |
9 | try: | |
10 | wifi.radio.connect( | |
11 | secrets["ssid"], | |
12 | "" if secrets["password"] is None else secrets["password"] | |
13 | ) | |
14 | except Exception as exc: | |
15 | print("WiFi connection failed:", str(exc)) | |
16 | if wifi.radio.ipv4_address is None: | |
17 | print("WiFi connection failed") | |
18 | else: | |
19 | print("WiFi connected:", wifi.radio.ipv4_address) | |
20 | ||
9890
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9836
diff
changeset
|
21 | connect_wifi() |
9828 | 22 | except ImportError: |
23 | print("WiFi secrets are kept in 'secrets.py', please add them there!") |