In MQTT, the Last Will and Testament (LWT) feature is used to:
Think about what happens if a device suddenly loses connection without warning.
LWT allows the broker to send a predefined message to other clients if a client disconnects unexpectedly, signaling an abnormal disconnection.
Consider this MQTT client connection command with LWT settings:
mosquitto_pub -h broker.example.com -t 'status/device1' -m 'offline' --will-topic 'status/device1' --will-message 'offline' --will-qos 1 --will-retain
What happens if the client disconnects unexpectedly?
Check the --will-* options for QoS and retain flags.
The --will-topic, --will-message, --will-qos, and --will-retain options define the LWT message that the broker publishes if the client disconnects unexpectedly.
Given the following broker configuration options, which snippet correctly sets up LWT to publish a retained message when a client disconnects unexpectedly?
Check the exact option names and retain flag value.
The correct broker config uses 'will_topic', 'will_message', 'will_qos', and 'will_retain' with retain set to true to ensure the LWT message is retained.
A client sets an LWT message, but when it disconnects unexpectedly, subscribers do not receive the LWT message. What is the most likely cause?
Consider how clean session affects session state and LWT delivery.
If a client connects with clean session true, the broker does not store session information, and LWT messages may not be delivered as expected on disconnect.
Arrange the following steps in the correct order to implement Last Will and Testament (LWT) in an MQTT client connection.
Think about configuration before connection, then broker behavior.
The client must first define LWT settings, then connect with those settings. The broker stores the LWT info and publishes it if the client disconnects unexpectedly.