Fixes issue with client erroneously reading a byte from 0 length packets
This commit is contained in:
parent
0b8488d9bf
commit
44199a17ee
@ -229,9 +229,21 @@ uint16_t Adafruit_MQTT::processPacketsUntil(uint8_t *buffer, uint8_t waitforpack
|
|||||||
if (packetType == waitforpackettype) {
|
if (packetType == waitforpackettype) {
|
||||||
return len;
|
return len;
|
||||||
} else {
|
} else {
|
||||||
|
// Serial.print("Packet Types: ");
|
||||||
|
// Serial.print(packetType);
|
||||||
|
// Serial.print(" ");
|
||||||
|
// Serial.println(waitforpackettype);
|
||||||
if (packetType == MQTT_CTRL_PUBLISH) {
|
if (packetType == MQTT_CTRL_PUBLISH) {
|
||||||
handleSubscriptionPacket(len);
|
handleSubscriptionPacket(len);
|
||||||
} else {
|
} else {
|
||||||
|
Serial.print("Packet dropped: ");
|
||||||
|
Serial.print(len);
|
||||||
|
Serial.print(" ");
|
||||||
|
for (int i = 0; i < MAXBUFFERSIZE; i++) {
|
||||||
|
Serial.print(this->buffer[i]);
|
||||||
|
Serial.print(" ");
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
ERROR_PRINTLN(F("Dropped a packet"));
|
ERROR_PRINTLN(F("Dropped a packet"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,7 +259,9 @@ uint16_t Adafruit_MQTT::readFullPacket(uint8_t *buffer, uint16_t maxsize, uint16
|
|||||||
|
|
||||||
// read the packet type:
|
// read the packet type:
|
||||||
rlen = readPacket(pbuff, 1, timeout);
|
rlen = readPacket(pbuff, 1, timeout);
|
||||||
if (rlen != 1) return 0;
|
if (rlen != 1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG_PRINT(F("Packet Type:\t"));
|
DEBUG_PRINT(F("Packet Type:\t"));
|
||||||
DEBUG_PRINTBUFFER(pbuff, rlen);
|
DEBUG_PRINTBUFFER(pbuff, rlen);
|
||||||
@ -259,7 +273,9 @@ uint16_t Adafruit_MQTT::readFullPacket(uint8_t *buffer, uint16_t maxsize, uint16
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
rlen = readPacket(pbuff, 1, timeout);
|
rlen = readPacket(pbuff, 1, timeout);
|
||||||
if (rlen != 1) return 0;
|
if (rlen != 1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
encodedByte = pbuff[0]; // save the last read val
|
encodedByte = pbuff[0]; // save the last read val
|
||||||
pbuff++; // get ready for reading the next byte
|
pbuff++; // get ready for reading the next byte
|
||||||
uint32_t intermediate = encodedByte & 0x7F;
|
uint32_t intermediate = encodedByte & 0x7F;
|
||||||
|
@ -53,6 +53,9 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen,
|
|||||||
uint16_t len = 0;
|
uint16_t len = 0;
|
||||||
int16_t t = timeout;
|
int16_t t = timeout;
|
||||||
|
|
||||||
|
if (maxlen == 0) { // handle zero-length packets
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
while (client->connected() && (timeout >= 0)) {
|
while (client->connected() && (timeout >= 0)) {
|
||||||
//DEBUG_PRINT('.');
|
//DEBUG_PRINT('.');
|
||||||
@ -64,10 +67,6 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen,
|
|||||||
//DEBUG_PRINTLN((uint8_t)c, HEX);
|
//DEBUG_PRINTLN((uint8_t)c, HEX);
|
||||||
len++;
|
len++;
|
||||||
|
|
||||||
if (maxlen == 0) { // handle zero-length packets
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (len == maxlen) { // we read all we want, bail
|
if (len == maxlen) { // we read all we want, bail
|
||||||
DEBUG_PRINT(F("Read data:\t"));
|
DEBUG_PRINT(F("Read data:\t"));
|
||||||
DEBUG_PRINTBUFFER(buffer, len);
|
DEBUG_PRINTBUFFER(buffer, len);
|
||||||
|
Loading…
Reference in New Issue
Block a user