Warning
The main branch of this repository contains work-in-progress development code for the upcoming release, and is not guaranteed to be stable or working. It is only compatible with the main branch of edgex-compose which uses the Docker images built from the main branch of this repo and other repos.The source for the latest release can be found at Releases.
For latest documentation please visit https://docs.edgexfoundry.org/latest/microservices/device/services/device-opc-ua/Purpose
This repository is a Go-based EdgeX Foundry Device Service which uses OPC-UA protocol to interact with the devices or IoT objects.
- Subscribe/Unsubscribe one or more variables (writable configuration)
- Execute read command
- Execute write command
- Execute method (using Read command of device SDK)
- Edgex-go: core data, core command, core metadata
- OPCUA Server (Prosys Simulation Server, for example)
Download the Prosys OPC UA Simulation Server from here. Install and run it to have access to the default configured resources.
Modify configuration.yaml file found under the ./cmd/res
folder if needed
Define devices for device-sdk to auto upload device profile and create device instance. Please modify Simple_Devices.yaml file found under the ./cmd/res/devices
folder.
This device service is currently limited to a single device instance.
A Device Profile can be thought of as a template of a type or classification of a Device.
Write a device profile for your own devices; define deviceResources
and deviceCommands
. Please refer to OpcuaServer.yaml.
OPC UA methods can be referenced in the device profile and called with a read command. An example of a method instance might look something like this:
deviceResources:
-
name: "SetDefaultsMethod"
description: "Set all variables to their default values"
properties:
# Specifies the response value type
valueType: "String"
readWrite: "R"
attributes:
{ methodId: "ns=5;s=Defaults", objectId: "ns=5;i=1111" }
deviceCommands:
-
name: "SetDefaults"
isHidden: false
readWrite: "R"
resourceOperations:
- { deviceResource: "SetDefaultsMethod" }
Notice that method calls require specifying the NodeId of both the method and its parent object.
The attributes
field may also contain an inputMap: []
that passes parameters to the method, if applicable.
-
Clone the device-rest-go repo with the following command:
git clone https://github.com/edgexfoundry/device-opc-ua.git
-
Build a docker image by using the following command:
make docker
-
Alternatively the device service can be built natively:
make build
Running unit tests starts a mock OPCUA server on port 48408
.
The mock server defines the following attributes:
Variable Name | Type | Default Value | Writable |
---|---|---|---|
ro_bool |
Boolean |
True |
|
rw_bool |
Boolean |
True |
✅ |
ro_int32 |
Int32 |
5 |
|
rw_int32 |
Int32 |
5 |
✅ |
square |
Method |
Int64 (return value) |
All attributes are defined in ns=2
.
# Install requirements (if necessary)
python3 -m pip install opcua
# Run tests
make test
This component is packaged as docker images.
Please refer to the Dockerfile and Docker Compose Builder scripts.