Sun, 03 Nov 2024 17:50:34 +0100
Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
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() | |
10153 | 13 | size = nvs.get_blob("hostname", buf) |
14 | hostname = buf[:size].decode() | |
15 | size = nvs.get_blob("country", buf) | |
16 | country = buf[:size].decode() | |
17 | ||
18 | print("Connecting WiFi to '{0}'...".format(ssid)) | |
19 | ||
20 | if country: | |
21 | try: | |
22 | network.country(country) | |
23 | except AttributeError: | |
24 | pass | |
25 | ||
26 | if hostname: | |
27 | try: | |
28 | network.hostname(hostname) | |
29 | except AttributeError: | |
30 | pass | |
9795 | 31 | |
32 | wifi = network.WLAN(network.STA_IF) | |
33 | wifi.active(False) | |
34 | wifi.active(True) | |
35 | wifi.connect(ssid, password) | |
36 | max_wait = 140 | |
37 | while max_wait and wifi.status() == network.STAT_CONNECTING: | |
38 | max_wait -= 1 | |
39 | sleep(0.1) | |
40 | print("Connection status:", wifi.isconnected()) | |
41 | except: | |
9828 | 42 | print("WiFi secrets are kept in NVM. Please store them there!") |
9795 | 43 | |
9890
66a6d3f131cc
Changed the MCU script to a pythonic naming.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9828
diff
changeset
|
44 | connect_wifi() |