@@ -213,22 +213,22 @@ def blink(color):
213
213
# Initialise various time tracking variables.
214
214
ping_time = 0
215
215
check_time = 0
216
- ping_fail_time = time .monotonic ()
216
+ ping_fail_time = time .time ()
217
217
218
218
# Initialise ping fail count tracking.
219
219
ping_fail_count = 0
220
220
221
221
# ============ LOOP ============
222
222
while True :
223
- # Resets current_time to the current time.monotonic() value every time through the loop.
224
- current_time = time .monotonic ()
223
+ # Resets current_time to the current second every time through the loop.
224
+ current_time = time .time ()
225
225
# WiFi and IO connections can fail arbitrarily. The bulk of the loop is included in a
226
226
# try/except block to ensure the project will continue to run unattended if any
227
227
# failures do occur.
228
228
try :
229
229
# If this is the first run of the code or `UP_PING_INTERVAL` time has passed, continue.
230
230
if not ping_time or current_time - ping_time > UP_PING_INTERVAL :
231
- ping_time = time .monotonic ()
231
+ ping_time = time .time ()
232
232
# Ping to verify network connection.
233
233
wifi_ping = wifi .radio .ping (ip = ip_address )
234
234
if wifi_ping is not None :
@@ -240,7 +240,7 @@ def blink(color):
240
240
ping_fail_count = 0
241
241
# If this is the first run of the code or `TIME_CHECK_INTERVAL` has passed, continue.
242
242
if not check_time or current_time - check_time > TIME_CHECK_INTERVAL :
243
- check_time = time .monotonic ()
243
+ check_time = time .time ()
244
244
# Retrieve the time and save it to sundial.
245
245
sundial = io .receive_time ()
246
246
# Print the current date and time to the serial console.
@@ -253,7 +253,7 @@ def blink(color):
253
253
254
254
# If the ping has failed, and it's been one second, continue with this code.
255
255
if wifi_ping is None and current_time - ping_fail_time > 1 :
256
- ping_fail_time = time .monotonic () # Reset the ping fail time to continue tracking.
256
+ ping_fail_time = time .time () # Reset the ping fail time to continue tracking.
257
257
ping_fail_count += 1 # Add one to the fail count tracking.
258
258
print (f"Ping failed { ping_fail_count } times" )
259
259
# If network down detection is enabled, run the following code.
0 commit comments