MQTT Last Will Says Offline Too Late? Understand Detection Timing
- PLC Play Ground
- 0
- Posted on
A Last Will message is not an instantaneous physical failure detector. Its timing depends on connection failure detection and configured protocol behavior. Define the maximum acceptable observation delay before relying on it for operational status.
MQTT status example; timing is configuration- and version-dependent.
What is happening?
A broker publishes the configured will under specified disconnect conditions. Keep-alive behavior and, in MQTT 5, will-delay and session settings can affect timing. Graceful disconnects and network partitions require separate test cases.
Check these five things
-
Record protocol version, keep-alive, will, and session settings.
-
Define what offline means to the consuming application.
-
Measure detection during controlled connection failures.
-
Test graceful disconnect and broker restart separately.
-
Combine status with data-age checks where needed.
Worked example
A teaching dashboard shows online until the broker determines that an unresponsive client connection has failed. The sensor may have stopped producing useful data earlier. A measurement-age indicator can reveal that gap without pretending the will is a real-time safety signal.
Quick diagnostic reference
| Event | Test separately |
|---|---|
| Graceful exit | Application status update |
| Lost connection | Broker detection |
| Frozen publisher logic | Data freshness |
The mistake to avoid
Do not use a general MQTT availability message as a machine safety function. Its communication semantics do not provide that assurance.
How to verify the fix
Record observed detection and recovery times under the approved network scenarios. Confirm the UI explains stale, disconnected, and unknown states consistently.
Field-work boundary: These are educational diagnostic guides. Use the exact equipment manuals and approved site procedures. Electrical testing and machinery changes belong to qualified, authorized personnel; control hazardous energy and validate affected functions before release.
Technical reference
HiveMQ: MQTT Essentials. The examples and diagnostic tables above are original teaching material; they do not replace the product manual.
