muizenval

Observe mouse traps remotely
Log | Files | Refs

boot.py (764B)


      1 import sys
      2 import config
      3 import network
      4 from time import sleep
      5 from machine import Pin
      6 
      7 led2 = Pin(2, Pin.OUT)
      8 
      9 connection = network.WLAN(network.STA_IF)
     10 
     11 def 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 
     34 if __name__ == "__main__":
     35     connect()