-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
318 lines (252 loc) · 17.5 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import time, rgb, wifi, urequests, machine,virtualtimers,gc,system, valuestore
from default_icons import animation_connecting_wifi, icon_no_wifi
#https://github.com/badgeteam/ESP32-platform-firmware/blob/cdc6e4bd0759a58f8fe2310efd41775060a456c5/firmware/python_modules/campzone2019/default_icons.py
#https://stackoverflow.com/questions/3018313/algorithm-to-convert-rgb-to-hsv-and-hsv-to-rgb-in-range-0-255-for-both
#https://github.com/chubin/wttr.in/blob/master/lib/constants.py
brightness = rgb.getbrightness()
rgb.background((0,0,0))
maxcolor = 180
rgb.setfont(rgb.FONT_7x5)
#rgb.setfont(rgb.FONT_6x3)
rgb.clear()
rgb.framerate(1)
print("Mem free after setup:",gc.mem_free())
gc.collect()
print("Mem free after clear:",gc.mem_free())
def moonphase(moon,x,y):
x = 24
y = 0
if moon == "🌑":
# newmoon🌑.gif
rgb.gif([0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00], (x, y),( 9, 8), 1)
elif moon == "🌒":
# waxingcrescent🌒.gif
rgb.gif([0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00], (x, y),( 9, 8), 1)
elif moon == "🌓":
# firstquarter🌓.gif
rgb.gif([0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00], (x, y),( 9, 8), 1)
elif moon == "🌔":
# waxinggibbous🌔.gif
rgb.gif([0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00], (x, y),( 9, 8), 1)
elif moon == "🌕":
# fullmoon🌕.gif
rgb.gif([0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00], (x, y),( 9, 8), 1)
elif moon == "🌖":
# waninggibbous🌖.gif
rgb.gif([0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00], (x, y),( 9, 8), 1)
elif moon == "🌗":
# lastquarter🌗.gif
rgb.gif([0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00], (x, y),( 9, 8), 1)
elif moon == "🌘":
# waningcrescent🌘.gif
rgb.gif([0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xe4a204ff, 0xe4a204ff, 0x093752ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xe4a204ff, 0x093752ff, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0x093752ff, 0x093752ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00], (x, y),( 9, 8), 1)
else:
# errorstate✨.gif
rgb.gif([0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00, 0xffffff00, 0xb03248ff, 0xffffff00, 0xffffff00], (x, y),( 9, 8), 2)
def condition(emoji,x,y):
print("Mem free for gif: ",gc.mem_free())
gc.collect()
print("Mem free after clear:",gc.mem_free())
if emoji == "☀️":
print("sunny☀️.gif")
from .sunny import data
elif emoji == "☁️":
print("cloudy☁️.gif")
from .cloudy import data
elif emoji == "⛅️":
print("partlycloudy⛅️.gif")
from .partlycloudy import data
elif emoji == "❄️":
print("snow❄️.gif")
from .snow import data
elif emoji =="⛈":
print("thunderstorm⛈.gif")
from .thunderstorm import data
elif emoji =="🌧":
print("rain🌧.gif")
from .rain import data
elif emoji =="🌦":
print("sunbehindcloudwithrain🌦.gif")
from .sunbehindcloudwithrain import data
else:
print("errorstate✨.gif")
from .errorstate import data
img, pos, size, frames = data
rgb.gif(img,(x,y), size, frames)
del data
gc.collect()
def mapToHSV(value):
#https://stackoverflow.com/questions/1969240/mapping-a-range-of-values-to-another/1969274
minTemp= 0
maxTemp= 35
minHSVColor= 0
maxHSVColor= 240
if value >= maxTemp:
print("red hot")
color = (255,0,0)
elif value > minTemp and value < maxTemp:
# Figure out how 'wide' each range is
tempSpan = maxTemp - minTemp
HSVColorSpan = maxHSVColor - minHSVColor
# Convert the left range into a 0-1 range (float)
valueScaled = float(value - minTemp) / float(tempSpan)
# Convert the 0-1 range into a value in the right range.
hsv= int(maxHSVColor - (valueScaled * HSVColorSpan))
print("HSV color:",hsv)
color = hsv_to_rgb(hsv/360.,1,1)
else:
print("white cold")
color = (255,255,255)
return color
##################################################################
#https://stackoverflow.com/questions/24852345/hsv-to-rgb-color-conversion
def hsv_to_rgb(h, s, v):
if s == 0.0: v*=255; return (v, v, v)
i = int(h*6.) # XXX assume int() truncates!
f = (h*6.)-i; p,q,t = int(255*(v*(1.-s))), int(255*(v*(1.-s*f))), int(255*(v*(1.-s*(1.-f)))); v*=255; i%=6
if i == 0: return (v, t, p)
if i == 1: return (q, v, p)
if i == 2: return (p, v, t)
if i == 3: return (p, q, v)
if i == 4: return (t, p, v)
if i == 5: return (v, p, q)
def wttrin():
#wttrinAPI = 'http://wttr.in/?format="%t+%c:+%S+%s+%m"' #semicolon was there to add a space, suddenly in Jan 16 it doesnt work anymore
while True:
#import valuestore
#valuestore.save('pixelWeather', 'settings', {"localisation":"CITYNAMEHERE"}) #Use this to save your location manually instead of using IP based geolocalisation
try:
settings = valuestore.load('pixelWeather', 'settings')
if settings['localisation'] == "":
raise Exception
else:
print("Using manual localisation:"+ str(settings['localisation']))
wttrinAPI = 'http://wttr.in/{}?format="%t+%S+%s+%m+%c+%l+%T"'.format(settings['localisation'])
except:
print("Using IP based localisation")
wttrinAPI = 'http://wttr.in/?format="%t+%S+%s+%m+%c+%l+%T"'
wttrinAPI = urequests.get(wttrinAPI)
print("wttr.in HTTP request status Code:",wttrinAPI.status_code)
#print(r.status_code)
if wttrinAPI.status_code == 200:
break
else:
# Hope it won't 500 a little later
print("Bad response")
time.sleep(5)
continue
wttrin = wttrinAPI.text
wttrin = wttrin[1:-1] # strip "" of string
print("Data:",wttrin)
wttrinAPI.close()
gc.collect()
chunks = wttrin.split(' ')
print("Chunks:",chunks)
temp = chunks[0]
#print("temp:",temp)
#temp = "-8dcc"
if temp[0] == "+":
temp = temp[1:]
chunks[0] = int(temp[:-2])
print("temp:",chunks[0])
print("sunrise:",chunks[1])
print("sunset :",chunks[2])
print("moonphase:",chunks[3])
#chunks[4] = chunks[4][:1]
print("condition:", chunks[4])
return chunks
def setTime():
rtc = machine.RTC()
print("Time before:",rtc.datetime())
while True:
worldTimeAPI = "http://worldtimeapi.org/api/ip"
request = urequests.get(worldTimeAPI)
print("WorldtimeAPI HTTP request status Code:",request.status_code)
#print(r.status_code)
if request.status_code == 200:
break
else:
# Hope it won't 500 a little later
print("Bad response")
time.sleep(5)
continue
result = request.json()
request.close()
gc.collect()
unixtime = result['unixtime']
raw_offset = result["raw_offset"]
localtime = time.localtime(unixtime)
rtc.init(localtime)
timezone = str('UTC-{}'.format(int(raw_offset/3600)))
machine.nvs_setstr('system', 'timezone', timezone)
rtc.timezone(timezone)
print("Time now:",rtc.now())
print("Local time:",time.localtime())
print("GMT time:",time.gmtime())
def wifiConnect():
while not wifi.status():
print("Connecting to WiFi")
data, size, frames = animation_connecting_wifi
rgb.clear()
rgb.framerate(3)
rgb.gif(data, (12, 0), size, frames)
wifi.connect()
if wifi.wait():
rgb.clear()
rgb.framerate(20)
print("WiFi Connected!")
time.sleep(1)
setTime()
break
else:
msg = "No wifi"
print(msg)
rgb.clear()
rgb.framerate(20)
data, frames = icon_no_wifi
rgb.image(data, (12, 0), (8,8))
time.sleep(3)
rgb.clear()
continue
def refresh():
wifiConnect()
rgb.framerate(1)
weather = wttrin()
sunrise = sum(int(x) * 60 ** i for i, x in enumerate(reversed(weather[1].split(':'))))
timeNow= sum(int(x) * 60 ** i for i, x in enumerate(reversed(time.strftime("%H:%M:%S",time.localtime()).split(':'))))
sunset= sum(int(x) * 60 ** i for i, x in enumerate(reversed(weather[2].split(':'))))
print("sunrise:",sunrise)
print("timenow:",timeNow)
print("sunset:",sunset)
rgb.clear()
output = "{}".format(weather[0])+"\u00B0" #adding degree sign, thanks Tom~
color= mapToHSV(weather[0])
rgb.text(output, color, (0, 1))
#import valuestore
#qq #Use this to keep showing current weather condition aftersunset
try:
settings = valuestore.load('pixelWeather', 'settings')
if settings['showMoon'] == "":
raise Exception
elif settings['showMoon'] == True:
moonphase(weather[3],23,0)
elif settings['showMoon'] == False:
condition(weather[4],23,0)
else:
raise Exception
except:
if sunrise < timeNow and timeNow < sunset: #It is daytime
condition(weather[4],23,0) #should implement dynamic postion depending on width of gif
else:
moonphase(weather[3],23,0)
print("Mem free after gif: ",gc.mem_free())
def wrapper():
try:
refresh()
run_again_in = 60000 # time until this function should run again, in ms
return run_again_in
except:
system.reboot()
# Initialise the virtualtimers task, and register our function
virtualtimers.begin(100)
virtualtimers.new(0, wrapper) # run now, with 0 delay