@@ -446,26 +446,24 @@ def publish(self, topic, msg, retain=False, qos=0):
446
446
raise MMQTTException ("Message size larger than %d bytes." % MQTT_MSG_MAX_SZ )
447
447
self ._check_qos (qos )
448
448
449
+ # fixed header
449
450
pub_hdr_fixed = bytearray (b"\x30 " )
450
451
pub_hdr_fixed [0 ] |= qos << 1 | retain
451
452
pub_hdr_fixed .append (2 + len (msg ) + len (topic ))
452
453
454
+ # variable header
453
455
pub_hdr_var = bytearray ()
454
456
pub_hdr_var .append (len (topic ) >> 8 ) # Topic len MSB
455
457
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 )
458
+ pub_hdr_var .extend (topic .encode ("utf-8" )) # Topic structure
459
+ # TODO: Add PID stuff back in
460
+ #pub_hdr_var.append(0x00) # pid msb
461
+ #pub_hdr_var.append(0xa) #'PID LSB
462
462
463
463
remaining_length = 7 + len (msg )
464
464
if qos > 0 :
465
465
remaining_length += 2 + len (qos )
466
466
467
-
468
-
469
467
# Remaining length calculation
470
468
large_rel_length = False
471
469
if remaining_length > 0x7f :
@@ -490,7 +488,6 @@ def publish(self, topic, msg, retain=False, qos=0):
490
488
491
489
self ._sock .send (pub_hdr_fixed )
492
490
self ._sock .send (pub_hdr_var )
493
- self ._send_str (topic )
494
491
self ._sock .send (msg )
495
492
496
493
def subscribe (self , topic , qos = 0 ):
0 commit comments