Generic MQTT Integration Guide (Last Will and Testament)
Review the following guide for setting up an integration between Manufacturing Connect Edge and an MQTT broker using Last Will and Testament.
When this type of integration is set up, it includes a notification to other clients that are connected to the MQTT broker when your connection as a client disconnects.
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
Follow the steps to Add a Connector and select the MQTT - Generic provider.
Configure the following parameters.
- Name: A recognizable name to identify the connector.
- Hostname: Enter the server address.
- Port: Confirm that the default value 1883 is entered.
- Client ID: Enter the client ID.
- Username (Optional)
- Password (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. Select one of the following:
- 0: The message is sent once and delivery isn’t guaranteed.
- 1: This method guarantees that the message will be delivered to the broker, but also doesn’t prevent it being received multiple times.
- 2: This method guarantees that the message will be delivered to the broker, and the message will be sent exactly once.
- 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.
- Integration Topic: Enter testTopic.
- LWT topic: Enter lwtTopicName.
- LWT payload: Enter Some LWT Payload.
- LWT payload type: The payload type for MQTT's Last Will and Testament feature. The options are string and base64.
- 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.
- Throttling limit: The maximum number of messages per second to be processed. The default value is zero, which means that there is no limit.
- Persistent storage: When enabled, this will cause messages to undergo a store-and-forward procedure. Messages will be stored within Manufacturing Connect Edge when cloud providers are online.
- Queue Mode: Select the queue mode as lifo (last in first out) or fifo (first in first out). Selecting lifo means that the last data entry is processed first, and selecting fifo means the first data entry is processed first.
After adding the connector, click the toggle in the connector tile to enable it.
If you see a Failed status, you can review the Connector Logs and relevant error messages.
You can verify the connection is successfully set up by creating a flow in Manufacturing Connect Edge.
To create a flow:
- In Manufacturing Connect Edge, navigate to Flows Manager.
- Click Add Flow.
- Enter MQTT LWT in the Name field and click Create Flow.
- Click the Start icon next to the MQTT LWT flow.
- Click the Go To Flow Definition icon. The Flow canvas opens in a new browser tab.
From the node palette, drag the MQTT In node (network section) to the canvas.
- Double-click the MQTT In node. The Edit MQTT In Node dialog box appears.
Click the Edit icon next to the Server field. The Add new mqtt-broker config node dialog box appears.
- In the Name field, enter the name of the broker.
- From the Connection tab, configure the following parameters.
- Server: Enter the server address.
- Port: Enter 1883.
- Client ID: Enter the client ID.
- Keep Alive: Enter 60.
- Click Add.
- From the Edit MQTT In Node dialog box, enter lwtTopicName in the Topic field.
- Select the desired QoS value.
- Click Done.
- From the Node palette, drag the Debug Node to the canvas and connect the two nodes.
- Click Deploy.
Expand the message window beneath the flow and click the Debug icon. Verify that messages are displaying.