---
title: MQTT Client
slug: bhdo-v2/mqtt-client
createdAt: 2023-03-27T20:37:48.000Z
---

You can set up an MQTT Client through DeviceHub.&#x20;

:::hint{type="info"}
**Note**: You can't connect the MQTT Client to the DeviceHub [MQTT Server](docId\:e1UMu4nrD4nuNWmTaFt8f) if they are using the same Belden Horizon Data Operations instance. This includes connecting through the Flows Manager or through an Integration connector. If they are using different Belden Horizon Data Operations instances, they can connect. &#x20;
:::

# Step 1: Add MQTT Client to DeviceHub

**To add the MQTT Client to DeviceHub:**

1. In Belden Horizon Data Operations, navigate to **DeviceHub**.&#x20;
2. Click the **Connect a Device** box.&#x20;
   The *Connect Device* dialog box appears.

   ::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/AURS-dG_viPnhWXyAyeMG_connect-a-devicebhdo.png" size="80" width="1316" height="527" caption="Connect a device icon" position="center" showCaption="true"}
3. For *Driver Type*, select **MQTT**. Then, for *Driver Name*, select **MQTT Client**.&#x20;
4. Enter a name for the client. Optionally, add a description.&#x20;
5. For **Broker Address**, enter the broker IP address or host name.&#x20;
6. For **Port**, enter the port of the broker.&#x20;

Configure the client with the following options.&#x20;

## Client Authentication

Select one of the following client authentication methods:

- Anonymous
- Certificate (only for SSL mode)
- Username/Password
- Username/Password & Certificate

Update the default username and password values as needed.&#x20;

## Security Mode

If you enable security mode, upload or paste the certificate in the **Certificate Authority** field.&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/k9A3yU_Fi1Mg8g9CN8H3g_image.png" size="80" width="1155" height="761" position="center" showCaption="false"}

## Will Enabled (Last Will and Testament)

If you enable a last will and testament, (LWT) configure the following.

- **Will Topic**: Enter the topic for the last will and testament.&#x20;
- **Will Payload**: Enter the payload in string format.&#x20;
- **Will Qos**: Select one of the following message delivery options.
  - 0 - At most once (fire and forget)
  - 1 - At least once (acknowledged delivery)
  - 2 - Exactly once (assured delivery)
- **Will Retained**: Select Enable or Disable.&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/6yO0HBIzPmXx0Ipd6bY2__image.png" size="80" width="1161" height="769" position="center" showCaption="false"}

## Advanced

If you show these options, configure the following as needed.&#x20;

- **Client ID**: Enter the MQTT Client ID. The default client ID is the DeviceHub device name.&#x20;
- **Persistent Session**: Select Enable or Disable.&#x20;
- **Certificate Verification**: Select Enable or Disable.&#x20;
- **Protocol Version**: Select the MQTT protocol version: v3 (3.1), v4 (3.1.1), v5 (5.0).&#x20;
- **Keep Alive Period**: Configure the keep-alive period in seconds.&#x20;
- **Write Timeout**: Configure the write timeout in seconds.&#x20;
- **Connect Timeout**: Configure the connect timeout in seconds.&#x20;

::Image[]{src="https://api.archbee.com/api/optimize/SSUUxKZUk9bFTEPNn_6Zo/Rk9akmHgG2VTYZWLvMyD5_image.png" size="80" width="1152" height="761" position="center" showCaption="false"}

## Additional Options

See the [Define Optional Parameters](docId\:f8KfMKcZ3LqC-Pp0XisNe) section to learn more about additional options.&#x20;

When done configuring the device, click **Add Device**.&#x20;

# Step 2: Add Tags

When you [Add Tags](docId\:PYRa8tUvdoIeJm1luBm-O) to the connected device refer to the following tag parameters.

## Tag Parameters

- **Name**: Enter the case-sensitive topic name in the server without any wildcard symbols. The name must be unique for the driver. &#x20;
- **Value Type**: Select string.&#x20;
- **Tag Name**: Enter a name for the tag.
- **Description** (Optional): Enter a description for the tag. &#x20;
- **Qos**: Select a Quality of Service.&#x20;
  - 0 - At most once (fire and forget)
  - 1 - At least once (acknowledged delivery)
  - 2 - Exactly once (assured delivery)
- **Retain**: Select a message policy.&#x20;
  - Don't Retain
  - Retain last Publish
- **Tag Formula**: Enter a formula for the tag to process the generated data. Two variables are permitted: `value` (current tag value) and `timestamp` (current tag UNIX time in milliseconds). The following math functions are available:
  - sin
  - cos
  - sqrt
  - tan
  - power
  - log
  - exp
- **Only Publish on Change of Value**: Select the checkbox to customize NATS messages to be published only when the *value&#x20;*&#x70;arameter changes from a previous value to a new one. *Change of Value* only applies to boolean, numeric (such as int or float), and simple string data types. It does not apply to complex types, such as JSON or array. Poll-once topics will not be affected by *Change of Value* settings. These topics will still only see a single message.
- **Meta Data**: Metadata summarizes basic information about data. This feature allows you to define key-value pair data for the device output payload later on. It can then be used to find, use, and reuse particular instances of data.&#x20;

