You've already forked Adafruit_MQTT_Library
mirror of
https://github.com/adafruit/Adafruit_MQTT_Library.git
synced 2025-06-14 21:02:25 +03:00
smarter packet reading makes for faster publish-handling! also, retries subscriptions 3 times
This commit is contained in:
@ -48,8 +48,7 @@ bool Adafruit_MQTT_Client::connected() {
|
||||
}
|
||||
|
||||
uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint8_t maxlen,
|
||||
int16_t timeout,
|
||||
bool checkForValidPubPacket) {
|
||||
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;
|
||||
@ -64,20 +63,10 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint8_t maxlen,
|
||||
//DEBUG_PRINTLN((uint8_t)c, HEX);
|
||||
len++;
|
||||
if (len == maxlen) { // we read all we want, bail
|
||||
DEBUG_PRINT(F("Read packet:\t"));
|
||||
DEBUG_PRINT(F("Read data:\t"));
|
||||
DEBUG_PRINTBUFFER(buffer, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
// special case where we just one one publication packet at a time
|
||||
if (checkForValidPubPacket) {
|
||||
if ((buffer[0] == (MQTT_CTRL_PUBLISH << 4)) && (buffer[1] == len-2)) {
|
||||
// oooh a valid publish packet!
|
||||
DEBUG_PRINT(F("Read PUBLISH packet:\t"));
|
||||
DEBUG_PRINTBUFFER(buffer, len);
|
||||
return len;
|
||||
}
|
||||
}
|
||||
}
|
||||
timeout -= MQTT_CLIENT_READINTERVAL_MS;
|
||||
delay(MQTT_CLIENT_READINTERVAL_MS);
|
||||
|
Reference in New Issue
Block a user