41
41
# io HTTP for getting the time from the internet
42
42
io = IO_HTTP (aio_username , aio_key , requests )
43
43
44
+ def reset_on_error (delay , error ):
45
+ print ("Error:\n " , str (error ))
46
+ print ("Resetting microcontroller in %d seconds" % delay )
47
+ time .sleep (delay )
48
+ microcontroller .reset ()
49
+
44
50
# function for making http requests with try/except
45
51
def get_request (tries , ping ):
46
52
for i in range (tries ):
@@ -56,7 +62,11 @@ def get_request(tries, ping):
56
62
return n
57
63
58
64
# get the time on start-up
59
- now = get_request (5 , io .receive_time ())
65
+ # pylint: disable=broad-except
66
+ try :
67
+ now = get_request (5 , io .receive_time ())
68
+ except Exception as e :
69
+ reset_on_error (10 , e )
60
70
print (now )
61
71
today = now .tm_mday
62
72
@@ -73,7 +83,13 @@ def sun_clock():
73
83
return _rise , _set
74
84
75
85
# initial API call
76
- sunrise , sunset = sun_clock ()
86
+ try :
87
+ sunrise , sunset = sun_clock ()
88
+ except Exception as e :
89
+ reset_on_error (10 , e )
90
+
91
+ print (sunrise )
92
+ print (sunset )
77
93
78
94
# the sunrise/sunset time is returned as a JSON aka a string
79
95
# this function chops up the string to get the hours and minutes as integers
@@ -95,6 +111,10 @@ def divide_time(z):
95
111
def sun_countdown (sun_event ):
96
112
n = get_request (5 , io .receive_time ())
97
113
remaining = time .mktime (sun_event ) - time .mktime (n )
114
+ < << << << Updated upstream
115
+ == == == =
116
+ r = remaining
117
+ >> >> >> > Stashed changes
98
118
# print(remaining)
99
119
# calculate the seconds remaining
100
120
secs_remaining = remaining % 60 # pylint: disable=unused-variable
@@ -105,10 +125,22 @@ def sun_countdown(sun_event):
105
125
# calculate the hours remaining
106
126
hours_until = remaining % 24
107
127
remaining //= 24
128
+ < << << << Updated upstream
108
129
return remaining , hours_until , minutes_until , n
109
130
110
131
total_until_rise , hours_until_sunrise , mins_until_sunrise , now = sun_countdown (rise_time )
111
132
total_until_set , hours_until_sunset , mins_until_sunset , now = sun_countdown (set_time )
133
+ == == == =
134
+ return r , hours_until , minutes_until , n
135
+ try :
136
+ total_until_rise , hours_until_sunrise , mins_until_sunrise , now = sun_countdown (rise_time )
137
+ except Exception as e :
138
+ reset_on_error (10 , e )
139
+ try :
140
+ total_until_set , hours_until_sunset , mins_until_sunset , now = sun_countdown (set_time )
141
+ except Exception as e :
142
+ reset_on_error (10 , e )
143
+ >> >> >> > Stashed changes
112
144
113
145
# red and yellow color percentage for neopixels
114
146
percent_red = 0
@@ -121,11 +153,27 @@ def sun_countdown(sun_event):
121
153
122
154
pixels = neopixel .NeoPixel (PIN , NUMPIXELS , brightness = BRIGHTNESS , auto_write = False )
123
155
156
+ print (total_until_set )
124
157
# check to see if the star fragment should be lit up on start-up
125
158
if total_until_set < 0 :
159
+ < << << << Updated upstream
160
+ == == == =
161
+ print ("star glow true" )
162
+ >> >> >> > Stashed changes
126
163
star_glow = True
164
+ percent_red = 255
165
+ percent_yellow = 125
166
+ # turn neopixels on using RGB values
167
+ pixels .fill ((percent_red , percent_yellow , 0 ))
168
+ pixels .show ()
127
169
else :
170
+ print ("star glow false" )
128
171
star_glow = False
172
+ percent_red = 0
173
+ percent_yellow = 0
174
+ # turn neopixels on using RGB values
175
+ pixels .fill ((percent_red , percent_yellow , 0 ))
176
+ pixels .show ()
129
177
130
178
# ticks time tracker
131
179
clock = ticks_ms ()
@@ -148,19 +196,33 @@ def sun_countdown(sun_event):
148
196
sunrise , sunset = sun_clock ()
149
197
(total_until_set , hours_until_sunset ,
150
198
mins_until_sunset , now ) = sun_countdown (set_time )
199
+ << << << < Updated upstream
200
+ == == == =
201
+ print (now )
202
+ >> >> >> > Stashed changes
151
203
print ("%d hour(s) until sunset" % hours_until_sunset )
152
204
print ("%d minutes(s) until sunset" % mins_until_sunset )
153
205
print (sunset )
154
206
print ()
155
207
# less than an hour until sunset...
208
+ < << << << Updated upstream
156
209
if hours_until_sunset == 0 or hours_until_sunset == 23 :
157
210
# check every minute
158
211
time_check = 60000
212
+ == == == =
213
+ if hours_until_sunset in (0 , 23 ):
214
+ # check every minute
215
+ time_check = 300000
216
+ > >> >> >> Stashed changes
159
217
# map color to ramp up in brightness over the course of the final hour
160
218
percent_red = simpleio .map_range (mins_until_sunset , 59 , 0 , 0 , 255 )
161
219
percent_yellow = simpleio .map_range (mins_until_sunset , 59 , 0 , 0 , 125 )
162
220
# if the sun has set..
221
+ < << << << Updated upstream
163
222
if mins_until_sunset < 1 :
223
+ == == == =
224
+ if total_until_set < 0 :
225
+ > >> >> >> Stashed changes
164
226
percent_red = 255
165
227
percent_yellow = 125
166
228
time_check = 900000
@@ -188,6 +250,7 @@ def sun_countdown(sun_event):
188
250
sunrise , sunset = sun_clock ()
189
251
(total_until_rise , hours_until_sunrise ,
190
252
mins_until_sunrise , now ) = sun_countdown (rise_time )
253
+ < << << << Updated upstream
191
254
print ("%d hour(s) until sunrise" % hours_until_sunrise )
192
255
print ("%d minutes(s) until sunrise" % mins_until_sunrise )
193
256
print (sunrise )
@@ -197,11 +260,26 @@ def sun_countdown(sun_event):
197
260
if hours_until_sunrise == 0 or hours_until_sunrise == 23 :
198
261
# check every minute
199
262
time_check = 60000
263
+ == == == =
264
+ print (now )
265
+ print ("%d hour(s) until sunrise" % hours_until_sunrise )
266
+ print ("%d minutes(s) until sunrise" % mins_until_sunrise )
267
+ print (sunrise )
268
+ print ()
269
+ # less than an hour until sunset...
270
+ if hours_until_sunrise in (0 , 23 ):
271
+ # check every minute
272
+ time_check = 300000
273
+ > >> >> >> Stashed changes
200
274
# map color to decrease brightness over the course of the final hour
201
275
percent_red = simpleio .map_range (mins_until_sunrise , 59 , 0 , 255 , 0 )
202
276
percent_yellow = simpleio .map_range (mins_until_sunrise , 59 , 0 , 125 , 0 )
203
277
# if the sun has risen..
278
+ < << << << Updated upstream
204
279
if mins_until_sunrise < 1 :
280
+ == == == =
281
+ if total_until_rise < 0 :
282
+ > >> >> >> Stashed changes
205
283
percent_red = 0
206
284
percent_yellow = 0
207
285
time_check = 900000
@@ -232,9 +310,14 @@ def sun_countdown(sun_event):
232
310
# turn neopixels on using RGB values
233
311
pixels .fill ((percent_red , percent_yellow , 0 ))
234
312
pixels .show ()
313
+ < << << << Updated upstream
235
314
# pylint: disable=broad-except
236
315
except Exception as e :
237
316
print ("Error:\n " , str (e ))
238
317
print ("Resetting microcontroller in 10 seconds" )
239
318
time .sleep (10 )
240
319
microcontroller .reset ()
320
+ == == == =
321
+ except Exception as e :
322
+ reset_on_error (10 , e )
323
+ >> >> >> > Stashed changes
0 commit comments