User Manual
Disconnect Callback
An optional disconnect callback is available in AdafruitMQTT. This callback handler will fire when you are
disconnected from the remote MQTT broker.
To use the callback, add the following function to your sketch (the function name and the contents of the function can
change depending on your project requirements):
Then pass this function name into the .setDisconnectCallback function BEFORE calling .connect or .connectSSL:
AdafruitMQTT Example
The following example illustrates how to subscribe to topics, set the last will message, publish, and implement one or
more subscribe callback handlers:
void disconnect_callback(void)
{
Serial.println();
Serial.println("-----------------------------");
Serial.println("DISCONNECTED FROM MQTT BROKER");
Serial.println("-----------------------------");
Serial.println();
}
// Set the disconnect callback handler
mqtt.setDisconnectCallback(disconnect_callback);
This example uses the freely accessible test MQTT broker at test.mosquitto.org. This server is publicly
accessible, so be careful what data you push to it since anyone can see the publications!
/*********************************************************************
This is an example for our Feather WIFI modules
Pick one up today in the adafruit shop!
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
MIT license, check LICENSE for more information
All text above, and the splash screen below must be included in
any redistribution
*********************************************************************/
#include <adafruit_feather.h>
#include <adafruit_mqtt.h>
#include "certificate_mosquitto.h"
/* This sketch demonstrates subscribe/unsubscribe activity with
* callbacks.
*
* It will connect to a public MQTT server (with/without TLS)
* and subscribe to TOPIC_SUBSCRIBE (defined below).
© Adafruit Industries https://learn.adafruit.com/introducing-the-adafruit-wiced-feather-wifi Page 117 of 202










