Skip to content

Commit

Permalink
Merge pull request #79 from dlizotte-uwo/master
Browse files Browse the repository at this point in the history
MQTT QOS=1,2 rules state that pid must be > 0.
  • Loading branch information
brentru committed Apr 5, 2021
2 parents a836197 + 5f079e7 commit c19c836
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions adafruit_minimqtt/adafruit_minimqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,9 @@ def publish(self, topic, msg, retain=False, qos=0):
if qos > 0:
# packet identifier where QoS level is 1 or 2. [3.3.2.2]
remaining_length += 2
pub_hdr_var.append(0x00)
pub_hdr_var.append(self._pid)
self._pid += 1
self._pid = self._pid + 1 if self._pid < 0xFFFF else 1
pub_hdr_var.append(self._pid >> 8)
pub_hdr_var.append(self._pid & 0xFF)

# Calculate remaining length [2.2.3]
if remaining_length > 0x7F:
Expand Down Expand Up @@ -668,7 +668,7 @@ def subscribe(self, topic, qos=0):
packet_length = 2 + (2 * len(topics)) + (1 * len(topics))
packet_length += sum(len(topic) for topic, qos in topics)
packet_length_byte = packet_length.to_bytes(1, "big")
self._pid += 1
self._pid = self._pid + 1 if self._pid < 0xFFFF else 1
packet_id_bytes = self._pid.to_bytes(2, "big")
# Packet with variable and fixed headers
packet = MQTT_SUB + packet_length_byte + packet_id_bytes
Expand Down Expand Up @@ -717,7 +717,7 @@ def unsubscribe(self, topic):
packet_length = 2 + (2 * len(topics))
packet_length += sum(len(topic) for topic in topics)
packet_length_byte = packet_length.to_bytes(1, "big")
self._pid += 1
self._pid = self._pid + 1 if self._pid < 0xFFFF else 1
packet_id_bytes = self._pid.to_bytes(2, "big")
packet = MQTT_UNSUB + packet_length_byte + packet_id_bytes
for t in topics:
Expand Down

0 comments on commit c19c836

Please sign in to comment.