Skip to content

Commit a022705

Browse files
authored
Merge pull request #227 from brentru/fix-msg-i2c-decode-err
Fix how subscription packet length is calculated
2 parents c84b63f + 4ba2fee commit a022705

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Adafruit_MQTT.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,12 @@ Adafruit_MQTT_Subscribe *Adafruit_MQTT::handleSubscriptionPacket(uint16_t len) {
563563
}
564564

565565
// Parse out length of packet.
566-
uint16_t const topicoffset = packetAdditionalLen(len);
566+
// NOTE: This includes data in the variable header and the payload.
567+
uint16_t remainingLen = len - 4; // subtract the 4 header bytes
568+
uint16_t const topicoffset = packetAdditionalLen(remainingLen);
567569
uint16_t const topicstart = topicoffset + 4;
568-
topiclen = buffer[3 + topicoffset];
570+
571+
topiclen = int((buffer[2 + topicoffset]) << 8 | buffer[3 + topicoffset]);
569572
DEBUG_PRINT(F("Looking for subscription len "));
570573
DEBUG_PRINTLN(topiclen);
571574

Adafruit_MQTT.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,14 @@
107107
// Largest full packet we're able to send.
108108
// Need to be able to store at least ~90 chars for a connect packet with full
109109
// 23 char client ID.
110+
// Future TODO: This should be replaced by the ability to dynamically allocate a
111+
// buffer as needed.
112+
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) || \
113+
defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_SAMD)
114+
#define MAXBUFFERSIZE (512)
115+
#else
110116
#define MAXBUFFERSIZE (150)
117+
#endif
111118

112119
#define MQTT_CONN_USERNAMEFLAG 0x80
113120
#define MQTT_CONN_PASSWORDFLAG 0x40
@@ -124,7 +131,7 @@
124131
#define SUBSCRIPTIONDATALEN 20
125132
#else
126133
#define MAXSUBSCRIPTIONS 15
127-
#define SUBSCRIPTIONDATALEN 100
134+
#define SUBSCRIPTIONDATALEN MAXBUFFERSIZE
128135
#endif
129136

130137
class AdafruitIO_MQTT; // forward decl

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit MQTT Library
2-
version=2.5.7
2+
version=2.5.8
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=MQTT library that supports the FONA, ESP8266, ESP32, Yun, and generic Arduino Client hardware.

0 commit comments

Comments
 (0)