Inspecting LWT (WILL) configurations and status for your MyQTT HUB


#1

1. Introduction

The following article explains how to use “Will inspector” feature to check that are the will configuration of your connected devices and if they did configure a will so you can better track and resolve problems associated with LWT not triggered.

2. How MQTT LWT works (MQTT Last Will Testament)

MQTT standard includes a feature that allows configuring a message, with a topic, qos and retain indication that will be sent to your MQTT HUB in case device connection is lost suddently.

As indicated at 3.1.2.5 Will Flag, will message will be sent under the following similar conditions:

  • An I/O error or network failure detected by the Server.
  • The Client fails to communicate within the Keep Alive time.
  • The Client closes the Network Connection without first sending a DISCONNECT Packet.
  • The Server closes the Network Connection because of a protocol error.

3. Requirements

To have your LWT message triggered and receive it, you need:

  1. A device correctly configuring it
  2. You need that device to lose its connection suddently without closing cleanly.
  3. Some other device must be subscribed to that will topic in other to receive it.

That is, if your device does not configure will, or it does not lose connection without closing cleanly or no device is subscribed to that topic, then, you will not receive these messages.

4. Inspecting current LWT (Will) configured by your devices

How will is configured depends on your MQTT client software. Please, check its documentation to know how to do it. Later on we give you some examples.

  1. Assuming you have devices connected, you can inspect what are their current will configuration by going to your domain hub devices tab:

  2. Then, you will see current devices connected that have a will configured (LWT):

5. What if I do not see will expected there

Most common causes are:

  1. Your device is not connected and hence, it cannot have will configuration
  2. It is connected but not sending will

6. How to configure will with mosquitto_sub to test my environment

Use the following mosquitto_sub to debug and test case your MQTT HUB.

  1. First, connect with a device that configures a will message (LWT):

    >>  mosquitto_sub -h 192.168.0.176 -i user_ID -u user_Usr -P '<pass>' -t message/topic/to/subscribe -q 2 -d --will-topic 'user/device/died' --will-retain --will-qos 2 --will-payload 'Device stopped without clean disconnect'
    

    Update this command to configure user_ID, user_Usr, password and rest of settings.

  2. Now use will inspecto to check that your device did configure will message.

  3. Now Control+C or kill mosquitto_sub process to trigger will notification.

  4. Now, you can check on “Last Msg” tab to see triggered message:

  5. And, any device subscribed to that topic will receive a copy of that message too.


Last will- Not published by broker
Last Will not working on my side
MyQttHub EN -- Start here
MyQttHub and SparkPlug Spec