User Manual

AdafruitMQTTTopic
AdafruitMQTT includes an OPTIONAL helper class called AdafruitMQTTTopic that can be used to publish data to a
single topic on an MQTT broker.
This helper class inherits from Print (https://adafru.it/lFk), which allows you to write data to MQTT topics similarly to how
you would write data to the 'Serial Monitor', using .print statements.
Constructor
Parameters:
mqtt: A reference to the AdafruitMQTT instance associated with this helper (since the connection to the MQTT
broker is defined and managed there).
topic: A null-terminated string containing the topic to publish to
qos: An optional quality of server (QoS) level to use when publishing. If left empty, this argument will default to
'At Most Once', meaning it will try to publish the data but if the operation fails it won't persist the attempt and retry
again later.
retain: Sets the 'retain' bit to indicate if any messages published to the MQTT broker should be retained on the
broker for the next client(s) that access that topic.
The following example shows how to properly declare an instance of the AdafruitMQTTTopic class (note that the
default QoS and retain values are used):
Functions
In addition to the functions defined in the Print base class (https://adafru.it/lFk) (see the Print.h
source (https://adafru.it/lFl) as well), the following functions are defined as part of AdafruitMQTTTopic:
void retain (bool on)
Enables or disabled the 'retain' feature when publishing messages. This indicates whether the published message
should be maintained on the broker when a message is written to the topic.
See 'MQTT/MqttTopicClass' in the examples folder for an example of how to use AdafruitMQTTTopic.
AdafruitMQTTTopic(AdafruitMQTT& mqtt,
const char* topic,
uint8_t qos = MQTT_QOS_AT_MOST_ONCE,
bool retain = false)
#define CLIENTID "Adafruit Feather"
#define TOPIC "adafruit/feather"
AdafruitMQTT mqtt (CLIENTID);
AdafruitMQTTTopic publisher (mqtt, TOPIC);
void retain(bool on)
© Adafruit Industries https://learn.adafruit.com/introducing-the-adafruit-wiced-feather-wifi Page 122 of 202