Create OPC-UA Thing Description

The following is an example of a Thing Description to be instantiated by the OPC-UA driver:

{
    "@type": [
        "swx:opcua,endpoint=opc.tcp://localhost:26543,interval=1000"
    ],
    "id": "<leave blank when creating a thing>",
    "title": "My OPCUA Test Device",
    "properties": {
        "ns=1;s=Temperature": {
            "@type": "float64",
            "title": "Temperature",
            "type": "number",
            "readOnly": true
        },
        "opcuaInterval": {
            "title": "Reporting Interval",
            "type": "integer",
            "readOnly": false
        }
    }
}
There are two important items to note here:
  • the “swx:opcua,endpoint=opc.tcp://…” string in the “@type” array
  • the “ns=1;s=Temperature” property key

The first item is essential for the OPC-UA driver to recognise this Thing Description as a OPC-UA device. Details on how to construct this string can be found in the next section.

The second item is essential for the OPC-UA driver to recognise the node it needs to manage. Details on how to construct property keys and the rest of the property object can be found in a subsequent section.

Construct the “swx:opcua,endpoint=opc.tcp://…” “@type”?

The following element in the “@type”` array is required to configure the OPC-UA endpoint. It is comma-separated string of parameters. The element has to start with swx:opcua.

"swx:opcua,endpoint=opc.tcp://localhost:26543,interval=1000"

The remaining items in the comma-separated list are key value pairs separated by equal signs. The following keys are allowed:

Basic:
Element Importance Description
endpoint Required This is the endpoint of the OPC-UA server
interval Optional The subscription interval in milliseconds (default 30000):
It is recommended to only set the basic options and leave the advanced ones to the default values. If the OPC-UA server does not allow self-signed certs to be used by clients then the advanced options can be used.
Advanced:
Element Importance Description
mode Optional The security mode to use, available options auto, None, Sign, SignAndEncrypt (default auto).
policy Optional The security policy to use, available options auto, None, Basic128Rsa15, Basic256, Basic256Sha256, Aes128_Sha256_RsaOaep, Aes256_Sha256_RsaPss (default auto)
autogencert Optional Auto generate a self-signed cert if no certfile/keyfile are specified (default true).
certfile Optional A public cert to use for communication with the endpoint.
keyfile Optional The private key of the public cert.
auth Optional The authentication method for the connection to the server (default Anonymous).
username Optional Needed when authentication method is set to user and password.
password Optional Needed when authentication method is set to user and password.
If either mode of policy are set to None then they will both be treated as set to None.
If either mode of policy are set to auto then the highest available security mode and level as recommended by the server will be used.
If only policy is set to auto then the highest available security level with the requested mode will be used.
If only mode is set to auto then the highest available security level with the requested policy will be used.
If no authentication method is configured, a UserIdentityToken for anonymous authentication will be set.

Construct a Property

The nodes to report are specified as keys in “properties” section. Example below:
"ns=1;s=Temperature": {
    "@type": "float64",
    "title": "Temperature",
    "type": "number",
    "readOnly": true
},
The corresponding section of node discovery report is the following:
"Objects": {
    "MyDevices": {
        "Temperature": {
            "BrowseName": "Temperature",
            "DataType": "float64",
            "Description": "",
            "DisplayName": "Temperature",
            "NodeID": "ns=1;s=Temperature",
            "Value": 34.52512524858854,
            "Writable": false
        },

The complete NodeID should be used at the property key of the Thing Description.

The @type is the DataType returned in the report.

The readOnly should be set to true if Writable is false (and vice versa).

The type can be determined from the DataType where available options are number, integer, string, etc. (see the Web-of-Things Modelling section).

If it is desirable to change the subscription interval on-the-fly then the opcuaInterval property as shown in the example of the introduction should be included in the Thing Description.