Skip to content

MQTT QOS=1,2 rules state that pid must be > 0. #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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