User Manual

Feather.printNetwork();
// Tell the MQTT client to auto print error codes and halt on errors
mqtt.err_actions(true, true);
// Set ClientID if defined
#ifdef CLIENTID
mqtt.clientID(CLIENTID);
#endif
// Last will must be set before connecting since it is part of the connection data
mqtt.will(TOPIC, WILL_MESSAGE, MQTT_QOS_AT_LEAST_ONCE);
// Connect to broker
Serial.printf("Connecting to " BROKER_HOST " port %d ... ", BROKER_PORT);
if (USE_TLS)
{
// Disable default RootCA to save SRAM since we don't need to
// access any other site except test.mosquitto.org
Feather.useDefaultRootCA(false);
// mosquitto CA is pre-generated using pycert.py
Feather.addRootCA(rootca_certs, ROOTCA_CERTS_LEN);
// Connect with SSL/TLS
mqtt.connectSSL(BROKER_HOST, BROKER_PORT);
}else
{
mqtt.connect(BROKER_HOST, BROKER_PORT);
}
Serial.println("OK");
// Subscribe with callback
mqttTopic.subscribe(subscribed_callback);
Serial.println("Please use desktop client to subcribe to \'" TOPIC "\' to monitor");
// Inital publish
Serial.printf("Publishing \'%d\' ... ", value);
mqttTopic.print( value ); // use .write to send in binary format
Serial.println("OK");
}
/**************************************************************************/
/*!
@brief This loop function runs over and over again
*/
/**************************************************************************/
void loop()
{
// value changed due to subscribed callback
if (old_value != value)
{
// check if still subscribed
if ( mqttTopic.subscribed() )
{
old_value = value;
Serial.println();
Serial.printf("Publishing \'%c\' ... \r\n", value);
mqttTopic.print( value ); // use .write to send in binary format
}
© Adafruit Industries https://learn.adafruit.com/introducing-the-adafruit-wiced-feather-wifi Page 127 of 202