MQTT Last Will and Testament (LWT)
The MQTT last will and testament is a message that a client registers with the broker when connecting, which the broker publishes on the client's behalf if the client disconnects ungracefully, so other systems learn it has gone offline.
When connecting, a client can specify a will topic, payload, QoS level and retain flag. If the client later disconnects cleanly by sending a DISCONNECT packet, the broker discards the will. If the connection is lost instead, for example through a network failure, a missed keep-alive or a protocol error, the broker publishes the will message to subscribers of the will topic. MQTT 5 adds a will delay interval, allowing a brief reconnection before the will is sent.
In IIoT systems, the last will provides presence and health monitoring for gateways, edge devices and applications. A common pattern publishes a retained online status when a device connects and sets a will that changes the same topic to offline, so dashboards and SCADA systems always show current connectivity. Sparkplug B builds on this mechanism for its death certificates, which mark data from a failed edge node as stale.
Detection speed depends on the keep-alive interval, since the broker treats a client as disconnected only after one and a half keep-alive periods without communication, so the interval should balance responsiveness against network traffic. Will messages report lost connectivity, not the condition of the machine itself, and consumers should treat data from an offline source as stale rather than current.
Key points
- Will topic, payload, QoS and retain flag are set at connection
- Published by the broker only after an ungraceful disconnect
- Commonly paired with a retained online and offline status topic
- Sparkplug B uses it for edge node death certificates
- Detection time depends on the keep-alive interval
Where AiVibe comes in
AiAmbA IoT is AiVibe's edge protocol layer: it discovers devices and normalises industrial signals, with supported protocols including Siemens S7, Mitsubishi MC, Delta Modbus, OPC UA and MQTT, and driver availability confirmed per installation. Writes to machines are deny-by-default.