Device Disconnected but Still “Online”? The Five Stages Behind False MQTT StatusA field device has clearly lost power, yet the green dot on the monitoring dashboard stays lit. By the time the offline alarm finally fires, twenty minutes may have passed—long past the point of useful response. After digging through logs, the root cause is usually one thing: the “online” status shown in the backend is never the device’s real-time state. It is a delayed judgment result. Break that judgment apart and the problem becomes clear. From Power Loss to “Turning Red”: Five Stages in BetweenA device goes through five stages before its backend status flips to offline. Any stage that stalls slows the whole detection:
So the green dot reflects the value written at the last stage, not the live connection state. Troubleshooting must follow this chain. Abrupt Power Loss: No Chance to Say GoodbyeSudden power loss, a pulled cable, or an instant Wi-Fi drop means no TCP FIN or RST can be sent. The broker-side socket still holds the connection, completely unaware the other end is gone—this is a half-open connection. Doesn’t TCP have its own keepalive? Two hard limitations make it unreliable: it’s off by default, and even when enabled, Linux probes only every 7,200 seconds by default. That’s why MQTT puts keepalive at the application layer: the client must send at least one PINGREQ within the keepalive period, and the broker replies with PINGRESP. Both fixed headers are just 2 bytes—negligible overhead. But low-power devices often stretch heartbeats to save energy. In NB-IoT scenarios, intervals of ten minutes or even half an hour are common—and a device may simply “sleep to death” and stop sending heartbeats entirely. The 1.5x Window: How Long a Device Can “Play Dead”When heartbeats stop, the broker doesn’t declare death immediately. MQTT 3.1.1 specifies: with a non-zero keepalive, the broker waits 1.5 times the keepalive period without receiving any packet before treating the connection as failed. That 1.5 factor is headroom for network jitter. The “playing dead” window follows:
Key takeaway: the alarm threshold must exceed 1.5x the keepalive period. Setting it within 1.5x causes false alarms. Different brokers apply their own grace factors, and actual waits often run slightly longer than 1.5x—so set the threshold to 2x the keepalive period. keepalive=0: Disabling Detection, Not “No Heartbeat Needed”Per the MQTT spec, a keepalive value of 0 means timeout detection is disabled—the broker won’t disconnect an inactive client, so the will message never fires. Some MQTT libraries default to 0, or an initialization omits the parameter, silently setting keepalive to 0 while the config page claims 60 seconds. The most direct way to confirm the effective value is packet capture. Watch for one trap: a PINGREQ is only the two bytes A Will Message Nobody Receives Is WastedThe broker dutifully publishes the will, but if nobody subscribes or the topic doesn’t match, status never updates. The consumer side must complete receive → parse → flip status → write snapshot. Wildcard subscription across all devices is preferable to per-device subscription. Two more pitfalls: graceful shutdowns must update status themselves (a normal DISCONNECT does not trigger the will), and duplicate ClientIDs count as anomalies (reconnecting the same ClientID elsewhere makes the broker kick the old connection and trigger the will). When device status flaps, check for duplicate ClientIDs first. With MQTT 5.0, note that Will Delay Interval makes total latency “1.5x keepalive + will delay,” and reason code 0x04 allows a graceful disconnect to also publish the will. Movingcomm’s Engineering View: Making Online Status Computable, Tunable, TraceableIn industrial IoT platforms and device connectivity, Movingcomm focuses not merely on “is the device connected,” but on whether the online-detection chain is observable: is the keepalive period taking effect as intended, is the will message correctly consumed, and how many seconds separate the status snapshot from the real connection. With centralized monitoring from the cloud management platform, operators can first confirm whether heartbeats are being sent, then verify whether the alarm threshold is reasonable, and finally check whether the will-consumption chain is intact—rather than digging through logs twenty minutes after the alarm fires. Turning “false online” from folklore into a computable, shorten-able delay is what industrial device connectivity actually needs.
|