1
0
mirror of https://github.com/adafruit/Adafruit_MQTT_Library.git synced 2025-06-16 08:20:55 +03:00

adds ping to the end of the main loop in examples

This commit is contained in:
Todd Treece
2015-10-22 14:13:19 -04:00
parent 7c2b558ee9
commit 4dc6f1e486
5 changed files with 55 additions and 57 deletions

View File

@ -90,14 +90,6 @@ void loop() {
// function definition further below.
MQTT_connect();
// Try to ping the MQTT server
/*
if (! mqtt.ping(3) ) {
// MQTT pings failed, lets reconnect
Serial.println("Ping fail!");
}
*/
// this is our 'wait for incoming subscription packets' busy subloop
Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt.readSubscription(1000))) {
@ -117,7 +109,13 @@ void loop() {
Serial.println(F("OK!"));
}
// ping the server to keep the mqtt connection alive
if(! mqtt.ping()) {
mqtt.disconnect();
}
delay(1000);
}
// Function to connect and reconnect as necessary to the MQTT server.