@@ -443,28 +443,19 @@ def publish(self, topic, msg, retain=False, qos=0):
443
443
else :
444
444
raise MMQTTException ("Invalid message data type." )
445
445
if len (msg ) > MQTT_MSG_MAX_SZ :
446
- raise MMQTTException ("Message size larger than %db ." % MQTT_MSG_MAX_SZ )
446
+ raise MMQTTException ("Message size larger than %d bytes ." % MQTT_MSG_MAX_SZ )
447
447
self ._check_qos (qos )
448
448
449
449
pub_hdr_fixed = bytearray (b"\x30 " )
450
-
451
450
pub_hdr_fixed [0 ] |= qos << 1 | retain
452
- pub_hdr_fixed .append (len (msg ))
451
+ pub_hdr_fixed .append (2 + len (msg ) + len ( topic ))
453
452
454
453
pub_hdr_var = bytearray ()
455
454
pub_hdr_var .extend (b"\x00 \x17 " )
456
455
457
-
458
- print (len (topic ))
459
- print (len (msg ))
460
456
remaining_length = 7 + len (msg )
461
-
462
457
if qos > 0 :
463
458
remaining_length += 2 + len (qos )
464
-
465
- assert remaining_length < 2097152 # TODO: need a more descriptive error thrown here!
466
-
467
- """
468
459
# Remaining length calculation
469
460
large_rel_length = False
470
461
if remaining_length > 0x7f :
@@ -480,17 +471,13 @@ def publish(self, topic, msg, retain=False, qos=0):
480
471
if large_rel_length :
481
472
pub_hdr_fixed .append (0x00 )
482
473
else :
483
- pub_hdr_fixed.append(remaining_length )
474
+ pub_hdr_fixed .append (2 )
484
475
pub_hdr_fixed .append (0x00 )
485
476
print (pub_hdr_fixed )
486
- """
487
-
488
-
489
477
490
478
491
479
self ._sock .send (pub_hdr_fixed )
492
480
self ._sock .send (pub_hdr_var )
493
- # UP TO HERE!!
494
481
self ._send_str (topic )
495
482
# self._sock.send(msg)
496
483
0 commit comments