remove broken while loop from ping()

This commit is contained in:
Todd Treece 2015-10-05 10:38:09 -04:00
parent 0fbd734646
commit 765a2feaff
2 changed files with 14 additions and 14 deletions

View File

@ -297,19 +297,20 @@ Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) {
return subscriptions[i]; return subscriptions[i];
} }
bool Adafruit_MQTT::ping(uint8_t times) { bool Adafruit_MQTT::ping() {
while (times) {
// Construct and send ping packet. // Construct and send ping packet.
uint8_t len = pingPacket(buffer); uint8_t len = pingPacket(buffer);
if (!sendPacket(buffer, len)) if (!sendPacket(buffer, len))
return false; 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; return false;
} }
// Packet Generation Functions ///////////////////////////////////////////////// // Packet Generation Functions /////////////////////////////////////////////////

View File

@ -163,9 +163,8 @@ class Adafruit_MQTT {
// that subscribe should be called first for each topic that receives messages! // that subscribe should be called first for each topic that receives messages!
Adafruit_MQTT_Subscribe *readSubscription(int16_t timeout=0); Adafruit_MQTT_Subscribe *readSubscription(int16_t timeout=0);
// Ping the server to ensure the connection is still alive. Returns true if // Ping the server to ensure the connection is still alive.
// successful, otherwise false. bool ping();
bool ping(uint8_t t);
protected: protected:
// Interface that subclasses need to implement: // Interface that subclasses need to implement: