User Manual
bool unsubscribe (void)
Unsubscribes to the topic if you previously called .subscribe.
Parameters: None
Returns: 'True' (1) if the operation succeeded, otherwise 'false' (0).
bool subscribed (void)
Indicates whether you are currently susbcripted to this topic or not.
Parameters: None
Returns: 'True' (1) if you are subscribed, otherwise 'false' (0).
Publishing Data via 'Print'
One important thing to keep in mind with AdafruitMQTTTopic is that every .print* function corresponds to an MQTT
publication request.
The following code will result in three different MQTT publications:
/**************************************************************************/
/*!
@brief MQTT subscribe event callback handler
@param topic The topic causing this callback to fire
@param message The new value associated with 'topic'
@note 'topic' and 'message' are UTF8Strings (byte array), which means
they are not null-terminated like C-style strings. You can
access its data and len using .data & .len, although there is
also a Serial.print override to handle UTF8String data types.
*/
/**************************************************************************/
void subscribed_callback(UTF8String topic, UTF8String message)
{
// Print out topic name and message
Serial.printf("["); Serial.print(topic); Serial.printf("]");
Serial.print(" : message = ") ;
Serial.println(message);
// Unsubscribe if message = "stop"
if ( message == "stop" )
{
Serial.print("Unsubscribing ... ");
mqttTopic.unsubscribe(); // Will halt if fails
Serial.println("OK");
}
}
© Adafruit Industries https://learn.adafruit.com/introducing-the-adafruit-wiced-feather-wifi Page 124 of 202










