8000 Substract timestamps using ticks_diff() to account for wrap around (#36) · blynkkk/lib-python@ca5949b · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

Commit ca5949b

Browse files
authored
Substract timestamps using ticks_diff() to account for wrap around (#36)
From the utime documentation, ticks_diff() should be used to compare timestamps. They say the wrap around is implementation specific but on forums I see people saying it's about 298 hours/12 days which at least is the case for me on the tinypico. In this specific case, the wrap around means the deltas will be small negative numbers which in turn will make is_server_alive() return True for days without sending anymore pings to the server. We will soon after get disconnected and the application will pretty much stay forever in that state.
1 parent ef36f6e commit ca5949b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

blynklib_mp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ def receive(self, length, timeout):
186186
def is_server_alive(self):
187187
now = ticks_ms()
188188
h_beat_ms = self.heartbeat * const(1000)
189-
rcv_delta = now - self._last_rcv_time
190-
ping_delta = now - self._last_ping_time
191-
send_delta = now - self._last_send_time
189+
rcv_delta = time.ticks_diff(now, self._last_rcv_time)
190+
ping_delta = time.ticks_diff(now, self._last_ping_time)
191+
send_delta = time.ticks_diff(now, self._last_send_time)
192192
if rcv_delta > h_beat_ms + (h_beat_ms // const(2)):
193193
return False
194194
if (ping_delta > h_beat_ms // const(10)) and (send_delta > h_beat_ms or rcv_delta > h_beat_ms):

0 commit comments

Comments
 (0)
0