Skip to content

Commit 9f4c8fd

Browse files
MQTT connect with an empty username should have the proper header
Connect needs to distinguish None from an empty string when populating and sending CONNECT to the MQTT broker. Fixes #129 Signed-off-by: Flavio Fernandes <flavio@flaviof.com>
1 parent b707805 commit 9f4c8fd

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ def connect(self, clean_session=True, host=None, port=None, keep_alive=None):
482482

483483
# Set up variable header and remaining_length
484484
remaining_length = 12 + len(self.client_id.encode("utf-8"))
485-
if self._username:
485+
if self._username is not None:
486486
remaining_length += (
487487
2
488488
+ len(self._username.encode("utf-8"))
@@ -532,9 +532,7 @@ def connect(self, clean_session=True, host=None, port=None, keep_alive=None):
532532
# [MQTT-3.1.3-11]
533533
self._send_str(self._lw_topic)
534534
self._send_str(self._lw_msg)
535-
if self._username is None:
536-
self._username = None
537-
else:
535+
if self._username is not None:
538536
self._send_str(self._username)
539537
self._send_str(self._password)
540538
if self.logger is not None:

0 commit comments

Comments
 (0)