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

branch
mpy_network
changeset 9836
902ec9a04ebe
child 9890
66a6d3f131cc
equal deleted inserted replaced
9835:b4b07de1b695 9836:902ec9a04ebe
1 try:
2 import secrets
3
4 def connectWiFi():
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
28 connectWiFi()
29 except ImportError:
30 print("WiFi secrets are kept in 'secrets.py', please add them there!")

eric ide

mercurial