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.
Define devices for device-sdk to auto upload device profile and create device instance. Please modify devices.toml
file found under the ./cmd/res/devices
folder.
This device service is currently limited to a single device instance.
# Pre-define Devices
[[DeviceList]]
Name = "SimulationServer"
Profile = "OPCUA-Server"
Description = "OPCUA device is created for test purpose"
Labels = [ "test" ]
[DeviceList.Protocols]
[DeviceList.Protocols.opcua]
Endpoint = "opc.tcp://127.0.0.1:53530/OPCUA/SimulationServer"
Modify configuration.toml
file found under the ./cmd/res
folder if needed
# Driver configs
[OPCUAServer]
DeviceName = "SimulationServer" # Name of existing Device
Policy = "None" # Security policy: None, Basic128Rsa15, Basic256, Basic256Sha256. Default: None
Mode = "None" # Security mode: None, Sign, SignAndEncrypt. Default: None
CertFile = "" # Path to cert.pem. Required for security mode/policy != None
KeyFile = "" # Path to private key.pem. Required for security mode/policy != None
[OPCUAServer.Writable]
Resources = "Counter,Random" # Device resources related to Node IDs to subscribe to (comma-separated values)
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 cmd/res/profiles/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.
make build
cd cmd
EDGEX_SECURITY_SECRET_STORE=false ./device-opcua
make docker
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