Skip to content

Commit 5c15d23

Browse files
author
brentru
committed
check for a PUBLISH before a CONNACK
1 parent 4cade94 commit 5c15d23

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

adafruit_minimqtt.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,18 @@ def connect(self, clean_session=True):
275275
self._send_str(self._pass)
276276
if self._logger is not None:
277277
self._logger.debug('Receiving CONNACK packet from broker')
278-
rc = self._sock.read(4)
279-
assert rc[0] == const(0x20) and rc[1] == const(0x02)
280-
if rc[3] != 0:
281-
raise MMQTTException(CONNACK_ERRORS[rc[3]])
282-
self._is_connected = True
283-
result = rc[2] & 1
284-
if self.on_connect is not None:
285-
self.on_connect(self, self._user_data, result, rc[3])
286-
return result
278+
while True:
279+
op = self._wait_for_msg()
280+
if op == 32:
281+
rc = self._sock.read(3)
282+
assert rc[0] == const(0x02)
283+
if rc[2] != const(0x00):
284+
raise MMQTTException(CONNACK_ERRORS[rc[3]])
285+
self._is_connected = True
286+
result = rc[0] & 1
287+
if self.on_connect is not None:
288+
self.on_connect(self, self._user_data, result, rc[3])
289+
return result
287290

288291
def disconnect(self):
289292
"""Disconnects the MiniMQTT client from the MQTT broker.

0 commit comments

Comments
 (0)