diff --git a/Adafruit_MQTT.cpp b/Adafruit_MQTT.cpp index 6d5a45a..7f4f587 100644 --- a/Adafruit_MQTT.cpp +++ b/Adafruit_MQTT.cpp @@ -297,19 +297,20 @@ Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) { return subscriptions[i]; } -bool Adafruit_MQTT::ping(uint8_t times) { - while (times) { - // Construct and send ping packet. - uint8_t len = pingPacket(buffer); - if (!sendPacket(buffer, len)) - return false; +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; - // Process ping reply. - len = readPacket(buffer, 2, PING_TIMEOUT_MS); - if (buffer[0] == (MQTT_CTRL_PINGRESP << 4)) - return true; - } return false; + } // Packet Generation Functions ///////////////////////////////////////////////// diff --git a/Adafruit_MQTT.h b/Adafruit_MQTT.h index ad5653d..5a9965d 100644 --- a/Adafruit_MQTT.h +++ b/Adafruit_MQTT.h @@ -163,9 +163,8 @@ class Adafruit_MQTT { // that subscribe should be called first for each topic that receives messages! Adafruit_MQTT_Subscribe *readSubscription(int16_t timeout=0); - // Ping the server to ensure the connection is still alive. Returns true if - // successful, otherwise false. - bool ping(uint8_t t); + // Ping the server to ensure the connection is still alive. + bool ping(); protected: // Interface that subclasses need to implement: