Skip to content

Training: OPC UA to Azure IoT Hub & MQTT Integration


    IoT, IIoT, MQTT, Connectivity of Things, Big Data, Cloud – we’ve all heard these terms, whether in the scope of our jobs or in an advertisement.  But maybe you’re working on a project requiring you to push and/or pull important process or business data to/from a cloud solution – possibly for populating machinery or system digital twins to be used in analytics applications ranging from predictive maintenance to machine learning, amongst many other use cases.

    You have probably heard about the Microsoft Azure platform but may not be aware of the Azure IoT Hub.  Azure IoT Hub is Microsoft’s managed cloud service platform for integrating IoT devices with Azure. Essentially, it’s the gateway for IoT data integration with all of the other services and functionality at your disposal in Azure – artificial intelligence, advanced analytics, machine learning, and other big data concepts geared towards smarter interconnectivity of literally any and all devices. Azure IoT Hub lets you create digital “twins” of your devices in the cloud and then populate them with live process data that you push to the cloud.

    In this article we will show you how to push OPC UA enabled process data to Azure IoT Hub at a high level and provide free access to virtual online training and tools to try it yourself.

    In the training we use the Cogent DataHub IoT Gateway and its built-in MQTT Client that empowers you to take OPC UA data and use MQTT to publish data with preconfigured, templated connections for Microsoft Azure IoT Hub, MQTT brokers, Google IoT Hub, or Amazon IoT Core. The DataHub can implement unidirectional or bi-directional data transfer between the cloud systems and standard industrial protocols such as OPC UA clients and servers and many more.

    6 Steps to Getting your OPC UA data (*) into Azure IoT Hub

    We will highlight these key steps here and you can access a free detailed video and guide at the end of this article:

    1. Configure an OPC UA connection in DataHub

    The first step is simply getting the Cogent DataHub connected to your OPC UA data source. DataHub supports both OPC UA client and server interfaces for getting your OPC UA capable systems connected securely, as well as integrating OPC Classic data sources.As with all supported DataHub interfaces, once your OPC data is in DataHub, it can be used with any other supported interface which, for our purposes here, is going to be the MQTT Client interface.

    1. Verifying the Connection String and Security Keys for your Azure IoT Hub

    The next step is logging in to your Azure Portal Dashboard (you’ll need to have an Azure account setup for this) and setting up a Shared Access Policy which will then provide the required Connection String and security keys for MQTT connections to the Azure IoT Hub and which will be used in the next step for further configuration of the Azure IoT Hub. We cover this in more detail in our free guide & video that you can access at the end of this article.

    1. Connecting Azure IoT Hub with Azure IoT Explorer

    Microsoft has written and released the Azure IoT Explorer as a means to manage devices in the Azure IoT Hub. It can be used to not only create, delete and/or edit the IoT devices, but also generate the access tokens needed to interact with them from an MQTT client like DataHub. All you need is the IoT Hub Connection String Key (highlighted in the previous step) to connect the Explorer to your IoT Hub.Once connected to the Azure IoT Hub, you can use the Azure IoT Explorer to configure “Devices” to represent your IoT data sources.

    1. Using the Azure IoT Explorer to Setup an IoT Device

    Using the Azure IoT Explorer, you can access an existing IoT Device or create a new one in the Devices tab, then generate the SAS security token used in the MQTT Client of the DataHub to securely connect to the Azure IoT Hub.

    An SAS token, in case you aren’t familiar, is a string you generate for use by MQTT clients to verify those clients are authorized to make connections to your Azure IoT Hub.

    1. Configure the DataHub MQTT Client to publish to Azure IoT Hub

    Once the necessary steps have been taken in the Azure IoT Hub and via the IoT Explorer, you can setup the connection from the DataHub MQTT Client via the specialized template you can see in the screenshot below using the settings gathered from Azure IoT Hub.With the specialized template for Azure IoT Hub, the specific details (including the MQTT payload format) are simplified such that connecting to Azure is straightforward to setup.

    DataHub makes it possible to quickly specify the desired OPC UA and other process data that you wish to publish to Azure, as well as, and MQTT topics you wish to pull from Azure (a mechanism in Azure referred to as “Cloud-to-device events” since Azure does not technically allow MQTT clients to subscribe to a topic). Such events are setup and generated from the Azure IoT Hub portal.

    1. Monitor your published data in Azure IoT Hub

    Once you’ve connected your DataHub to Azure and are publishing the desired OPC UA and other process data sources, you will naturally want to monitor and confirm that everything is behaving as desired. For this purpose, the Azure IoT Hub Explorer can be used once again to monitor messages sent to the cloud. In this case it can be used to confirm the DataHub is publishing the data, and to confirm the format used for any Azure side scripting/processing that will be done.

    This is accomplished under the Telemetry section in the IoT Explorer, with events being received populating as shown below. As such, you can verify that your value, quality, and other parameters are being published as expected.Get Your Training Video & Guide

    The Cogent DataHub MQTT Client connection to Azure IoT Hub that we’ve just highlighted is easy, secure, and reliable. With just a few steps it is possible to begin to stream your own OPC UA process and business data to Azure IoT, convert between MQTT and any DataHub supported protocol, and act as an MQTT gateway for OPC UA clients and servers and other process interfaces. Once published, your Azure hosted cloud analytics, machine learning and other applications can consume the data from your Azure IoT hosted digital twins.

    Our free On-Demand Video Training steps you through every detail of how to get your own OPC systems connected and streaming to Microsoft Azure IoT Hub using the Cogent DataHub free trial. When you request the access to the video training, you will also receive a link to a step-by-step PDF reference and training guide.

    Watch Now

    (*) Editor’s note: The data format used is specific to the Cogent DataHub Gateway and not OPC UA compliant. For gateway solutions that send OPC UA compliant data to the cloud, please contact the OPC Foundation.