-
Notifications
You must be signed in to change notification settings - Fork 293
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
MQTT with QOS 1 or 2 forbids a packet ID of 0. #190
Changes from 2 commits
4f76558
7b2061a
847f561
f4685f4
5b93947
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,7 +116,7 @@ Adafruit_MQTT::Adafruit_MQTT(const char *server, uint16_t port, const char *cid, | |
will_qos = 0; | ||
will_retain = 0; | ||
|
||
packet_id_counter = 0; | ||
packet_id_counter = 1; // MQTT spec forbids packet id of 0 if QOS=1 | ||
} | ||
|
||
Adafruit_MQTT::Adafruit_MQTT(const char *server, uint16_t port, | ||
|
@@ -137,7 +137,7 @@ Adafruit_MQTT::Adafruit_MQTT(const char *server, uint16_t port, | |
will_qos = 0; | ||
will_retain = 0; | ||
|
||
packet_id_counter = 0; | ||
packet_id_counter = 1; // MQTT spec forbids packet id of 0 if QOS=1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
} | ||
|
||
int8_t Adafruit_MQTT::connect() { | ||
|
@@ -342,7 +342,7 @@ bool Adafruit_MQTT::publish(const char *topic, uint8_t *data, uint16_t bLen, | |
|
||
// we increment the packet_id_counter right after publishing so inc here too | ||
// to match | ||
packnum++; | ||
packnum = packnum + 1 + (packnum + 1 == 0); // Skip zero | ||
if (packnum != packet_id_counter) | ||
return false; | ||
} | ||
|
@@ -709,8 +709,8 @@ uint16_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic, | |
p[1] = packet_id_counter & 0xFF; | ||
p += 2; | ||
|
||
// increment the packet id | ||
packet_id_counter++; | ||
// increment the packet id, skipping 0 | ||
packet_id_counter = packet_id_counter + 1 + (packet_id_counter + 1 == 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perform this within the check for QOS<1 on L729 instead There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
memmove(p, data, bLen); | ||
|
@@ -735,8 +735,8 @@ uint8_t Adafruit_MQTT::subscribePacket(uint8_t *packet, const char *topic, | |
p[1] = packet_id_counter & 0xFF; | ||
p += 2; | ||
|
||
// increment the packet id | ||
packet_id_counter++; | ||
// increment the packet id, skipping 0 | ||
packet_id_counter = packet_id_counter + 1 + (packet_id_counter + 1 == 0); | ||
|
||
p = stringprint(p, topic); | ||
|
||
|
@@ -764,8 +764,8 @@ uint8_t Adafruit_MQTT::unsubscribePacket(uint8_t *packet, const char *topic) { | |
p[1] = packet_id_counter & 0xFF; | ||
p += 2; | ||
|
||
// increment the packet id | ||
packet_id_counter++; | ||
// increment the packet id, skipping 0 | ||
packet_id_counter = packet_id_counter + 1 + (packet_id_counter + 1 == 0); | ||
|
||
p = stringprint(p, topic); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dlizotte-uwo this constructor does not guarantee a QoS level, we should handle checking and incrementing the PID based on the QoS level within the SUBSCRIBE, UNSUBSCRIBE, and PUBLISH calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brentru Hi, the QoS only needs to be checked for PUBLISH (and is already done in L707).
SUBSCRIBE and UNSUBSCRIBE always need a (valid) packet id
(Ref)
In PUBLISH QoS = 0, the packet id is not used.