How-To Guides
Integration Guides

Generic MQTT Integration Guide (Last Will and Testament)

5min

Review the following guide for setting up an integration between Manufacturing Connect Edge and an MQTT broker using Last Will and Testament.

Overview of MQTT 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

Step 1: Add Generic MQTT Connector

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.

Step 2: Enable the Connector

After adding the connector, click the toggle in the connector tile to enable it.

Document image


If you see a Failed status, you can review the Connector Logs and relevant error messages.

Step 3: Verify Connection in Flows Manager

You can verify the connection is successfully set up by creating a flow in Manufacturing Connect Edge.

To create a flow:

  1. In Manufacturing Connect Edge, navigate to Flows Manager.
  2. Click Add Flow.
  3. Enter MQTT LWT in the Name field and click Create Flow.
  4. Click the Start icon next to the MQTT LWT flow.
  5. Click the Go To Flow Definition icon. The Flow canvas opens in a new browser tab.
  6. From the node palette, drag the MQTT In node (network section) to the canvas.

    MQTT In node
    MQTT In node
    
  7. Double-click the MQTT In node. The Edit MQTT In Node dialog box appears.
  8. Click the Edit icon next to the Server field. The Add new mqtt-broker config node dialog box appears.

    Edit server icon
    Edit server icon
    
  9. In the Name field, enter the name of the broker.
  10. 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.
  11. Click Add.
  12. From the Edit MQTT In Node dialog box, enter lwtTopicName in the Topic field.
  13. Select the desired QoS value.
  14. Click Done.
  15. From the Node palette, drag the Debug Node to the canvas and connect the two nodes.
  16. Click Deploy.
  17. Expand the message window beneath the flow and click the Debug icon. Verify that messages are displaying.

    Debug node messages
    Debug node messages