diff --git a/docs/en/modules/mqtt.md b/docs/en/modules/mqtt.md index f445f8e7..feb402f3 100644 --- a/docs/en/modules/mqtt.md +++ b/docs/en/modules/mqtt.md @@ -151,6 +151,15 @@ This is the description of how the `autoreconnect` functionality may (or may not Setup [Last Will and Testament](http://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament) (optional). A broker will publish a message with qos = 0, retain = 0, data = "offline" to topic "/lwt" if client does not send keepalive packet. +As the last will is sent to the broker when connecting, `lwt()` must be called BEFORE calling `connect()`.   + +The broker will publish a client's last will message once he NOTICES that the connection to the client is broken. The broker will notice this when: +  - The client fails to send a keepalive packet for as long as specified in `mqtt.Client()` +  - The tcp-connection is properly closed (without closing the mqtt-connection before) + - The broker tries to send data to the client and fails to do so, because the tcp-connection is not longer open. + +This means if you specified 120 as keepalive timer, just turn off the client device and the broker does not send any data to the client, the last will message will be published 120s after turning off the device. + #### Syntax `mqtt:lwt(topic, message[, qos[, retain]])`