iot-edge-opc-publisher-v1/README.md

3.5 KiB

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments

OPC UA Publisher Module for the Azure IoT Gateway SDK

This reference implementation demonstrates how the Azure IoT Gateway SDK 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 the Gateway SDK can be used, i.e. HTTPS, AMQP and MQTT. The transport is selected in the transport setting in the gatewayconfig.json file.

This module, apart from including an OPC UA client for connecting to existing OPC UA servers you have on your network, also includes an OPC UA server on port 62222 that can be used to configure the module.

This module uses the OPC Foundations's OPC UA reference stack and therefore licensing restrictions apply. Visit http://opcfoundation.github.io/UA-.NETStandardLibrary/ for OPC UA documentation and licensing terms.

Branch Status
master Build status Build Status

Directory Structure

/src

This folder contains the source code of the module, a managed gateway loader and a library to handle IoT Hub credentials.

Building the Module

This module requires the .NET Core SDK V1.0. You can build the module from Visual Studio 2015 by opening the solution file, right clicking the GatewayApp.NetCore project and selecting "publish". Alternatively, the module can be built from the command line with:

dotnet restore
dotnet publish .\src\GatewayApp.NetCore

Configuring the Module

The OPC UA nodes whose values should be published to Azure IoT Hub can be configured in the "publishednodes.json" file. It has the format:

[
  {
    "EndpointUrl": "opc.tcp://myopcservername:51210/UA/SampleServer",
    "NodeId": { "Identifier": "ns=1;i=123" }
  }
  {
    "EndpointUrl": "opc.tcp:// myopcservername:51210/UA/SampleServer",
    "NodeId": { "Identifier": "ns=2;i=456" }
  }
]

Configuring the Gateway

The Configuration Section must contain at a minimum all items shown in the provide file. The JSON type conforms to the OPC UA reference stack serialization of the ApplicationConfiguration type.

You should pass your application name and the IoT Hub owner connection string (which can be read out for your IoT Hub from portal.azure.com) as command line arguments. The IoT Hub owner connection string is only required for device registration with IoT Hub on first run.

Running the module

You can run the module on Windows along with the Gateway SDK and IoT Hub module directly via Visual Studio 2015 by hitting F5 (after publishing). Don't forget your command line arguments!

You can also run the module in a Docker container using the Dockerfile provided. From the root of the repo, in a console, type:

docker build -t gw .

On first run, for one-time IoT Hub registration:

docker run -it --rm gw <applicationName> <IoTHubOwnerConnectionString>

From then on:

docker run -it --rm gw <applicationName>