8000 Ensure millisecond precision in read_response() (#35) · blynkkk/lib-python@6832b99 · 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 6832b99

Browse files
authored
Ensure millisecond precision in read_response() (#35)
The micropython documentation for utime.time() states that on some hardware, the function only have second precision. This is the case at least for the TinyPICO board. This means that we get an effective 1 second timeout for the read_response() function instead of the expected 50ms. In turn, it makes the run() function quite slow which delays the whole application. To get higher precision, the documentation recommends to use utime.ticks_ms() instead which is what have been implemented here.
1 parent a3c09d2 commit 6832b99

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

blynklib_mp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ def process(self, msg_type, msg_id, msg_len, msg_args):
345345
self.call_handler("{}{}".format(self._VPIN_READ, msg_args[1]), int(msg_args[1]))
346346

347347
def read_response(self, timeout=0.5):
348-
end_time = time.time() + timeout
349-
while time.time() <= end_time:
348+
end_time = time.ticks_ms() + int(timeout * const(1000))
349+
while time.ticks_diff(end_time, time.ticks_ms()) > 0:
350350
rsp_data = self.receive(self.rcv_buffer, self.SOCK_TIMEOUT)
351351
if rsp_data:
352352
self._last_rcv_time = ticks_ms()

0 commit comments

Comments
 (0)
0