Building Azure IoT Edge with OPC UA support

To build Azure IoT Edge, we can use the OPC UA publisher that is available at the Git repository: https://github.com/Azure/iot-edge-opc-publisher. We can build this using Visual Studio Code, or we can download the Docker image.

Before starting the Docker image, we need to retrieve few pieces of information:

  1. From the IoT Hub, we need to retrieve the connection string. Click on the iothubowner policy and copy and paste the connection string:

Getting the connection string for the Azure IoT Edge
  1. Now, we need to configure the OPC UA server. In an empty directory, called something like azure-edge, create a file called publishednodes.json. If we plan to use the OPC UA Prosys Server developed in Chapter 6, Performing an Exercise based on Industrial Protocols and Standards, we can configure this as follows:
[
{
"EndpointUrl": "opc.tcp://opcuaserver:53530/OPCUA/SimulationServer",
"OpcNodes": [
{
"ExpandedNodeId": "nsu=http://www.prosysopc.com/OPCUA/SimulationNodes;s=MyDevice.Pump_01.Pressure",
"OpcSamplingInterval": 2000,
"OpcPublishingInterval": 5000
}
]
}
]
  1. Finally, from the command line, we can run the following command. We need to replace <opc-ua server ip> with the IP address of the OPC UA Proxy Server, and <IoT Hub connection string> with the Azure IoT Hub connection string retrieved previously. We also need to provide the full path of the <azure-edge directory> in which we stored the publishednodes.json file:
docker run --rm -it -v <azure-edge directory>:/docker --name publisher --add-host opcuaserver:<opc-ua server ip> microsoft/iot-edge-opc-publisher:2.1.4 publisher "<IoT Hub connection string>" --lf /docker/publisher.log.txt --as true --si 1 --ms 0 --tm true --vc true --di 30

Azure IoT Edge will connect to the OPC UA Proxy Server and subscribe to the temperature measure, polling for a new value every 5,000 ms. The measure will only be published if the value has changed.

In the log file, publisher.log.txt, we should be able to find a line that is similar to the following:

10/12/2018 11:02:37: Created monitored item for node 'ns=5;s=MyDevice.Pump_01.Pressure' in subscription with id '2' on endpoint 'opc.tcp://opcuaserver:53530/OPCUA/SimulationServer'

We can also check whether the messages have sent or not in the IoT Hub console. The expected output is as follows:

The Azure IoT Hub log, showing Azure IoT Edge connections to the Hub
At the time of writing this book, the OPC UA publisher module is constantly changing. We suggest that you take a look at the official documentation for the most up-to-date version. In this exercise, we are using the latest stable version 2.14.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset