OPC UA PubSub and MQTT with the OPC Data Client Development Toolkit (2024)

8 min read

Aug 8, 2024 2:00:00 PM

If you've been keeping up with our Summer of IoT blog series, you've likely noticed our in-depth exploration of Software Toolbox solutions and the use of MQTT for IoT applications. In this latest installment of the series, our spotlight shifts to the OPC Data Client development toolkit. When speaking about IoT, OPC UA is a major player, which is why our focus for this post will be to delve into the integration of OPC UA PubSub (publish/subscribe) and how it leverages MQTT as its conduit for message transmission.

OPC Data Client is a rapid development toolkit for quickly adding OPC client connectivity to custom applications including OPC UA and OPC Classic (DA, AE and XML-DA). The OPC Data Client has been extensively tested for OPC interoperability, with various OPC Servers from many vendors, and on different computer environments. This also includes regular participation at the OPC Foundation's OPC Interoperability Workshops where the toolkit’s reference implementation has passed their independent lab testing process.

OPC UA PubSub and MQTT with the OPC Data Client Development Toolkit (1)

In the realm of message transmission, efficiency is key. Designed specifically for gathering data from numerous devices and seamlessly transporting it to IT infrastructure, MQTT excels in scenarios demanding lightweight protocols particularly in remote monitoring setups where minimizing code footprint and conserving network bandwidth are paramount. Employing a publish/subscribe mechanism, MQTT optimizes payload delivery and minimizes overhead, accommodating application-specific JSON or binary formats with ease. Standardization of the payload format is not defined by MQTT standards. This is where OPC UA excels, because it provides standardized formats, especially when used with OPC UA companion specifications, the subject of a recent post. Recognized and embraced by IT departments globally, MQTT stands as a trusted and versatile solution for data exchange. This post will delve into the intricacies of MQTT UADP, MQTT JSON for optimizing OPC UA PubSub messaging with MQTT, shedding light on best practices for enhancing communication efficiency and reliability between MQTT clients and brokers in the context of Data Client.

Examples of OPC UA PubSub utilizing MQTT

Given OPC Data Client's capability for custom applications, this blog explores sample code for MQTT JSON and MQTT UADP using TCP, serving as a foundation for your projects.

The OPC UA standard offers a publish-subscribe (Pub/Sub) model where clients can either send (publish) or receive (subscribe) data. A broker is needed to manage data exchange between Publishers and Subscribers.

For systems with multiple data senders and receivers, OPC UA Pub/Sub is more efficient than direct connections. It supports UDP and MQTT, offering flexibility with standardized methods for data organization and packaging, solving interoperability issues common in other Pub/Sub solutions.

In a system with numerous machine sensors, OPC UA Pub/Sub allows sensors to publish data to a broker. Client applications can then receive this data without 1-to-1 connections. Sensors can also receive feedback from clients, enhancing application responsiveness and efficiency.

OPC UA PubSub and MQTT with the OPC Data Client Development Toolkit (2)

Understanding JSON and UADP

What is JSON?

JSON (JavaScript Object Notation) is a lightweight data interchange format that is easy for humans to read and write and easy for machines to parse and generate. It uses a text format that is completely language-independent but uses conventions that are familiar to programmers of the C family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

What is UADP?

UADP (Universal Architecture Data Protocol) is a protocol used in the OPC UA (Open Platform Communications Unified Architecture) framework for industrial automation. UADP is designed to support efficient data transmission by encoding messages in a binary format, which allows for fast and reliable communication between devices and systems in industrial settings. It facilitates interoperability and scalability in complex industrial environments.

When should I use JSON or UADP?

JSON and UADP cater to different needs and use cases. JSON, or JavaScript Object Notation, offers users the flexibility to create payloads structured exactly as they need. This freedom allows for customized data interchange, which can be particularly useful in web applications and scenarios where human readability and ease of debugging are crucial. However, this customization means that receivers must understand the specific format to retrieve data successfully, which can add complexity and require additional effort to maintain.

In contrast, UADP (Universal Architecture Data Protocol) provides a predefined structure within the OPC UA framework. This structured approach means that any OPC UA Pub/Sub compliant solution already expects the data in a specific format, saving time and reducing the investment needed to create and maintain customized payloads. UADP's binary encoding facilitates secure, efficient and reliable communication, particularly suited for industrial automation environments where performance, scalability, and interoperability are critical. However, users are confined to the predefined structure, which may limit flexibility compared to JSON. Developers must consider their application, corporate and industry specific best practice security requirements, and operating environment needs to make the best choice for their applications.

MQTT JSON Mapping using TCP

Now that we have a clear understanding of JSON and the UADP protocol and considerations of when to utilize each, let’s walk through an OPC Data Client provided example that shows how to subscribe to dataset messages on an OPC-UA PubSub connection using JSON via TCP. This is useful for applications that need to handle real-time data from industrial devices or other OPC-UA compliant sources. It is important to note that while we are only exploring the JSON example, the process will be identical with a few minor changes if you wish to use UADP mapping instead. To follow along with this code for your own implementation, please find these examples in our Online User Guide:

Before diving into the code, you must ensure that the OpcLabs.MqttNet package is referenced in your project. This package is essential for the MQTT transport to work.

Breakdown of Sample Code:

  1. Namespaces and Class Definition:

    OPC UA PubSub and MQTT with the OPC Data Client Development Toolkit (3)
    Namespaces: The code uses several namespaces for threading, OPC-UA PubSub functionalities, and operation models.

    Class Definition: The SubscribeDataSet class contains the main method MqttJsonTcp for subscribing to dataset messages.

  2. PubSub Connection Descriptor for JSON:

    OPC UA PubSub and MQTT with the OPC Data Client Development Toolkit (4)
    Connection Descriptor: Defines the PubSub connection using MQTT over TCP.

    Transport Protocol Mapping: Specifies the transport protocol mapping as MQTT JSON or MQTT UADP. This step is often optional due to automatic message mapping recognition.

  3. Subscription Arguments:

    OPC UA PubSub and MQTT with the OPC Data Client Development Toolkit (5)
    Subscription Arguments: Defines the arguments for subscribing to the dataset, including the MQTT topic name.
  4. Subscriber Object and Event Handling:

    OPC UA PubSub and MQTT with the OPC Data Client Development Toolkit (6)
    Subscriber Object: Instantiates the subscriber object.

    Event Handling: Hooks the DataSetMessage event to the subscriber_DataSetMessage_MqttJsonTcp method for handling incoming dataset messages.

  5. Subscribing and Unsubscribing:

    OPC UA PubSub and MQTT with the OPC Data Client Development Toolkit (7)
    Subscribing: Subscribes to the dataset messages.

    Processing: For this particular example, dataset message events are processed for 20 seconds. This can be modified and adjusted based on your needs/preferences.

    Unsubscribing: Unsubscribes from all dataset messages and waits for one second to ensure all messages are processed. This can be modified and adjusted as well.

  6. Event Handler Method:

    OPC UA PubSub and MQTT with the OPC Data Client Development Toolkit (8)

    Event Handling Logic: Displays the dataset if the message is successfully received. If there is an error, it prints the error message.

  7. Example Output:

    OPC UA PubSub and MQTT with the OPC Data Client Development Toolkit (9)
    This example illustrates a basic, yet powerful, way to handle real-time data from OPC-UA compliant devices using MQTT JSON or UADP mapping over TCP. By subscribing to dataset messages, you can efficiently monitor and process industrial data streams. Be sure to update the connection descriptors and subscription arguments in the example to match your specific use case and environment.

Conclusion

In this article, we've witnessed the powerful combination of OPC Data Client and MQTT and how it optimizes PubSub messaging in IoT applications. We’ve also learned that the OPC Data Client can facilitate your OPC connectivity needs and provide a reliable solution that is sure to work with whatever OPC Server you use, thanks to extensive interoperability testing MQTT continues to grow in popularity and its implementation within the industrial automation community.

Through this exploration, we've highlighted using MQTT JSON and MQTT UADP to enhance communication efficiency and reliability in OPC UA PubSub messaging. As you continue to innovate and build IoT solutions, integrating these technologies can improve data exchange and system performance, ensuring your applications are both effective and efficient.

Don't forget to subscribe to our blog for the latest updates, how-to videos, and other resources for OPC Data Client and our other solutions. As always, please feel free to contact our technical team Monday-Friday, 8AM to 5PM US Eastern Time.

Ready to get started with custom OPC client development and expand your IoT integration even further? Download OPC Data Client today!

OPC UA PubSub and MQTT with the OPC Data Client Development Toolkit (10)

Topics:OPC Data ClientSummer of IoT

OPC UA PubSub and MQTT with the OPC Data Client Development Toolkit (11)

Written by Kyle Persyn
Previous Post
Cogent DataHub V11 Feature Enhancements: User Experience
OPC UA PubSub and MQTT with the OPC Data Client Development Toolkit (2024)
Top Articles
Dallas police killed their teenage brothers. 50 years later, the siblings want answers
John Nightingale - Info zur Person mit Bilder, News & Links
Woodward Avenue (M-1) - Automotive Heritage Trail - National Scenic Byway Foundation
Is Paige Vanzant Related To Ronnie Van Zant
Pnct Terminal Camera
Cash4Life Maryland Winning Numbers
Team 1 Elite Club Invite
Robot or human?
Jesus Calling December 1 2022
Chelsea player who left on a free is now worth more than Palmer & Caicedo
DL1678 (DAL1678) Delta Historial y rastreo de vuelos - FlightAware
Mail Healthcare Uiowa
Horned Stone Skull Cozy Grove
Scentsy Dashboard Log In
Pwc Transparency Report
Full Range 10 Bar Selection Box
The Weather Channel Facebook
Chile Crunch Original
Les Schwab Product Code Lookup
Costco Gas Foster City
Mani Pedi Walk Ins Near Me
Images of CGC-graded Comic Books Now Available Using the CGC Certification Verification Tool
Water Days For Modesto Ca
Gopher Hockey Forum
Ltg Speech Copy Paste
Guinness World Record For Longest Imessage
Blush Bootcamp Olathe
R/Orangetheory
Serenity Of Lathrop - Manteca Photos
Wow Quest Encroaching Heat
El agente nocturno, actores y personajes: quién es quién en la serie de Netflix The Night Agent | MAG | EL COMERCIO PERÚ
School Tool / School Tool Parent Portal
Omnistorm Necro Diablo 4
Leena Snoubar Net Worth
Why I’m Joining Flipboard
R/Moissanite
Anhedönia Last Name Origin
Craigslist Boats Dallas
Craigs List Hartford
Tattoo Shops In Ocean City Nj
Kenner And Stevens Funeral Home
Lucifer Morningstar Wiki
10 Types of Funeral Services, Ceremonies, and Events » US Urns Online
Displacer Cub – 5th Edition SRD
Unpleasant Realities Nyt
Morbid Ash And Annie Drew
Raley Scrubs - Midtown
Marion City Wide Garage Sale 2023
BYU Football: Instant Observations From Blowout Win At Wyoming
Gameplay Clarkston
Unity Webgl Extreme Race
La Fitness Oxford Valley Class Schedule
Latest Posts
Article information

Author: Jeremiah Abshire

Last Updated:

Views: 5373

Rating: 4.3 / 5 (74 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Jeremiah Abshire

Birthday: 1993-09-14

Address: Apt. 425 92748 Jannie Centers, Port Nikitaville, VT 82110

Phone: +8096210939894

Job: Lead Healthcare Manager

Hobby: Watching movies, Watching movies, Knapping, LARPing, Coffee roasting, Lacemaking, Gaming

Introduction: My name is Jeremiah Abshire, I am a outstanding, kind, clever, hilarious, curious, hilarious, outstanding person who loves writing and wants to share my knowledge and understanding with you.