-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-1.py
59 lines (46 loc) · 1.57 KB
/
main-1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from microwifimanager.manager import *
from machine import TouchPad, Pin, reset
from constants import *
from light import Light
from senko import Senko
import time, api
try:
light = Light(LED_PIN, NUM_LEDS)
touchPin = TouchPad(Pin(TOUCH_PIN))
OTA = Senko(user="graham768", repo="Familamps", files = UPDATE_FILES)
wlan = WifiManager(ssid="Familamp").get_connection()
if wlan is None:
print("Could not initialize the network connection.")
while True:
# fade red on/off until rebooted
light.changeColor(127, 0, 0, delay_ms=5)
light.changeColor(0, 0, 0, delay_ms=5)
if OTA.update():
print("Updated to the latest version! Rebooting...")
reset()
time.sleep(1) # allow glowBlue thread to recognize wifi connection
light.changeColor(*api.getColor())
lastRequest = 0
failCount = 0
while True:
time.sleep(1)
try:
# Check for an update every 10 seconds
if (time.time() - lastRequest) > 10:
# TODO WDT
lastRequest = time.time()
light.changeColor(*api.getColor())
if touchPin.read() < TOUCH_THRESHOLD:
print("I'm touched!")
light.blinkWhite()
light.changeColor(*COLOR)
resp = api.putColor(*COLOR)
except Exception:
light.blinkError()
failCount += 1
if failCount >= 5:
raise
except Exception:
# TODO Error logging
# reset()
raise