-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__init__.py
82 lines (68 loc) · 2.3 KB
/
__init__.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import gc
import time
import urequests
import ugfx
import wifi
def clear(color):
ugfx.clear(ugfx.BLACK)
ugfx.flush()
ugfx.clear(ugfx.WHITE)
ugfx.flush()
ugfx.clear(color)
def wait_wifi():
clear(ugfx.BLACK)
ugfx.string(50, 25, "STILL", "Roboto_BlackItalic24", ugfx.WHITE)
ugfx.string(30, 50, "Connecting to wifi", "PermanentMarker22", ugfx.WHITE)
len = ugfx.get_string_width("Connecting to wifi", "PermanentMarker22")
ugfx.line(30, 72, 30 + 14 + len, 72, ugfx.WHITE)
ugfx.string(140, 75, "Anyway", "Roboto_BlackItalic24", ugfx.WHITE)
ugfx.flush()
while not wifi.sta_if.isconnected():
time.sleep(0.1)
def wait_sauna():
clear(ugfx.BLACK)
ugfx.string(50, 25, "STILL", "Roboto_BlackItalic24", ugfx.WHITE)
ugfx.string(30, 50, "Connecting to sauna", "PermanentMarker22", ugfx.WHITE)
len = ugfx.get_string_width("Connecting to sauna", "PermanentMarker22")
ugfx.line(30, 72, 30 + 14 + len, 72, ugfx.WHITE)
ugfx.string(140, 75, "Anyway", "Roboto_BlackItalic24", ugfx.WHITE)
ugfx.flush()
def show_temp(temperature):
clear(ugfx.BLACK)
ugfx.string(50, 25, "Sauna Finland PRKL", "Roboto_BlackItalic24", ugfx.WHITE)
ugfx.string(100, 50, str(temperature) + " C", "Roboto_BlackItalic24", ugfx.WHITE)
if temperature < 50:
ugfx.string(70, 75, "Good for Swedes", "Roboto_BlackItalic24", ugfx.WHITE)
elif temperature > 50 and temperature < 70:
ugfx.string(70, 75, "Heat is up!", "Roboto_BlackItalic24", ugfx.WHITE)
else:
ugfx.string(70, 75, "Good for Finns!", "Roboto_BlackItalic24", ugfx.WHITE)
ugfx.flush()
ugfx.init()
wifi.init()
wait_wifi()
temperature = None
while True:
try:
r = urequests.get("http://www.tarlab.fi/sensors/temperature1")
except:
if not wifi.sta_if.isconnected():
wifi.init()
wait_wifi()
else:
if r.status_code == 200:
gc.collect()
try:
temp = int(float(r.text))
except ValueError:
pass
else:
r.close()
if temp != temperature:
temperature = temp
show_temp(temperature)
time.sleep(60)
continue
temperature = None
wait_sauna()
time.sleep(31)