bg

Connecting an OPC Client to an MQTT Broker In Real-Time

This tutorial will teach you how to link an OPC client with the use of an MQTT broker using our Datatag Link utility. This link will allow you to send data in both directions (bi-directional data transfer is configurable) in real-time.

Why Connect an OPC Client to an MQTT Broker?

In various industrial and IoT scenarios, it can be essential to connect an OPC client to an MQTT broker. Here are some key reasons:

  • Real-time data sharing: allow real-time data sharing between industrial systems (OPC) and IoT platforms (MQTT).
  • Centralized monitoring: Centralized aggregation and facilitation of data from many OPC servers into a single MQTT broker for monitoring.
  • Cloud integrations: Platform-cloud systems: publish OPC data to connect integrated cloud-based systems.
  • Scalability: The lightweight protocol of MQTT makes it even better for scaling data transmission across the broadest possible number of networks.
  • Interoperability: Union-of-legacy-industrial-systems-modern-iot-protocols.

By connecting an OPC client to an MQTT broker, you can access data faster, make the system work better together, and perform advanced analysis and automation.

Connecting an OPC Client to an MQTT Broker In Real-Time

Get Started with Datatag Link Setup

How it works

In this tutorial, Datatag Link acts as a bridge between an OPC client and an MQTT broker, enabling real-time data exchange. Here's how it works:

  1. OPC communication: By connecting to the OPC server, Datatag Link retrieves value data from the provided OPC tag.
  2. MQTT communication: The application sends the value of the OPC tag to the appropriate MQTT topic at the broker.
  3. Tag linking: A tag link enables Datatag Link to automatically publish any changes in the OPC tag value to the MQTT broker or the other way around.
  4. Real-time logging: All data transactions can be tracked in real-time, thus providing an opportunity to see the communication and troubleshoot problems that could arise.

Step-by-Step Tutorial: Interconnect OPC Client And MQTT Using Datatag Link

Step 1: Install and launch Datatag Link

  1. Download and install: If you haven't already, download Datatag Link from our website. When you install the program, choose "OPC Client" or "OPC Server" on the left side, and "MQTT" on the right side.
  2. Launch the program: After installation, start Datatag Link. The main window will open, displaying the Tag List, Toolbar with buttons for the most used functions, and Status Panel.

Datatag Link Main Window With Connected OPC And MQTT Items

Step 2: Configure the OPC client connection

1. Add a new connection:

  • Click the Add button on the toolbar.
  • Click Add under the Server section to configure the OPC client.
  • Server name/IP: Enter the OPC server's name. To access OPC servers located in remote locations, simply enter the name or IP address of the computer, such as "localhost" for a local server, and then select "Find."

OPC Client Connection Settings

2. Set OPC tag parameters:

  • Tag name: Specify the OPC tag you want to link (e.g., 'node1.node2.tag1').
  • Data type: Set the data type of the OPC tag (e.g., Integer, Float, or Auto for automatic detection).
  • Process valid values only: Enable this option to ensure only valid OPC values are transmitted.
  • Force read values: Enable this if you want the program to poll the OPC tag value periodically (e.g., every 5000 ms).

OPC-MQTT Link Settings

Step 3: Configure the MQTT broker

1. Add a new connection:
  • Click Add under the Broker section to configure the MQTT broker.
  • Broker name: Enter a descriptive name for the broker (e.g., "MQTT Broker 1").
  • IP address and port: Enter the IP address and port of the MQTT broker (e.g., '192.168.1.100:1883').
  • Click the OK button to save the MQTT broker settings.

MQTT Broker Connection Settings

2. Set MQTT topic parameters:

  • Tag name: Specify the MQTT topic path (e.g., 'sensors/temperature').
  • Data type: Since MQTT uses a text format, ensure the data format matches the OPC tag's data type.
  • Retain flag: Enable this if you want the broker to retain the last received value.
  • QoS level: Set the Quality of Service level (e.g., 1 for at least once delivery).
  • Transmission direction: Set to Bidirectional if you want two-way communication, or One-Way if data should flow only from OPC to MQTT.
  • Click the OK button to save the link settings for both sides.
  • The new connection will appear in the Tag List.

Step 5: Save and test the configuration

1. Save the configuration:

  • Go to File → Save to save the current configuration. Furthermore, it is possible to save your modifications by clicking the "Save" button located on the toolbar within the main window.
  • When you start the program next time, all these settings will be loaded automatically.
2. Test the connection:
  • Verify the connection: In the Status Panel, check for the symbols "<" or ">" to confirm data transmission between the OPC client and MQTT broker.
  • Monitor the Status Panel for any errors or warnings.
  • Use the Transactions File option under the View Menu to check the data exchange logs.
  • Use 3rd party tools to check data on both side. For example UA Expert for OPC UA data, and MQTT explorer for MQTT data.

For more detailed instructions, refer to the full Datatag Link Manual.

Explore Advanced Features

FAQ

Q1: Can I connect multiple OPC tags to multiple MQTT topics?

A: Yes, In Datatag Link, you can connect up to 65000 tags. You can link one tag to multiple MQTT topics on several brokers to use this data in different applications.

Q2: What if my OPC tag and MQTT topic use different data formats?

A: Datatag Link automatically handles data format conversion between OPC and MQTT. You can also manually specify the data type for each tag to ensure compatibility. Also, the program can encode data to JSON when the program publishes data to MQTT.

Q3: How do I troubleshoot connection issues with the OPC server or MQTT broker?

A: If you encounter connection issues, check the following:

  • Check the File → Message Log protocol file for any error messages.
  • Double-check the OPC server Id, tag name, and MQTT broker IP address.
  • Ensure that the OPC server and MQTT broker are running and accessible. If the program cannot access any server, it logs a message to a protocol file.
  • Use the Test Connection feature to confirm that Datatag Link can communicate with both the OPC server and MQTT broker.

Connecting Two OPC Servers: From OPC DA Server to OPC UA Server.
OPC Tag Grouping From Different OPC DA Servers To OPC UA.
Connecting an OPC Client/Server to an SQL Database Using Datatag Link.
Connecting an OPC Client to an MQTT Broker In Real-Time.
Linking Tags In Two MODBUS Slave Devices In Real-Time.
How to Connect a MODBUS Slave Device to an SQL Database.
Log OPC DA, UA, HDA, AE data to SQL or Excel.
Data Logger Suite - log data from various data sources (OPC, MQTT, MODBUS, SNMP, etc.).