User Manual

mqtt.connect(BROKER_HOST, BROKER_PORT);
}
Serial.println("OK");
Serial.print("Subscribing to " TOPIC_SUBSCRIBE " ... ");
mqtt.subscribe(TOPIC_SUBSCRIBE, MQTT_QOS_AT_MOST_ONCE, subscribed_callback); // Will halted if an error occurs
Serial.println("OK");
}
/**************************************************************************/
/*!
@brief This loop function runs over and over again
*/
/**************************************************************************/
void loop()
{
}
/**************************************************************************/
/*!
@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.print("[Subscribed] ");
Serial.print(topic);
Serial.print(" : ") ;
Serial.println(message);
// Echo back
Serial.print("Echo back to " TOPIC_ECHO " ... ");
mqtt.publish(TOPIC_ECHO, message); // Will halt if an error occurs
Serial.println("OK");
// Unsubscribe from SUBSCRIBED_TOPIC2 if we received an "stop" message
// Won't be able to echo anymore
if ( message == "stop" )
{
Serial.print("Unsubscribing from " TOPIC_SUBSCRIBE " ... ");
mqtt.unsubscribe(TOPIC_SUBSCRIBE); // Will halt if fails
Serial.println("OK");
}
}
/**************************************************************************/
/*!
@brief Connect to defined Access Point
*/
/**************************************************************************/
© Adafruit Industries https://learn.adafruit.com/introducing-the-adafruit-wiced-feather-wifi Page 136 of 202