How-To Guides
Integration Guides

Generic MQTT Integration Guide (Mosquitto)

6min

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

Mosquitto is a lightweight open source message broker that Implements MQTT versions 3.1.0, 3.1.1, and version 5.0.

Before You Begin

  • You must download the Mosquitto message broker. See the Mosquitto Download page to learn more.
  • Configure Mosquitto so that anonymous users are allowed to access it.

To verify that Mosquitto is running in Windows, open up a command prompt and enter netstat -an. If Mosquitto is successfully running, you should be able to see your IP address and port 1883.

Document image


If you don't see port 1883 being used:

  • Open Task Manager > Services and start/restart the Mosquitto server from there.
  • Make sure the mosquitto.conf file is correctly configured so that Mosquitto can run on your system.

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: Mosquitto is running locally on your PC, so enter your IP address.
  • Port: Confirm that the default value 1883 is entered.
  • Client ID: Enter 1.
  • Username: Leave this field blank.
  • Password: Leave this field blank.
  • QoS: Make sure the default value 1 is entered.
  • Parallel Publish Count: Confirm the default value 100 is entered. 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 mos_topic_1.
  • LWT topic: The topic for MQTT's Last Will and Testament feature. You can leave this value blank.
  • LWT payload: The payload for MQTT's Last Will and Testament feature. You can leave this value blank.
  • 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. The default value is 1.
  • 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: Add Outbound/Inbound Topic to Connector

To add the outbound and inbound topics to the MQTT connector:

  1. Navigate to Integration.
  2. Click the MQTT - Generic connector tile.
  3. Click the Topics tab.
  4. Click the Add a new subscription icon. The Data Integration dialog box appears.

    Add new subscription icon
    Add new subscription icon
    
  5. Configure the following parameters.
    • Data Direction: Select Local to Remote - Outbound.
    • Local Data Topic: Enter a local data topic.
    • Remote Data Topic: Confirm the topic where the data is pushed. This is the Integration Topic value for the connector.
    • Enable: Select the toggle to enable the topic.
  6. Click OK to add the topic.
  7. Click the Add a new subscription icon again to add the inbound topic.
  8. Configure the following parameters.
    • Data Direction: Select Remote to Local - Inbound.
    • Local Data Topic: Enter integration.raw.Mos_topic_1.
    • Remote Data Topic: Confirm the topic where the data is pushed. This is the Integration Topic value for the connector.
    • Enable: Select the toggle to enable the topic.
  9. Click OK to add the topic.

Step 3: 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 4: Create Flow to Verify Connection

To create the flow:

  1. In Manufacturing Connect Edge, navigate to Flows Manager.
  2. Click the Go To Flow Definition icon for a selected Flows Manager. The Flow canvas opens in a new browser tab.

    Go To Flow Definition icon
    Go To Flow Definition icon
    
  3. From the node palette, drag the DataHub Subscribe node (DataConnector section), Inject node (Common section), and Debug node (Common section) to the canvas.

    The DataHub Subscribe, Inject, and Debug nodes
    The DataHub Subscribe, Inject, and Debug nodes
    
  4. Connect the DataHub Subscribe and Inject nodes to the Debug node.

    Document image
    
  5. Double click the DataHub Subscribe node. The Edit DataHub Subscribe Node dialog box appears.
  6. In the Topic field, enter integration.raw.Mos_topic_in.
  7. If needed, configure the DataHub Subscribe connection. See Configure Connector Nodes to learn more.
  8. Click Done.
  9. Double-click the Inject node. The Edit Inject Node dialog box appears.
  10. In the msg.payload field, select string.
  11. In the msg.topic field, enter integration.raw.Mos_topic_1.
  12. Enter test in the Name field, and then click Done.
  13. Click Deploy to save the flow.
  14. Open the command prompt window and go to the directory that stores Mosquitto files.
  15. Enter mosquitto_pub.exe -t mos_topic_1 -m "Hello from Mosquitto", and then press ENTER.

    Command prompt window
    Command prompt window
    
  16. In the browser window that has the Manufacturing Connect Edge flow canvas, expand the message window beneath the flow to view debug messages and click the Debug icon. Verify that Hello from mosquitto displays.

    Successful message in Flow canvas
    Successful message in Flow canvas