I wrote up a custom dotnet core template to create a starting point for Azure IoT Edge modules targeting OPC-UA communication as a client. There is a project for connecting to OPC-UA devices called OPC Publisher for Azure IoT Edge

This reference implementation demonstrates how Azure IoT Edge can be used to connect to existing OPC UA servers and publishes JSON encoded telemetry data from these servers in OPC UA “Pub/Sub” format (using a JSON payload) to Azure IoT Hub. All transport protocols supported by Azure IoT Edge can be used, i.e. HTTPS, AMQP and MQTT (the default).

which sounds promising but lacks some integration into the Azure IoT Edge message queuing system and module twin properties updates. Also I just wanted to have a simple client to call a device that’s it.

Installation & Usage

To install the .NET Core template for your command line you can simply

1
dotnet new -i DariuszParys.OPC.IoTEdgeModule.CSharp

this will download and install the template for your command line interface. Check with executing dotnet new if the template is successfully installed

1
2
3
4
5
6
7
8
9
10
11
12
13
C:\>dotnet new -i DariuszParys.OPC.IotEdgeModule.CSharp
Restoring packages for C:\Users\devel\.templateengine\dotnetcli\v2.0.3\scratch\restore.csproj...
Installing DariuszParys.OPC.IoTEdgeModule.CSharp 1.0.0.
Generating MSBuild file C:\Users\devel\.templateengine\dotnetcli\v2.0.3\scratch\obj\restore.csproj.nuget.g.props.
Generating MSBuild file C:\Users\devel\.templateengine\dotnetcli\v2.0.3\scratch\obj\restore.csproj.nuget.g.targets.
Restore completed in 1,99 sec for C:\Users\devel\.templateengine\dotnetcli\v2.0.3\scratch\restore.csproj.
Vorlagen Kurzname Sprache Tags
---------------------------------------------------------------------------------------------------------------
...
Azure IoT Edge OPC-UA Module (Client) aziotedgeopcmodule [C#] Console
...

To setup a new project simply run

1
dotnet new aziotedgeopcmodule -n "MyOpcModule"

Where MyOpcModule should be exchanged with the name you want to have for your module.

Code Asset Overview

This project includes a variety of code assets. Based on the .NET Standard Library samples from the OPC Foundation I included all necessary code plumbing to make a fresh start easier.

Opc-Related.cs

This file implements the partial class Module. It has all the necessary OPC-UA plumbing to connect to the device and provides session handling.

Module.cs

This is the other partial class implementation of Module. This file is responsible for integrating into the queueing of Azure IoT Edge and also implements module twin update handling.

ModuleConfig.cs

Here you define the configuration for your module which will be updated via module twin updates.

Dockerfiles

There are three different Dockerfiles provided. One for linux-x64, Windows nano-containers and Linux-ARM 32bit.

Github Repo

The template is also available in a public Github repo https://github.com/dariuszparys/edgev2-opc-client in case you prefer to modify it or just want to have a look without installing the template itself.

I also have another project on Github where you can see the OPC Foundation .NET Core sample client and server running in Azure IoT Edge with install scripts provided for easier testing.

Summary

OPC-UA communication is one of the standards Azure IoT Edge supports through various ways. This template should make a good starting point to get fast onboarded.