Skip to content

Commit 0a1b340

Browse files
committed
adafruit_minimqtt: Fix issue adafruit#86 with multiple poll() PINGREQs
If I set timeout to zero there is a problem as the poll() call will be called multiple times while a ping request is outstanding and this results in multiple ping requests being made. I see 3-5 at a time with DEBUG logging on. This is because self._timestamp is being reset after self.ping() The solution seems to be pretty straightforward which is to reset self._timestamp() before sending the ping() Signed-off-by: Alex J Lennon <[email protected]>
1 parent eccc36f commit 0a1b340

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,13 +776,13 @@ def loop(self, timeout=1):
776776
self._timestamp = time.monotonic()
777777
current_time = time.monotonic()
778778
if current_time - self._timestamp >= self.keep_alive:
779+
self._timestamp = 0
779780
# Handle KeepAlive by expecting a PINGREQ/PINGRESP from the server
780781
if self.logger is not None:
781782
self.logger.debug(
782783
"KeepAlive period elapsed - requesting a PINGRESP from the server..."
783784
)
784785
rcs = self.ping()
785-
self._timestamp = 0
786786
return rcs
787787
self._sock.settimeout(timeout)
788788
rc = self._wait_for_msg()

0 commit comments

Comments
 (0)