Skip to content

Commit 55964b1

Browse files
author
brentru
committed
build variable header manually to verify topic structure
1 parent 60a57d4 commit 55964b1

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,21 @@ def publish(self, topic, msg, retain=False, qos=0):
451451
pub_hdr_fixed.append(2 + len(msg) + len(topic))
452452

453453
pub_hdr_var = bytearray()
454-
pub_hdr_var.extend(b"\x00\x17")
454+
pub_hdr_var.append(len(topic) >> 8) # Topic len MSB
455+
pub_hdr_var.append(len(topic) & 0xFF) # Topic len LSB
456+
pub_hdr_var.append(0x61) # 'a'
457+
pub_hdr_var.append(0x2F) #'/'
458+
pub_hdr_var.append(0x62) # 'b'
459+
pub_hdr_var.append(0x00) # pid msb
460+
pub_hdr_var.append(0xa) #'PID LSB
461+
print('pub_hdr_var ', pub_hdr_var)
455462

456463
remaining_length = 7 + len(msg)
457464
if qos > 0:
458465
remaining_length += 2 + len(qos)
466+
467+
468+
459469
# Remaining length calculation
460470
large_rel_length = False
461471
if remaining_length > 0x7f:
@@ -471,15 +481,17 @@ def publish(self, topic, msg, retain=False, qos=0):
471481
if large_rel_length:
472482
pub_hdr_fixed.append(0x00)
473483
else:
474-
pub_hdr_fixed.append(2)
475-
pub_hdr_fixed.append(0x00)
484+
# append MSB/LSB to header
485+
#pub_hdr_fixed.append(len(topic) >> 8)
486+
#pub_hdr_fixed.append(len(topic) & 0xFF)
487+
print(remaining_length)
476488
print(pub_hdr_fixed)
477489

478490

479491
self._sock.send(pub_hdr_fixed)
480492
self._sock.send(pub_hdr_var)
481493
self._send_str(topic)
482-
# self._sock.send(msg)
494+
self._sock.send(msg)
483495

484496
def subscribe(self, topic, qos=0):
485497
"""Subscribes to a topic on the MQTT Broker.

0 commit comments

Comments
 (0)