Skip to content

OPC-UA Device Service Component

The OPC-UA Device Service components integrate the OPC-UA protocol with XRT. For further reading about the OPC-UA protocol, see the OPC Foundation website.

The OPC-UA Device Service components support the following features:

  • Secure and unsecure connections to a remote OPC-UA server
  • Reading and writing to an OPC-UA endpoint
  • Monitored Item Service for monitoring Data Change Items and Event Items
  • TranslateBrowsePathsToNodeIds Service
  • Browse Service

OPC-UA Device Service Configuration

Note

The core components required for running OPC-UA (and all other device services) are contained in Device Service Component Configuration. Please refer to this page to ensure the appropriate core components are assigned before continuing.

With those components assigned, there are also the following optional OPC-UA Driver options that can be used to configure the device service:

OPC-UA Driver Options

Parameter Type Description Default Value
LDSName String The device names of the LDS servers added to XRT. Multiple servers can be specifed by separating the device names with a semi-colon. Empty

A template of the OPC-UA device service configuration file is provided where the driver options have been set to demonstrate their usage:

{
  "Library": "libxrt-opcua-device-service.so",
  "Factory": "xrt_opcua_device_service_factory",
  "Name": "opcua_device_service",
  "Topic": "opcua_device_service/data",
  "RequestTopic": "xrt/device/bacnet_ip_device_service/request",
  "ReplyTopic": "xrt/device/bacnet_ip_device_service/reply",
  "DiscoveryRequestTopic": "xrt/discovery/bacnet_ip_device_service/request",
  "DiscoveryReplyTopic": "xrt/discovery/bacnet_ip_device_service/reply",
  "DiscoveryTopic": "xrt/discovery/bacnet_ip_device_service/devices",
  "ProfileRequestTopic": "xrt/profile/bacnet_ip_device_service/request",
  "ProfileReplyTopic": "xrt/profile/bacnet_ip_device_service/reply",
  "ScheduleRequestTopic": "xrt/schedule/bacnet_ip_device_service/request",
  "ScheduleReplyTopic": "xrt/schedule/bacnet_ip_device_service/reply",
  "StateDir": "opcua-device-service/state",
  "ProfileDir": "opcua-device-service/profiles",
  "Scheduler": "sched",
  "Logger": "logger",
  "ThreadPool": "pool",
  "Bus": "bus",
  "Driver": {
    "LDSName": "lds-server1;lds-server2",
  }
}

OPC-UA Device Profile

Details on general profile usage can be found on the Device Profiles page

The following sections will cover how device resources are mapped to OPC-UA nodes.

Attributes

The attributes used in an OPC-UA device resource are described in the following table:

Attribute Description Valid Values
nsIndex Mandatory

The namespace index of the node in the OPC-UA server
UInt16
nodeID Optional

The identifier of the node in the OPC-UA server
Valid values are as follows:
  • string
  • guid
  • bytestring
  • uint32
IDType Optional

The data type used for the nodeID attribute
Valid values are as follows:
  • STRING
  • NUMERIC
  • BYTESTRING
  • GUID
startNode Optional

The name of the starting node for the translation of browse path to node ID
The nodeID in the following format:

<namespaceIndex>;<IDType>=<nodeID>
browsePath Optional

The name of a child node qualified with a namespace URI, relative to either the startNode attribute or the RootNode protocol property
String
monitored Optional

Specifies whether the defined nodes in a remote server are monitored using OPC-UA subscriptions

Set to true to monitor the nodes
Valid values are as follows:
  • true
  • false (default)
publishInterval Optional

Applies only when monitored is set to true

The value in milliseconds of the publishing interval requested when creating a new subscription ID
Double

Example resources

The device resource below allows for read access to the Server state node found in OPC-UA servers, accessed using it's namespace, node ID and ID Type.

{
    "name": "ServerState",
    "description": "The Server State",
    "attributes": {
        "nodeID": "2259",
        "nsIndex": "0",
        "IDType": "NUMERIC"
    },
    "properties": {
        "value": {
            "type": "Int32",
            "readWrite": "R"
        }
    }
}

Similarly, we could also represent this node using its browse path. The ServerStatus node's parent is the Server Node which has a namespace of 0 and an numeric identifier of 2253.

{
    "name": "ServerState",
    "description": "The Server State",
    "attributes": {
        "nsIndex": "0",
        "startNode" : "0;i=2253",
        "browsePath" : "ServerStatus"
    },
    "properties": {
        "value": {
            "type": "Int32",
            "readWrite": "R"
        }
    }
}

If we want to set up a subscription to monitor changes in the value of this item we can add the monitored attrubute. We can set the interval at which changes in this value are tested by the server with the publishInterval attribute.

{
    "name": "ServerState",
    "description": "The Server State",
    "attributes": {
        "nodeID": "2259",
        "nsIndex": "0",
        "IDType": "NUMERIC",
        "monitored": "true",
        "publishInterval": "10000",
    },
    "properties": {
        "value": {
            "type": "Int32",
            "readWrite": "R"
        }
    }
}

Data Types

When the remote OPC-UA server receives a request, it returns a value with an OPC-UA type. The following table lists the supported OPC-UA data types and their equivalent XRT data type:

OPC-UA Data Type XRT Data Type
UA_Boolean Bool
UA_Byte UInt8
UA_Uint16 UInt16
UA_Uint32 UInt32
UA_Uint64 UInt64
UA_SByte Int8
UA_Int16 Int16
UA_Int32 Int32
UA_Int64 Int64
UA_Float Float32
UA_Double Float64
UA_String String
UA_DateTime Int64

Device Commands

See the Device Commands page for details on how to define device commands for grouping device resources for fewer requests.

OPC-UA Device Provisioning

The following section will explain how to configure a device for the OPC-UA device service.

Note

For information on dynamic device additions, removals and updates please see the MQTT API Guide.

Provisioning

To provision an OPC-UA device, the OPC-UA protocol must be used along with the Address protocol property which specifies the address of the OPC-UA server.

A basic example of an OPC-UA device provision within the devices.json file is provided below:

{
   "OPCUASimulator": {
    "name": "OPCUASimulator",
    "profile": "opc-ua-simulator-profile",
    "protocols": {
      "OPC-UA": {
        "Address": "localhost:49947"
      }
    }
  }   
}

Device Protocol Properties

There are some additional protocol properties that can be used to configure a device:

Parameter Type Description Default Value
Address String Mandatory

The URI of the OPC-UA server in the following format:

<myServerAddress>:<serverPort><endpointPath> e.g 127.0.0.1:4840/Endpoint
N/A
Security String Optional

The security policy to be used for connecting to the OPC-UA server Valid values are as follows:
  • None
  • Basic128Rsa15
  • Basic256Sha256
None
Username String Optional

The username to be used during connection to an endpoint
N/A
Password Base64-encoded String Optional

The password associated with the username used during connection to an endpoint
N/A
ApplicationUri String Optional

The URI associated with any certificate used to connect to the remote OPC-UA server
Empty
SecurityMode String Optional

The message security mode used with secure connections to the OPC-UA server Valid values are as follows:
  • Sign
  • SignEncrypt
Sign
Certificate String Optional

The name of the DER file containing the certificate to use when establishing a secure connection
certificate.der
PrivateKey String Optional

The name of the DER file containing the private key to use when establishing a secure connection
private_key.der
RequestedSessionTimeout UInt32 Optional

The suggested timeout for sessions created between the Device Service and an OPC-UA server endpoint in milliseconds
1200000
RootNode String Optional

The starting point for the TranslateBrowsePathsToNodeIds Service and the full server tree browse functionality in the following format:

<namespaceIndex>;<IDType>=<nodeID> e.g 3;i=42
The servers root folder node
BrowseSubFilter String Optional

Describes the node types to be subscribed to as part of the browse functionality Valid values are as follows:
  • All
  • Variable
  • Event
Empty
BrowseDepth UInt8 Optional

Represents the maximum depth of the server tree browse for this device
0
BrowsePublishInterval Double Optional

The value to use for the requested publish interval when setting up system-generated subscriptions
0.0

Note

Currently, device protocol properties only support string values

OPC-UA Device Service Interaction

Any sections contained within the part of the guide are to describe protocol specific functionality of the device service.

For information on how to dynamically execute reads, writes, setting up schedules, triggering device discovery and much more, please refer to the MQTT API Guide.

OPC-UA Auto-events

Auto events, in the OPC-UA device service, provide the ability create subscriptions to monitor variable and event nodes. When the monitored item's value is updated on the server, the device service will recieve a notification and will post the updated value. The server will poll this monitored item at a configurable interval rate.

To set up an OPC-UA monitored item it is similar to how a schedule is configured. The main differences are that the interval property is ignored, and there is an extra field called options. There should be a Subscription field which can contain options for the subscription.

Subscription Setting Description Valid Values
Interval The interval at which the server will poll the monitored resource. UInt32 Value

An example of how an OPC-UA subscription can be made is provided below as a static configuration in the schedules.json file.

{
    "subscription": {
      "name":"example-schedule",
      "device":"ExampleDevice",
      "resource":["Resource1", "Resource2"],
      "options": {
          "Subscription": {
            "Interval" : 1500
          }
      }
    }
}

To change the interval at which the server will poll the monitored resource, set the Interval property to your desired polling rate.

Note

The polling rate is ultimately decided by the server, meaning that it can ignore this value when creating a new subscription to the monitored resource.

Run the OPC-UA Device Service

Find details on how to run the OPC-UA device service on the Run Device Services page.

Back to top