---
title: Generic MQTT-TCP Last Will and Testament Configuration
slug: bhdo/generic-mqtt-tcp-last-will-and-testament-configuration
createdAt: 2022-11-24T18:28:04.000Z
---

You can use the MQTT Generic connector to send messages to the MQTT broker, which includes a notification to other clients that are connected to the broker when this client disconnects.&#x20;

When a client connects to the MQTT broker, it creates a connect packet that is predefined and sent to the MQTT broker.

You can define the message to notify you if the client disconnects.

There are four properties that you can set for the Last Will and Testament.

- LWT Topic: This is the topic that is used by the MQTT broker to send if the client disconnects.
- LWT Payload: This is the payload message that is sent if the client disconnects.
- QoS: This is the quality of service level (0, 1, or 2).
- Retain: This indicates if the message should be retained (true or false).

The MQTT broker sends this message in the following scenarios:

- If the client fails to communicate within the defined *Keep Alive* period
- If the client does not send a disconnect packet before it closes the network connection
- The broker closes the network connection due to a protocol error by the client

This example uses MQTT Integration and Flows.

# Step 1: Add Generic MQTT Connector

Follow the steps to [Add a Connector](https://public-docs.litmus.io/bhdo/add-a-connector) and select the **MQTT - Generic&#x20;**&#x70;rovider.&#x20;

Configure the following parameters.

- **Name**: A recognizable name to identify the connector.&#x20;
- **Hostname**: Enter the server address.&#x20;
- **Port**: Confirm that the default value **1883** is entered.&#x20;
- **Client ID**: Enter the client ID.
- **Username&#x20;**(Optional)
- **Password&#x20;**(Optional)
- **QoS**: The Quality of Service (QoS) level is an agreement between the sender of a message and the receiver of a message that defines the guarantee of delivery for a specific message.
- **Parallel Publish Count**: The number of messages being published simultaneously. Once the defined limit has been reached, subsequent messages are silently dropped. The default value is 100.&#x20;
- **Integration Topic**: Enter **testTopic**.&#x20;
- **LWT topic**: Enter **lwtTopicName**.&#x20;
- **LWT payload**: Enter **Some LWT Payload**.&#x20;
- **LWT payload type**: The payload type for MQTT's Last Will and Testament feature. The options are *string&#x20;*&#x61;nd *base64*.&#x20;
- **LWT QoS**: The Quality of Service value for MQTT's Last Will and Testament feature.
- **LWT retained**: Select this check box to retain the value for MQTT's Last Will and Testament feature.&#x20;
- **Throttling limit**: The maximum number of messages per second to be processed. The default value is zero, which means that there is no limit.&#x20;
- **Persistent storage**: When enabled, this will cause messages to undergo a store-and-forward procedure. Messages will be stored within Belden Horizon Data Operations when cloud providers are online. &#x20;

# Step 2: Verify Connection in Flows Manager

You can verify the connection is successfully set up by creating a flow in Belden Horizon Data Operations.&#x20;

**To create a flow:**

1. In Belden Horizon Data Operations, navigate to **Flows Manager**.&#x20;
2. Click **Add Flow**.
3. Enter **MQTT LWT&#xA0;**&#x69;n the **Name&#xA0;**&#x66;ield and click **Create Flow**.
4. Click the **Start&#x20;**&#x69;con next to the MQTT LWT flow.

   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/TUtjgpAzfgRGwuWG9p2Je_start-flows-manager.png" size="80" width="1095" height="427" position="center" showCaption="false"}
5. Click the **Go To Flow Definition** icon.&#x20;
   The Flow canvas opens in a new browser tab.&#x20;

   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/mwY6OVLiiKmmHiKba4nHJ_go-to-flow-definition.png" size="80" width="1118" height="447" caption="Go To Flow Definition icon" position="center" showCaption="true"}
6. From the node palette, drag the **MQTT In** node (network section) to the canvas.&#x20;

   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/7f0HoqgLntPC_1APyE5Yr_mqttinnode.png" size="80" width="1121" height="637" caption="MQTT In node" position="center" showCaption="true"}
7. Double-click the **MQTT In** node.
   The *Edit MQTT In Node* dialog box appears.&#x20;
8. Click the **Edit&#x20;**&#x69;con next to the *Server&#x20;*&#x66;ield.&#x20;
   The *Add new mqtt-broker config node* dialog box appears.&#x20;

   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/h_f4IwachNpeLbdv60Q_q_editservericon.png" size="60" width="505" height="462" caption="Edit server icon" position="center" showCaption="true"}
9. In the *Name&#x20;*&#x66;ield, enter the name of the broker.&#x20;
10. From the Connection tab, configure the following parameters.&#x20;
    - **Server**: Enter the server address.&#x20;
    - **Port**: Enter **1883**.&#x20;
    - **Client ID**: Enter the client ID.&#x20;
    - **Keep Alive**: Enter **60**.&#x20;
11. Click **Add**.&#x20;
12. From the *Edit MQTT In Node* dialog box, enter **lwtTopicName&#x20;**&#x69;n the **Topic&#x20;**&#x66;ield.&#x20;
13. Click **Done**.
14. From the *Node&#x20;*&#x70;alette, drag the **Debug&#xA0;**&#x4E;ode to the canvas and connect the two nodes.
15. Drag the **Sidebar&#xA0;**&#x62;eneath the flow up and click the **Debug&#xA0;**&#x69;con. Verify that messages are displaying.&#x20;

    ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/gPJk6NsW3loIyEUdOJWuM_debugicon.png" size="80" width="885" height="365" caption="Debug node messages" position="center" showCaption="true"}

