@@ -448,18 +448,16 @@ def publish(self, topic, msg, retain=False, qos=0):
448448 self ._check_qos (qos )
449449
450450 # fixed header
451- pub_hdr_fixed = MQTT_PUB
451+ pub_hdr_fixed = bytearray ()
452+ pub_hdr_fixed .extend (MQTT_PUB )
452453 pub_hdr_fixed [0 ] |= retain | qos << 1
453454
454-
455455 # variable header
456456 pub_hdr_var = bytearray ()
457457 pub_hdr_var .append (len (topic ) >> 8 ) # Topic len MSB
458458 pub_hdr_var .append (len (topic ) & 0xFF ) # Topic len LSB
459459 pub_hdr_var .extend (topic .encode ("utf-8" )) # Topic structure
460- # TODO: Add PID stuff back in
461- #pub_hdr_var.append(0x00) # pid msb
462- #pub_hdr_var.append(0xa) #'PID LSB
460+ # TODO: Add PID to variable header if qos > 0
463461
464462 remaining_length = 2 + len (msg ) + len (topic )
465463 if qos > 0 :
@@ -476,14 +474,18 @@ def publish(self, topic, msg, retain=False, qos=0):
476474 encoded_byte |= 0x80
477475 pub_hdr_fixed .append (encoded_byte )
478476 else :
479- print ('remaining_length' , remaining_length )
480477 pub_hdr_fixed .append (remaining_length )
481478
479+ print ('pub_hdr_fixed' , pub_hdr_fixed )
480+ print ('pub_hdr_var' , pub_hdr_var )
482481
483482 self ._sock .send (pub_hdr_fixed )
484483 self ._sock .send (pub_hdr_var )
485484 self ._sock .send (msg )
486485
486+ import gc
487+ gc .collect ()
488+
487489 def subscribe (self , topic , qos = 0 ):
488490 """Subscribes to a topic on the MQTT Broker.
489491 This method can subscribe to one topics or multiple topics.
0 commit comments