Tue, 21 Mar 2023 11:23:42 +0100
MicroPython
- Added a 'reset' capability to the PyBoard and Teensy menus.
9890
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9828
diff
changeset
|
1 | def connect_wifi(): |
9795 | 2 | import esp32 |
3 | import network | |
4 | from time import sleep | |
5 | ||
6 | try: | |
7 | nvs = esp32.NVS("wifi_creds") | |
8 | buf = bytearray(1024) | |
9 | size = nvs.get_blob("ssid", buf) | |
10 | ssid = buf[:size].decode() | |
11 | size = nvs.get_blob("password", buf) | |
12 | password = buf[:size].decode() | |
13 | ||
14 | wifi = network.WLAN(network.STA_IF) | |
15 | wifi.active(False) | |
16 | wifi.active(True) | |
17 | wifi.connect(ssid, password) | |
18 | max_wait = 140 | |
19 | print("Connecting WiFi to '{0}'...".format(ssid)) | |
20 | while max_wait and wifi.status() == network.STAT_CONNECTING: | |
21 | max_wait -= 1 | |
22 | sleep(0.1) | |
23 | print("Connection status:", wifi.isconnected()) | |
24 | except: | |
9828 | 25 | print("WiFi secrets are kept in NVM. Please store them there!") |
9795 | 26 | |
9890
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9828
diff
changeset
|
27 | connect_wifi() |