Skip to content
Protocols

Last Will and Testament

A message a client registers with an MQTT broker when connecting, which the broker publishes on the client's behalf if the connection drops unexpectedly.

When an MQTT client connects it can specify a will topic, payload, QoS and retain flag. If the client later disconnects cleanly, nothing happens. If the broker loses the connection without a disconnect packet, the broker publishes the will message as if the device had sent it. MQTT 5 adds a will delay so brief reconnects do not trigger it.

The common pattern pairs a retained online status published at connect with a retained offline will on the same status topic, giving every subscriber an accurate presence indicator without polling or a separate heartbeat service. The mechanism depends on the broker’s keep-alive timer noticing the silence, so the time to detect a failure is bounded by the keep-alive interval the client chose, a value that trades detection speed against bandwidth. See MQTT explained.

Part of the IoT Glossary. Spotted an error or a missing term? Tell us.