boot.py (764B) download
1import sys
2import config
3import network
4from time import sleep
5from machine import Pin
6
7led2 = Pin(2, Pin.OUT)
8
9connection = network.WLAN(network.STA_IF)
10
11def connect():
12
13 if connection.isconnected():
14 print("Already connected")
15 led2.on()
16 return
17
18 connection.active(True)
19 connection.connect(config.WIFI_SSID, config.WIFI_PASSWORD)
20
21 retry = 0
22 while not connection.isconnected(): # wait until connection is complete
23 if retry == 10: # try 10 times
24 sys.exit("Could not establish connection, check your settings")
25 retry += 1
26
27 sleep(1) # check again in a sec
28
29 # no exit, we have a connection!
30 print("Connection established")
31 led2.on()
32
33
34if __name__ == "__main__":
35 connect()