@@ -451,11 +451,21 @@ def publish(self, topic, msg, retain=False, qos=0):
451
451
pub_hdr_fixed .append (2 + len (msg ) + len (topic ))
452
452
453
453
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 )
455
462
456
463
remaining_length = 7 + len (msg )
457
464
if qos > 0 :
458
465
remaining_length += 2 + len (qos )
466
+
467
+
468
+
459
469
# Remaining length calculation
460
470
large_rel_length = False
461
471
if remaining_length > 0x7f :
@@ -471,15 +481,17 @@ def publish(self, topic, msg, retain=False, qos=0):
471
481
if large_rel_length :
472
482
pub_hdr_fixed .append (0x00 )
473
483
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 )
476
488
print (pub_hdr_fixed )
477
489
478
490
479
491
self ._sock .send (pub_hdr_fixed )
480
492
self ._sock .send (pub_hdr_var )
481
493
self ._send_str (topic )
482
- # self._sock.send(msg)
494
+ self ._sock .send (msg )
483
495
484
496
def subscribe (self , topic , qos = 0 ):
485
497
"""Subscribes to a topic on the MQTT Broker.
0 commit comments