move wifi to boot.py
This commit is contained in:
parent
816b83f6fd
commit
1fa59a0ca5
18
boot.py
18
boot.py
|
@ -1,2 +1,18 @@
|
|||
import esp
|
||||
esp.osdebug(None)
|
||||
import webrepl
|
||||
import config
|
||||
|
||||
def connect_wifi(ssid, psk):
|
||||
import network
|
||||
sta_if = network.WLAN(network.STA_IF)
|
||||
if not sta_if.isconnected():
|
||||
sta_if.active(True)
|
||||
sta_if.connect(ssid, psk)
|
||||
while not sta_if.isconnected():
|
||||
pass
|
||||
return(sta_if.ifconfig())
|
||||
|
||||
esp.osdebug(None)
|
||||
|
||||
connect_wifi(config.WIFI_SSID, config.WIFI_PSK)
|
||||
webrepl.start()
|
27
main.py
27
main.py
|
@ -3,7 +3,6 @@ import neopixel
|
|||
import config
|
||||
import ntptime
|
||||
import time
|
||||
import webrepl
|
||||
|
||||
def set_time(hour, minute):
|
||||
np_hour = neopixel.NeoPixel(machine.Pin(23), 24, bpp=4)
|
||||
|
@ -14,18 +13,6 @@ def set_time(hour, minute):
|
|||
np_minute[int(minute / 2)] = config.MINUTE_COLOR
|
||||
np_minute.write()
|
||||
|
||||
def connect_wifi(ssid, psk):
|
||||
import network
|
||||
sta_if = network.WLAN(network.STA_IF)
|
||||
if not sta_if.isconnected():
|
||||
sta_if.active(True)
|
||||
sta_if.connect(ssid, psk)
|
||||
while not sta_if.isconnected():
|
||||
pass
|
||||
webrepl.start()
|
||||
return(sta_if.ifconfig())
|
||||
|
||||
|
||||
def sync_ntptime():
|
||||
try:
|
||||
print("Syncing time...")
|
||||
|
@ -51,6 +38,11 @@ def check_daylight_saving(current_time):
|
|||
return True
|
||||
return False
|
||||
|
||||
def check_wifi_connection():
|
||||
import network
|
||||
sta_if = network.WLAN(network.STA_IF)
|
||||
return sta_if.isconnected
|
||||
|
||||
# Test LEDs before startup
|
||||
for hour in range(0, 11):
|
||||
set_time(hour, 0)
|
||||
|
@ -62,9 +54,10 @@ set_time(0, 0)
|
|||
|
||||
# Main Loop
|
||||
while True:
|
||||
|
||||
# Call connect_wifi to reconnect if connection is lost
|
||||
connect_wifi(config.WIFI_SSID, config.WIFI_PSK)
|
||||
|
||||
if not check_wifi_connection():
|
||||
machine.reset()
|
||||
|
||||
current_time = time.localtime()
|
||||
|
||||
# Sync time if we are on full hour
|
||||
|
@ -77,8 +70,6 @@ while True:
|
|||
else:
|
||||
current_time = time.localtime(time.mktime(current_time) + config.TIMEZONE_OFFSET)
|
||||
|
||||
|
||||
|
||||
print("Set Time:", current_time)
|
||||
set_time(current_time[3], current_time[4])
|
||||
time.sleep(1)
|
Loading…
Reference in New Issue