@@ -446,26 +446,24 @@ def publish(self, topic, msg, retain=False, qos=0):
446446 raise MMQTTException ("Message size larger than %d bytes." % MQTT_MSG_MAX_SZ )
447447 self ._check_qos (qos )
448448
449+ # fixed header
449450 pub_hdr_fixed = bytearray (b"\x30 " )
450451 pub_hdr_fixed [0 ] |= qos << 1 | retain
451452 pub_hdr_fixed .append (2 + len (msg ) + len (topic ))
452453
454+ # variable header
453455 pub_hdr_var = bytearray ()
454456 pub_hdr_var .append (len (topic ) >> 8 ) # Topic len MSB
455457 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
462462
463463 remaining_length = 7 + len (msg )
464464 if qos > 0 :
465465 remaining_length += 2 + len (qos )
466466
467-
468-
469467 # Remaining length calculation
470468 large_rel_length = False
471469 if remaining_length > 0x7f :
@@ -490,7 +488,6 @@ def publish(self, topic, msg, retain=False, qos=0):
490488
491489 self ._sock .send (pub_hdr_fixed )
492490 self ._sock .send (pub_hdr_var )
493- self ._send_str (topic )
494491 self ._sock .send (msg )
495492
496493 def subscribe (self , topic , qos = 0 ):
0 commit comments