User Manual
and this message will be sent if the server/broker is unable to contact the client for a specific amount of time.
This functionality isn't a mandatory part of MQTT, but can be used to detect when nodes are online and offline. When
you connect, you can for example set a string like "Online" to a specific topic, and then set a last will message of
"Offline" to that same topic. If the node goes offline (battery failure, disconnect, etc.), the broker will use the last will to
set the topic to "Offline" once the server/client timeout occurs.
void will ( const char* topic, UTF8String message, uint8_t qos =
MQTT_QOS_AT_MOST_ONCE, uint8_t retained = 0);
Sets the last will message.
Parameters:
topic: The topic where the data should be published (ex: "adafruit/data" or "home/rooms/bedroom/temp").
message: The string of data to write to the specified 'topic' (UTF8String is used to make it easier to work with
UTF8 data).
qos: The quality of service level (see the MQTT spec for details). Default = 'At Most Once', meaning the message
tries to send once but isn't persisted if the send fails. Possible values are:
MQTT_QOS_AT_MOST_ONCE
MQTT_QOS_AT_LEAST_ONCE
MQTT_QOS_EXACTLY_ONCE
retained: Whether or not the published message should be 'retained' by the MQTT broker. Sending a message
with the retained bool set to 'false' (0) will clear any previously retained message from the broker. The default
value is false.
Returns: 'True' (1) is the last will message was successfully set, otherwise 'false' (0).
Client ID
The client identifier (Client ID) is an string that identifies each MQTT client connecting to an MQTT broker.
This value should be unique on the broker since the broker uses it for identifying the client and the client's current
'state' of the client (subscriptions, QoS, etc.).
By default, a random 10-23 character string will be generated for the unique Client ID that gets passed to the broker
during the connection process. If you wish to maintain a consistent client ID across connections, however, you can
override the random client ID by using the .clientID function below:
void clientID(const char* client)
Sets a manual Client ID, overriding the default random value.
Parameters:
client: A null-terminated string representing the client ID to pass to the MQTT broker.
Returns: Nothing
Be sure to set the last will BEFORE calling the .connect function since the last will is set during the connect
phase!
© Adafruit Industries https://learn.adafruit.com/introducing-the-adafruit-wiced-feather-wifi Page 116 of 202










