Skip to content

Commit 4cade94

Browse files
author
brentru
committed
add a wait_for_msg call to catch any async publish before pingresp
1 parent 6d928e4 commit 4cade94

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

adafruit_minimqtt.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,13 @@ def ping(self):
310310
self._sock.write(MQTT_PINGREQ)
311311
if self._logger is not None:
312312
self._logger.debug('Checking PINGRESP')
313-
ping_resp = self._sock.read(2)
314-
if ping_resp[0] != MQTT_PINGRESP or ping_resp[1] != const(0x00):
315-
raise MMQTTException('PINGRESP not returned from broker.')
313+
while 1:
314+
op = self._wait_for_msg(0.5)
315+
if op == const(208):
316+
ping_resp = self._sock.read(2)
317+
if ping_resp[0] != const(0x00):
318+
raise MMQTTException('PINGRESP not returned from broker.')
319+
return
316320

317321
# pylint: disable=too-many-branches, too-many-statements
318322
def publish(self, topic, msg, retain=False, qos=0):

0 commit comments

Comments
 (0)