You've already forked Adafruit_MQTT_Library
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:
@ -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.
|
||||
|
Reference in New Issue
Block a user