Skip to content

Commit ab72e5d

Browse files
authored
Merge pull request #2512 from kattni/canary-use-time-time
Switch type of time used
2 parents 3c9ee49 + 4362352 commit ab72e5d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Canary_Nightlight/code.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,22 +213,22 @@ def blink(color):
213213
# Initialise various time tracking variables.
214214
ping_time = 0
215215
check_time = 0
216-
ping_fail_time = time.monotonic()
216+
ping_fail_time = time.time()
217217

218218
# Initialise ping fail count tracking.
219219
ping_fail_count = 0
220220

221221
# ============ LOOP ============
222222
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()
225225
# WiFi and IO connections can fail arbitrarily. The bulk of the loop is included in a
226226
# try/except block to ensure the project will continue to run unattended if any
227227
# failures do occur.
228228
try:
229229
# If this is the first run of the code or `UP_PING_INTERVAL` time has passed, continue.
230230
if not ping_time or current_time - ping_time > UP_PING_INTERVAL:
231-
ping_time = time.monotonic()
231+
ping_time = time.time()
232232
# Ping to verify network connection.
233233
wifi_ping = wifi.radio.ping(ip=ip_address)
234234
if wifi_ping is not None:
@@ -240,7 +240,7 @@ def blink(color):
240240
ping_fail_count = 0
241241
# If this is the first run of the code or `TIME_CHECK_INTERVAL` has passed, continue.
242242
if not check_time or current_time - check_time > TIME_CHECK_INTERVAL:
243-
check_time = time.monotonic()
243+
check_time = time.time()
244244
# Retrieve the time and save it to sundial.
245245
sundial = io.receive_time()
246246
# Print the current date and time to the serial console.
@@ -253,7 +253,7 @@ def blink(color):
253253

254254
# If the ping has failed, and it's been one second, continue with this code.
255255
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.
257257
ping_fail_count += 1 # Add one to the fail count tracking.
258258
print(f"Ping failed {ping_fail_count} times")
259259
# If network down detection is enabled, run the following code.

0 commit comments

Comments
 (0)