Skip to content

Commit d938bc0

Browse files
committed
(-) MQTT_PUB const; fixed pub_hdr_var.append()
1 parent 044d06c commit d938bc0

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
MQTT_PINGRESP = const(0xD0)
6363
MQTT_SUB = b"\x82"
6464
MQTT_UNSUB = b"\xA2"
65-
MQTT_PUB = bytearray(b"\x30")
6665
MQTT_DISCONNECT = b"\xe0\0"
6766

6867
# Variable CONNECT header [MQTT 3.1.2]
@@ -461,11 +460,11 @@ def publish(self, topic, msg, retain=False, qos=0):
461460
), "Quality of Service Level 2 is unsupported by this library."
462461

463462
# fixed header. [3.3.1.2], [3.3.1.3]
464-
pub_hdr_fixed = bytearray([MQTT_PUB[0] | retain | qos << 1])
463+
pub_hdr_fixed = bytearray([0x30 | retain | qos << 1])
465464

466465
# variable header = 2-byte Topic length (big endian)
467-
pub_hdr_var = struct.pack(">H", len(topic))
468-
pub_hdr_var.extend(topic.encode("utf-8")) # Topic name
466+
pub_hdr_var = bytearray(struct.pack(">H", len(topic)))
467+
pub_hdr_var.append(topic.encode("utf-8")) # Topic name
469468

470469
remaining_length = 2 + len(msg) + len(topic)
471470
if qos > 0:

0 commit comments

Comments
 (0)