Skip to content

Commit a30a80f

Browse files
author
brentru
committed
Re-enable QoS and Retain, test against broker
1 parent 59b8b07 commit a30a80f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"""
4343
import struct
4444
import time
45+
import gc
4546
from random import randint
4647
from micropython import const
4748
import adafruit_logging as logging
@@ -62,7 +63,7 @@
6263
MQTT_PINGRESP = const(0xD0)
6364
MQTT_SUB = b"\x82"
6465
MQTT_UNSUB = b"\xA2"
65-
MQTT_PUB = bytearray(b"\x30\0")
66+
MQTT_PUB = bytearray(b"\x30")
6667
MQTT_DISCONNECT = b"\xe0\0"
6768

6869
# Variable CONNECT header [MQTT 3.1.2]
@@ -440,16 +441,16 @@ def publish(self, topic, msg, retain=False, qos=0):
440441
msg = str(msg).encode("ascii")
441442
elif isinstance(msg, str):
442443
msg = str(msg).encode("utf-8")
443-
print(type(msg))
444444
else:
445445
raise MMQTTException("Invalid message data type.")
446446
if len(msg) > MQTT_MSG_MAX_SZ:
447447
raise MMQTTException("Message size larger than %d bytes." % MQTT_MSG_MAX_SZ)
448448
self._check_qos(qos)
449449

450450
# fixed header
451-
pub_hdr_fixed = bytearray(b"\x30")
452-
pub_hdr_fixed[0] |= qos << 1 | retain
451+
pub_hdr_fixed = MQTT_PUB
452+
pub_hdr_fixed[0] |= retain | qos << 1
453+
453454

454455
# variable header
455456
pub_hdr_var = bytearray()
@@ -462,7 +463,7 @@ def publish(self, topic, msg, retain=False, qos=0):
462463

463464
remaining_length = 2 + len(msg) + len(topic)
464465
if qos > 0:
465-
remaining_length += 2 + len(qos)
466+
remaining_length += 2 + qos
466467

467468
# Remaining length calculation
468469
if remaining_length > 0x7f:

0 commit comments

Comments
 (0)