You've already forked Adafruit_MQTT_Library
mirror of
https://github.com/adafruit/Adafruit_MQTT_Library.git
synced 2025-07-21 18:22:06 +03:00
MQTT with QOS 1 or 2 forbids a packet ID of 0.
This commit is contained in:
@ -116,7 +116,7 @@ Adafruit_MQTT::Adafruit_MQTT(const char *server, uint16_t port, const char *cid,
|
|||||||
will_qos = 0;
|
will_qos = 0;
|
||||||
will_retain = 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,
|
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_qos = 0;
|
||||||
will_retain = 0;
|
will_retain = 0;
|
||||||
|
|
||||||
packet_id_counter = 0;
|
packet_id_counter = 1; // MQTT spec forbids packet id of 0 if QOS=1
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t Adafruit_MQTT::connect() {
|
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
|
// we increment the packet_id_counter right after publishing so inc here too
|
||||||
// to match
|
// to match
|
||||||
packnum++;
|
packnum = packnum + 1 + (packnum + 1 == 0); //Skip zero
|
||||||
if (packnum != packet_id_counter)
|
if (packnum != packet_id_counter)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -709,8 +709,8 @@ uint16_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
|
|||||||
p[1] = packet_id_counter & 0xFF;
|
p[1] = packet_id_counter & 0xFF;
|
||||||
p += 2;
|
p += 2;
|
||||||
|
|
||||||
// increment the packet id
|
// increment the packet id, skipping 0
|
||||||
packet_id_counter++;
|
packet_id_counter = packet_id_counter + 1 + (packet_id_counter + 1 == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
memmove(p, data, bLen);
|
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[1] = packet_id_counter & 0xFF;
|
||||||
p += 2;
|
p += 2;
|
||||||
|
|
||||||
// increment the packet id
|
// increment the packet id, skipping 0
|
||||||
packet_id_counter++;
|
packet_id_counter = packet_id_counter + 1 + (packet_id_counter + 1 == 0);
|
||||||
|
|
||||||
p = stringprint(p, topic);
|
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[1] = packet_id_counter & 0xFF;
|
||||||
p += 2;
|
p += 2;
|
||||||
|
|
||||||
// increment the packet id
|
// increment the packet id, skipping 0
|
||||||
packet_id_counter++;
|
packet_id_counter = packet_id_counter + 1 + (packet_id_counter + 1 == 0);
|
||||||
|
|
||||||
p = stringprint(p, topic);
|
p = stringprint(p, topic);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user