Better documentation for mqtt:lwt() (#2128)

This commit is contained in:
dbaumgarten 2017-10-06 00:31:41 +02:00 committed by Marcel Stör
parent 3e60fa8f60
commit ec6ed6f868
1 changed files with 9 additions and 0 deletions

View File

@ -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. 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 #### Syntax
`mqtt:lwt(topic, message[, qos[, retain]])` `mqtt:lwt(topic, message[, qos[, retain]])`