adds packet ids for publish QoS > 0
also adds packet id counter so packet ids aren't static values. this is a step in the direction of QoS 1 support
This commit is contained in:
parent
765a2feaff
commit
b9c9a28883
@ -225,7 +225,7 @@ bool Adafruit_MQTT::unsubscribe(Adafruit_MQTT_Subscribe *sub) {
|
|||||||
|
|
||||||
// if QoS for this subscription is 1 or 2, we need
|
// if QoS for this subscription is 1 or 2, we need
|
||||||
// to wait for the unsuback to confirm unsubscription
|
// to wait for the unsuback to confirm unsubscription
|
||||||
if(subscriptions[i]->qos > 0) {
|
if(subscriptions[i]->qos > 0 && MQTT_PROTOCOL_LEVEL > 3) {
|
||||||
|
|
||||||
// wait for UNSUBACK
|
// wait for UNSUBACK
|
||||||
len = readPacket(buffer, 5, CONNECT_TIMEOUT_MS);
|
len = readPacket(buffer, 5, CONNECT_TIMEOUT_MS);
|
||||||
@ -404,6 +404,16 @@ uint8_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
|
|||||||
// fill in packet[1] last
|
// fill in packet[1] last
|
||||||
p+=2;
|
p+=2;
|
||||||
|
|
||||||
|
// add packet identifier. used for checking PUBACK in QOS > 0
|
||||||
|
if(qos > 0) {
|
||||||
|
p[0] = (packet_id_counter >> 8) & 0xFF;
|
||||||
|
p[1] = packet_id_counter & 0xFF;
|
||||||
|
p+=2;
|
||||||
|
|
||||||
|
// increment the packet id
|
||||||
|
packet_id_counter++;
|
||||||
|
}
|
||||||
|
|
||||||
p = stringprint_P(p, topic);
|
p = stringprint_P(p, topic);
|
||||||
|
|
||||||
memcpy(p, data, strlen(data));
|
memcpy(p, data, strlen(data));
|
||||||
@ -424,11 +434,14 @@ uint8_t Adafruit_MQTT::subscribePacket(uint8_t *packet, const char *topic,
|
|||||||
// fill in packet[1] last
|
// fill in packet[1] last
|
||||||
p+=2;
|
p+=2;
|
||||||
|
|
||||||
// put in a message id,
|
// packet identifier. used for checking SUBACK
|
||||||
p[0] = 0xAD;
|
p[0] = (packet_id_counter >> 8) & 0xFF;
|
||||||
p[1] = 0xAF;
|
p[1] = packet_id_counter & 0xFF;
|
||||||
p+=2;
|
p+=2;
|
||||||
|
|
||||||
|
// increment the packet id
|
||||||
|
packet_id_counter++;
|
||||||
|
|
||||||
p = stringprint_P(p, topic);
|
p = stringprint_P(p, topic);
|
||||||
|
|
||||||
p[0] = qos;
|
p[0] = qos;
|
||||||
@ -450,12 +463,14 @@ uint8_t Adafruit_MQTT::unsubscribePacket(uint8_t *packet, const char *topic) {
|
|||||||
// fill in packet[1] last
|
// fill in packet[1] last
|
||||||
p+=2;
|
p+=2;
|
||||||
|
|
||||||
// packet identifier. used for QoS > 1
|
// packet identifier. used for checking UNSUBACK
|
||||||
// TODO: this shouldn't be a static value
|
p[0] = (packet_id_counter >> 8) & 0xFF;
|
||||||
p[0] = 0xAD;
|
p[1] = packet_id_counter & 0xFF;
|
||||||
p[1] = 0xAF;
|
|
||||||
p+=2;
|
p+=2;
|
||||||
|
|
||||||
|
// increment the packet id
|
||||||
|
packet_id_counter++;
|
||||||
|
|
||||||
p = stringprint_P(p, topic);
|
p = stringprint_P(p, topic);
|
||||||
|
|
||||||
len = p - packet;
|
len = p - packet;
|
||||||
|
@ -193,6 +193,7 @@ class Adafruit_MQTT {
|
|||||||
uint8_t will_qos;
|
uint8_t will_qos;
|
||||||
uint8_t will_retain;
|
uint8_t will_retain;
|
||||||
uint8_t buffer[MAXBUFFERSIZE]; // one buffer, used for all incoming/outgoing
|
uint8_t buffer[MAXBUFFERSIZE]; // one buffer, used for all incoming/outgoing
|
||||||
|
uint16_t packet_id_counter = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Adafruit_MQTT_Subscribe *subscriptions[MAXSUBSCRIPTIONS];
|
Adafruit_MQTT_Subscribe *subscriptions[MAXSUBSCRIPTIONS];
|
||||||
|
Loading…
Reference in New Issue
Block a user