src/eric7/MicroPython/Devices/MCUScripts/esp32WiFiConnect.py

branch
eric7
changeset 10153
ffe7432f716b
parent 9890
66a6d3f131cc
child 11038
918bc08e1f89
equal deleted inserted replaced
10152:33e7b9d3f91c 10153:ffe7432f716b
8 buf = bytearray(1024) 8 buf = bytearray(1024)
9 size = nvs.get_blob("ssid", buf) 9 size = nvs.get_blob("ssid", buf)
10 ssid = buf[:size].decode() 10 ssid = buf[:size].decode()
11 size = nvs.get_blob("password", buf) 11 size = nvs.get_blob("password", buf)
12 password = buf[:size].decode() 12 password = buf[:size].decode()
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
13 31
14 wifi = network.WLAN(network.STA_IF) 32 wifi = network.WLAN(network.STA_IF)
15 wifi.active(False) 33 wifi.active(False)
16 wifi.active(True) 34 wifi.active(True)
17 wifi.connect(ssid, password) 35 wifi.connect(ssid, password)
18 max_wait = 140 36 max_wait = 140
19 print("Connecting WiFi to '{0}'...".format(ssid))
20 while max_wait and wifi.status() == network.STAT_CONNECTING: 37 while max_wait and wifi.status() == network.STAT_CONNECTING:
21 max_wait -= 1 38 max_wait -= 1
22 sleep(0.1) 39 sleep(0.1)
23 print("Connection status:", wifi.isconnected()) 40 print("Connection status:", wifi.isconnected())
24 except: 41 except:

eric ide

mercurial