From f36ec4cf85a84d094c6b779b33004d5443e13184 Mon Sep 17 00:00:00 2001 From: Malachi Burke Date: Mon, 14 Dec 2015 20:10:00 -0800 Subject: [PATCH] Fixing reversal of topic/packet identifier (topic should come first) --- Adafruit_MQTT.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Adafruit_MQTT.cpp b/Adafruit_MQTT.cpp index 9cb0898..8d6beda 100644 --- a/Adafruit_MQTT.cpp +++ b/Adafruit_MQTT.cpp @@ -490,6 +490,7 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) { return len; } +// as per http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718040 uint8_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic, const char *data, uint8_t qos) { uint8_t *p = packet; @@ -499,6 +500,9 @@ uint8_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic, // fill in packet[1] last p+=2; + // topic comes before packet identifier + p = stringprint_P(p, topic); + // add packet identifier. used for checking PUBACK in QOS > 0 if(qos > 0) { p[0] = (packet_id_counter >> 8) & 0xFF; @@ -509,8 +513,6 @@ uint8_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic, packet_id_counter++; } - p = stringprint_P(p, topic); - memcpy(p, data, strlen(data)); p+=strlen(data); len = p - packet;