ESP32 MQTT Last Will Message Not Published
DodaTech
Updated 2026-06-26
1 min read
In this tutorial, you'll learn about ESP32 MQTT Last Will Message Not Published. We cover key concepts, practical examples, and best practices.
The Problem
ESP32 MQTT Last Will and Testament (LWT) message is not published when the device disconnects unexpectedly.
Quick Fix
Wrong
client.connect("esp32"); // No Last Will configured
Device disconnects unexpectedly. No offline notification received.
Right
client.setWill("esp32/status", "offline", true, 1);
if (client.connect("esp32")) {
client.publish("esp32/status", "online", true);
}
Device connects: esp32/status = online
Device loses power: esp32/status = offline (auto-published by broker)
Prevention
Always call setWill() before connect(). Use retained messages (true) for status topics. Use QoS 1 for the will message. Publish online message immediately after connecting. Test by force-disconnecting the device.
DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro