@@ -448,18 +448,16 @@ def publish(self, topic, msg, retain=False, qos=0):
448
448
self ._check_qos (qos )
449
449
450
450
# fixed header
451
- pub_hdr_fixed = MQTT_PUB
451
+ pub_hdr_fixed = bytearray ()
452
+ pub_hdr_fixed .extend (MQTT_PUB )
452
453
pub_hdr_fixed [0 ] |= retain | qos << 1
453
454
454
-
455
455
# variable header
456
456
pub_hdr_var = bytearray ()
457
457
pub_hdr_var .append (len (topic ) >> 8 ) # Topic len MSB
458
458
pub_hdr_var .append (len (topic ) & 0xFF ) # Topic len LSB
459
459
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
463
461
464
462
remaining_length = 2 + len (msg ) + len (topic )
465
463
if qos > 0 :
@@ -476,14 +474,18 @@ def publish(self, topic, msg, retain=False, qos=0):
476
474
encoded_byte |= 0x80
477
475
pub_hdr_fixed .append (encoded_byte )
478
476
else :
479
- print ('remaining_length' , remaining_length )
480
477
pub_hdr_fixed .append (remaining_length )
481
478
479
+ print ('pub_hdr_fixed' , pub_hdr_fixed )
480
+ print ('pub_hdr_var' , pub_hdr_var )
482
481
483
482
self ._sock .send (pub_hdr_fixed )
484
483
self ._sock .send (pub_hdr_var )
485
484
self ._sock .send (msg )
486
485
486
+ import gc
487
+ gc .collect ()
488
+
487
489
def subscribe (self , topic , qos = 0 ):
488
490
"""Subscribes to a topic on the MQTT Broker.
489
491
This method can subscribe to one topics or multiple topics.
0 commit comments