1
0
mirror of https://github.com/adafruit/Adafruit_MQTT_Library.git synced 2025-07-27 15:01:49 +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

@ -104,16 +104,6 @@ void loop() {
// connection and automatically reconnect when disconnected). See the MQTT_connect
// function definition further below.
MQTT_connect();
// Try to ping the MQTT server
/*
if (! mqtt.ping(3) ) {
// MQTT pings failed, let's reconnect by forcing a watchdog reset.
Serial.println("Ping fail! Resetting...");
Watchdog.enable(8000);
delay(10000);
}
*/
// this is our 'wait for incoming subscription packets' busy subloop
Adafruit_MQTT_Subscribe *subscription;
@ -133,6 +123,12 @@ void loop() {
} else {
Serial.println(F("OK!"));
}
// ping the server to keep the mqtt connection alive
if(! mqtt.ping()) {
Serial.println(F("MQTT Ping failed."));
}
}
// Function to connect and reconnect as necessary to the MQTT server.