Thu, 03 Aug 2023 17:33:07 +0200
MicroPython
- Added support to set the host name of the device (WiFi and Ethernet).
- Added support to set the WiFi country code (where supported by the device and the installed firmware).
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 picowireless as pw |
6 | from time import sleep | |
7 | ||
8 | print("Connecting WiFi to '{0}' ...".format(secrets.WIFI_SSID)) | |
9 | pw.init() | |
10 | if bool(secrets.WIFI_KEY): | |
11 | pw.wifi_set_passphrase(secrets.WIFI_SSID, secrets.WIFI_KEY) | |
12 | else: | |
13 | pw.wifi_set_network(secrets.WIFI_SSID) | |
14 | ||
15 | max_wait = 140 | |
16 | while max_wait: | |
17 | if pw.get_connection_status() == 3: | |
18 | break | |
19 | max_wait -= 1 | |
20 | sleep(0.1) | |
21 | if pw.get_connection_status() == 3: | |
22 | pw.set_led(0, 64, 0) | |
23 | print("WiFi connected:", '.'.join(str(i) for i in pw.get_ip_address())) | |
24 | else: | |
25 | pw.set_led(64, 0, 0) | |
26 | print("WiFi connection failed") | |
27 | ||
9890
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9836
diff
changeset
|
28 | connect_wifi() |
9836 | 29 | except ImportError: |
30 | print("WiFi secrets are kept in 'secrets.py', please add them there!") |