MQTT Will Message (Last Will and Testament) Demo

This demonstrates MQTT v5.0 Will Messages using an in-tab broker with MessagePort connections.

How it works:
  1. Observer subscribes to status/+ to receive will messages
  2. Device connects with a will message and 5-second keep-alive
  3. Click "Force Disconnect" to close the connection without DISCONNECT
  4. Wait ~8 seconds for keep-alive timeout, then the broker publishes the will message

Note: The broker detects disconnection via keep-alive timeout (1.5x keep-alive period).

Observer Client

Status: Disconnected

Received Messages:

Waiting for messages...

Device Client (with Will Message)

Status: Disconnected
Will Message Configuration:
  • Topic: status/device-1
  • Payload: {"status": "offline", "reason": "unexpected_disconnect"}
  • QoS: 1 (At Least Once)
  • Retain: false
  • Keep-alive: 5 seconds (timeout at ~8s)