Skip to content

Commit 0223a92

Browse files
author
brentru
committed
only call on_publish once
1 parent f23d2b8 commit 0223a92

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,11 @@ def publish(self, topic, msg, retain=False, qos=0):
447447
raise MMQTTException("Message size larger than %d bytes." % MQTT_MSG_MAX_SZ)
448448
self._check_qos(qos)
449449

450-
# fixed header
451-
pub_hdr_fixed = bytearray()
450+
pub_hdr_fixed = bytearray() # fixed header
452451
pub_hdr_fixed.extend(MQTT_PUB)
453452
pub_hdr_fixed[0] |= retain | qos << 1
454453

455-
# variable header
456-
pub_hdr_var = bytearray()
454+
pub_hdr_var = bytearray() # variable header
457455
pub_hdr_var.append(len(topic) >> 8) # Topic len MSB
458456
pub_hdr_var.append(len(topic) & 0xFF) # Topic len LSB
459457
pub_hdr_var.extend(topic.encode("utf-8")) # Topic structure
@@ -488,9 +486,9 @@ def publish(self, topic, msg, retain=False, qos=0):
488486
)
489487
self._sock.send(pub_hdr_fixed)
490488
self._sock.send(pub_hdr_var)
491-
if self.on_publish is not None:
492-
self.on_publish(self, self.user_data, topic, self._pid)
493489
self._sock.send(msg)
490+
if qos == 0 and self.on_publish is not None:
491+
self.on_publish(self, self.user_data, topic, self._pid)
494492
if qos == 1:
495493
while True:
496494
op = self._wait_for_msg()

0 commit comments

Comments
 (0)