OPC-UA Discovery
The OPC-UA Device Service can automatically discover, generate device profiles for, and onboard OPC-UA endpoints. This can greatly simplify the process for connecting to new OPC-UA servers and devices.
To use the OPC-UA Device Service discovery capability, it is required to have an OPC-UA Local Discovery Server (LDS) set up as an Edge Xpert device.
Note
This example uses an OPC-UA simulator to start an OPC-UA LDS on port 4840 and an OPC-UA Server on port 49947. To learn more about this simulator, see the Edge Xrt documentation.
## Preconfiguration
## Create a local docker-compose file to override the default service settings
version: '3.7'
services:
device-opc-ua:
environment:
LDSName: LDS
DEVICE_DISCOVERY_ENABLED: 'true'
XRTCONTROL_DISCOVERY_IDENTIFIER: 'Address'
LDSName
: name of the Local Discovery Server (LDS)DEVICE_DISCOVERY_ENABLED
: specifies whether device discovery is enabledXRTCONTROL_DISCOVERY_IDENTIFIER
: must be one of the OPC-UA protocol properties, e.g. 'Address'
Start Services
-
Deploy the Local Discovery Server (LDS):
docker run --rm -d --network=host --hostname=172.17.0.1 --name opc-ua-lds iotechsys/opc-ua-lds:1.2
Note
Some OPC-UA server (for example Prosys) require a secure connection to allow discovery operations. In those cases we must provide the key and cert to the LDS, as shown in the example below.
docker run --rm -it --network=host --name opc-ua-lds -v /path/to/keys:/keys/ iotechsys/opc-ua-lds:1.2 urn:open62541.server.application /keys/server_cert.der /keys/server_key.der
-
Deploy the OPC-UA simulator:
docker run --rm -d --network=host --hostname=172.17.0.1 --name opc-ua-sim iotechsys/opc-ua-sim:1.2 -l /example-scripts/simulation.lua --discovery-url=opc.tcp://172.17.0.1:4840
-
Deploy Edge Xpert with the
xpert-manager
anddevice-opc-ua
services:$ edgexpert up xpert-manager device-opc-ua Overriding configuration with local docker-compose.yml
Onboard the LDS to Edge Xpert
To use device discovery, an LDS must first be set up as a device in Edge Xpert.
Info
If Edge Xpert is running in secure mode, you will need to replace localhost in the URL with the IP address for the service. See CLI Service Ports for details.
-
Add a device profile for the LDS. This requires a dummy deviceResource as shown below:
curl http://localhost:59881/api/v2/deviceprofile -H "Content-Type:application/json" -X POST \ -d '[ { "apiVersion": "v2", "profile": { "name": "LDS_profile", "apiVersion": "v2", "description": "LDS profile", "deviceResources": [ { "attributes": { "nodeId": { "identifierType": "NUMERIC", "identifier": 2259, "namespaceIndex": 0 }, "nodeAttribute": "value", "dataTypeId": { "identifierType": "NUMERIC", "identifier": 852, "namespaceIndex": 0 } }, "description": "The Server State", "name": "ServerState", "properties": { "readWrite": "R", "valueType": "UInt32" } } ], "labels": [ "opc-ua" ] } } ]'
-
Register the LDS as an Edge Xpert device:
curl http://localhost:59881/api/v2/device -H "Content-Type:application/json" -X POST \ -d '[ { "apiVersion": "v2", "device": { "name" :"LDS", "serviceName": "device-opc-ua", "profileName": "LDS_profile", "protocolName": "opc-ua", "protocols":{ "OPC-UA":{ "Address": "172.17.0.1:4840/", "Security": "None" } }, "adminState":"UNLOCKED", "operatingState":"UP" } } ]'
Discovered Devices
The device service will automatically trigger discovery at 30 second interals (by default) and attempt to find any available OPC-UA devices:
$ docker logs -f device-opc-ua
...
level=INFO ts=2022-04-12T22:46:51.570249959+08:00 app=device-opc-ua source=message.go:58 msg="Service started in: 8.020531518s"
level=INFO ts=2022-04-12T22:46:51.570301426+08:00 app=device-opc-ua source=autodiscovery.go:51 msg="Starting auto-discovery with duration 30s"
level=INFO ts=2022-04-12T22:46:51.570342052+08:00 app=device-opc-ua source=driver.go:248 msg="Trigger Discover..."
[xrt:1668086073603334:console:Info] OPC-UA Discovery: Found 2 devices
[xrt:1668086073603368:console:Info] OPC-UA Discovery: Finished
[xrt:1668086103606508:console:Info] OPC-UA Discovery: Started
...
The devices that were discovered and onboarded can be viewed as normal in the Edge Xpert Manager UI or by running the following command:
curl localhost:59881/api/v2/device/all
This should return the simulated OPC-UA device running on port 49947. Available deviceResources include a Counter, Sawtooth and Sinusoid simulations (as implemented by the Lua script within the simulator started above).
Note that the OPC-UA discovery process may also discover the LDS running on port 4840, which is itself an OPC-UA device. This can be blocked during the discovery process if desired. See Automatic Discovery for more details.
Note
When registering with the LDS, the device should provide a physical IP address or a reachable hostname in the registration information. If the device or simulator uses a specific/local machine name as the address, the OPC-UA device service might be unable to reach or resolve that location when it comes to connecting to the device. In that case, you might see an error message similar to that shown below:
[xrt:1692962225987670:console:Debug] Getting server opc.tcp://machine-name:53530/OPCUA/SimulationServer's endpoints
[2023-08-25 11:17:10.988 (UTC+0000)] warn/network DNS lookup of machine-name failed with error -3 - Unknown error
[2023-08-25 11:17:10.988 (UTC+0000)] warn/client Could not open a TCP connection to opc.tcp://machine-name:53530/OPCUA/SimulationServer
services:
device-opc-ua:
environment:
...
extra_hosts:
machine-name: "172.17.0.1"
machine-name
with yours.
Discovered Device Profiles
Note that the discovery process includes the automatic generation and onboarding of device profiles that describe each discovered OPC-UA server device.
If desired, the user can export these device profiles from the Edge Xpert Manager UI and use them to onboard OPC-UA devices using the the manual device onboarding process. The user may choose to first edit or update the profiles to include specific additional information either by editing the files manually or by importing and editing the profiles in IOTech's Device Configuration Tool (DCT). This workflow helps to simplify the intial task of creating a device profile, particularly when the OPC-UA Server references a large number of devices or resouces.