diff --git a/Adafruit_MQTT.cpp b/Adafruit_MQTT.cpp index f2e3b50..c0de9c9 100644 --- a/Adafruit_MQTT.cpp +++ b/Adafruit_MQTT.cpp @@ -30,8 +30,8 @@ static char *dtostrf (double val, signed char width, unsigned char prec, char *s } #endif -void printBuffer(uint8_t *buffer, uint8_t len) { - for (uint8_t i=0; i (maxsize - (pbuff-buffer) - 1)) { + DEBUG_PRINTLN(F("Packet too big for buffer")); + rlen = readPacket(pbuff, (maxsize - (pbuff-buffer) - 1), timeout); + } else { + rlen = readPacket(pbuff, value, timeout); + } //DEBUG_PRINT(F("Remaining packet:\t")); DEBUG_PRINTBUFFER(pbuff, rlen); return ((pbuff - buffer)+rlen); @@ -322,7 +327,7 @@ bool Adafruit_MQTT::publish(const char *topic, uint8_t *data, uint8_t bLen, uint // If QOS level is high enough verify the response packet. if (qos > 0) { - len = readFullPacket(buffer, PUBLISH_TIMEOUT_MS); + len = readFullPacket(buffer, MAXBUFFERSIZE, PUBLISH_TIMEOUT_MS); DEBUG_PRINT(F("Publish QOS1+ reply:\t")); DEBUG_PRINTBUFFER(buffer, len); if (len != 4) @@ -403,7 +408,7 @@ bool Adafruit_MQTT::unsubscribe(Adafruit_MQTT_Subscribe *sub) { if(subscriptions[i]->qos > 0 && MQTT_PROTOCOL_LEVEL > 3) { // wait for UNSUBACK - len = readFullPacket(buffer, CONNECT_TIMEOUT_MS); + len = readFullPacket(buffer, MAXBUFFERSIZE, CONNECT_TIMEOUT_MS); DEBUG_PRINT(F("UNSUBACK:\t")); DEBUG_PRINTBUFFER(buffer, len); @@ -427,7 +432,7 @@ Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) { uint8_t i, topiclen, datalen; // Check if data is available to read. - uint16_t len = readFullPacket(buffer, timeout); // return one full packet + uint16_t len = readFullPacket(buffer, MAXBUFFERSIZE, timeout); // return one full packet if (!len) return NULL; // No data available, just quit. DEBUG_PRINT("Packet len: "); DEBUG_PRINTLN(len); diff --git a/Adafruit_MQTT.h b/Adafruit_MQTT.h index bd320b7..6df4b01 100644 --- a/Adafruit_MQTT.h +++ b/Adafruit_MQTT.h @@ -78,7 +78,7 @@ // Largest full packet we're able to send. // Need to be able to store at least ~90 chars for a connect packet with full // 23 char client ID. -#define MAXBUFFERSIZE (125) +#define MAXBUFFERSIZE (150) #define MQTT_CONN_USERNAMEFLAG 0x80 #define MQTT_CONN_PASSWORDFLAG 0x40 @@ -99,7 +99,7 @@ //and returns an int typedef void (*SubscribeCallbackType)(char *); -extern void printBuffer(uint8_t *buffer, uint8_t len); +extern void printBuffer(uint8_t *buffer, uint16_t len); class Adafruit_MQTT_Subscribe; // forward decl @@ -201,10 +201,10 @@ class Adafruit_MQTT { // Read MQTT packet from the server. Will read up to maxlen bytes and store // the data in the provided buffer. Waits up to the specified timeout (in // milliseconds) for data to be available. - virtual uint16_t readPacket(uint8_t *buffer, uint8_t maxlen, int16_t timeout) = 0; + virtual uint16_t readPacket(uint8_t *buffer, uint16_t maxlen, int16_t timeout) = 0; // Read a full packet, keeping note of the correct length - uint16_t readFullPacket(uint8_t *buffer, uint16_t timeout); + uint16_t readFullPacket(uint8_t *buffer, uint16_t maxsize, uint16_t timeout); // Properly process packets until you get to one you want uint16_t processPacketsUntil(uint8_t *buffer, uint8_t waitforpackettype, uint16_t timeout); diff --git a/Adafruit_MQTT_CC3000.h b/Adafruit_MQTT_CC3000.h index ec6bf37..daa3502 100644 --- a/Adafruit_MQTT_CC3000.h +++ b/Adafruit_MQTT_CC3000.h @@ -100,7 +100,7 @@ class Adafruit_MQTT_CC3000 : public Adafruit_MQTT { return mqttclient.connected(); } - uint16_t readPacket(uint8_t *buffer, uint8_t maxlen, int16_t timeout) { + uint16_t readPacket(uint8_t *buffer, uint16_t maxlen, int16_t timeout) { /* Read data until either the connection is closed, or the idle timeout is reached. */ uint16_t len = 0; int16_t t = timeout; diff --git a/Adafruit_MQTT_Client.cpp b/Adafruit_MQTT_Client.cpp index 81f9652..1487856 100644 --- a/Adafruit_MQTT_Client.cpp +++ b/Adafruit_MQTT_Client.cpp @@ -47,7 +47,7 @@ bool Adafruit_MQTT_Client::connected() { return client->connected(); } -uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint8_t maxlen, +uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen, int16_t timeout) { /* Read data until either the connection is closed, or the idle timeout is reached. */ uint16_t len = 0; diff --git a/Adafruit_MQTT_Client.h b/Adafruit_MQTT_Client.h index db1216a..bb99e3f 100644 --- a/Adafruit_MQTT_Client.h +++ b/Adafruit_MQTT_Client.h @@ -50,7 +50,7 @@ class Adafruit_MQTT_Client : public Adafruit_MQTT { bool connectServer(); bool disconnectServer(); bool connected(); - uint16_t readPacket(uint8_t *buffer, uint8_t maxlen, int16_t timeout); + uint16_t readPacket(uint8_t *buffer, uint16_t maxlen, int16_t timeout); bool sendPacket(uint8_t *buffer, uint8_t len); private: diff --git a/Adafruit_MQTT_FONA.h b/Adafruit_MQTT_FONA.h index 920c217..b8e3ba2 100644 --- a/Adafruit_MQTT_FONA.h +++ b/Adafruit_MQTT_FONA.h @@ -68,7 +68,7 @@ class Adafruit_MQTT_FONA : public Adafruit_MQTT { return fona->TCPconnected(); } - uint16_t readPacket(uint8_t *buffer, uint8_t maxlen, int16_t timeout) { + uint16_t readPacket(uint8_t *buffer, uint16_t maxlen, int16_t timeout) { uint8_t *buffp = buffer; DEBUG_PRINTLN(F("Reading data.."));