40 lines
878 B
Python
40 lines
878 B
Python
"""This file is executed on every boot (including wake-boot from deepsleep)"""
|
|
|
|
# import esp
|
|
# esp.osdebug(None)
|
|
import gc
|
|
import time
|
|
import network
|
|
import webrepl
|
|
from wifi_config import known_wifi_ap
|
|
|
|
# Connect to one of the known wifi AP
|
|
WLAN = network.WLAN(network.STA_IF)
|
|
WLAN.active(True)
|
|
AP_LIST = WLAN.scan()
|
|
|
|
for ap in AP_LIST:
|
|
if WLAN.isconnected():
|
|
break
|
|
|
|
ap_ssid = ap[0].decode("utf-8")
|
|
if ap_ssid in known_wifi_ap.keys():
|
|
print("Known wifi network found : {}".format(ap_ssid))
|
|
print("Try to connect...")
|
|
WLAN.connect(ap_ssid, known_wifi_ap[ap_ssid])
|
|
|
|
DELAY = 0
|
|
|
|
while not WLAN.isconnected():
|
|
print("Waiting for wifi to connect...")
|
|
time.sleep(1)
|
|
DELAY += 1
|
|
if DELAY > 10:
|
|
print("Wifi time-out")
|
|
break
|
|
|
|
webrepl.start()
|
|
|
|
print("Boot.py : Done")
|
|
gc.collect()
|