back compatible ping()

This commit is contained in:
ladyada 2015-10-21 00:15:27 -04:00
parent 286245ab62
commit 632c2f2cfe
2 changed files with 14 additions and 13 deletions

View File

@ -325,20 +325,21 @@ Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) {
return subscriptions[i];
}
bool Adafruit_MQTT::ping() {
// Construct and send ping packet.
uint8_t len = pingPacket(buffer);
if (!sendPacket(buffer, len))
return false;
// Process ping reply.
len = readPacket(buffer, 2, PING_TIMEOUT_MS);
if (buffer[0] == (MQTT_CTRL_PINGRESP << 4))
return true;
bool Adafruit_MQTT::ping(uint8_t num = 1) {
while (num--) {
// Construct and send ping packet.
uint8_t len = pingPacket(buffer);
if (!sendPacket(buffer, len))
return false;
// Process ping reply.
len = readPacket(buffer, 2, PING_TIMEOUT_MS);
if (buffer[0] == (MQTT_CTRL_PINGRESP << 4))
return true;
}
return false;
}
// Packet Generation Functions /////////////////////////////////////////////////

View File

@ -169,7 +169,7 @@ class Adafruit_MQTT {
Adafruit_MQTT_Subscribe *readSubscription(int16_t timeout=0);
// Ping the server to ensure the connection is still alive.
bool ping();
bool ping(uint8_t n);
protected:
// Interface that subclasses need to implement: