Skip to content

MQTT Client Will Message Not Sent

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about MQTT Client Will Message Not Sent. We cover key concepts, practical examples, and best practices.

The Problem

The Last Will and Testament (LWT) message does not send when the client disconnects.

Quick Fix

Wrong

// No will configured in connection options
No notification when client goes offline.
const mqtt = require('mqtt')

const options = {
  host: 'broker:1883',
  clientId: 'sensor-01',
  will: {
    topic: 'clients/sensor-01/status',
    payload: 'offline',
    qos: 1,
    retain: true
  }
}

const client = mqtt.connect(options)

client.on('connect', () => {
  // Publish online status on connect
  client.publish('clients/sensor-01/status', 'online', { retain: true })
  console.log('Connected with will message configured')
})
"offline" appears on clients/sensor-01/status when client disconnects.

Prevention

Will message is configured in CONNECT packet (not after). It publishes when the broker detects abnormal disconnection. Will QoS and retain should match your use case. The will topic is typically device-specific. Use dedicated topics: clients/{clientid}/status.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

FAQ

### What triggers the will message?

Abnormal disconnection: network failure, keep-alive timeout, broker crash. Normal disconnection (DISCONNECT packet) does NOT trigger will.

Can I update the will after connecting?

No. MQTT 3.1.1 does not support will updates. MQTT 5.0 has a Will Delay Interval property that allows setting a delayed will.

What is the difference between will and retained?

Will is sent automatically on abnormal disconnect. Retained messages are set manually by the publisher and persist until overwritten.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro