Star

ThingsBoard Documentation

Documentation for using ThingsBoard IoT Platform.

OPC-UA Extension Configuration

This guide will help you to get familiar with OPC-UA connector configuration for ThingsBoard IoT Gateway. Use general configuration to enable this extension. We will describe connector configuration file below.


Example of OPC-UA Connector config file. Press to expand.
{
  "server": {
    "name": "OPC-UA Default Server",
    "url": "localhost:4840/freeopcua/server/",
    "scanPeriodInMillis": 10000,
    "timeoutInMillis": 5000,
    "security": "Basic128Rsa15",
    "identity": {
      "type": "anonymous"
    },
    "mapping": [
      {
        "deviceNodePattern": "MyObject\\d+",
        "deviceNamePattern": "Device ${MyVariable22}",
        "attributes": [
          {
            "key": "Tag1",
            "path": "${MyVariable1}"
          }
        ],
        "timeseries": [
          {
            "key": "Tag3",
            "path": "${Tag3}"
          },
          {
            "key": "Tag2",
            "path": "${MyVariable3}"
          }
        ],
        "rpc_methods": [
          {
            "method": "multiply",
            "arguments": [2, 4]
          }
        ],
        "attributes_updates": [
          {
            "attributeOnThingsBoard": "t",
            "attributeOnDevice": "MyVariable1"
          }
        ]
      }
    ]
  }
}

Section “server”

Configuration in this section uses for connecting to Modbus server.

Parameter Default value Description
name OPC-UA Default Server Name of connector to server.
host localhost:4840/freeopcua/server/ Hostname or ip address of Modbus server.
scanPeriodInMillis 10000 Port of Modbus server for connect.
timeoutInMillis 5000 Timeout in seconds for connecting to Modbus server.
security Basic128Rsa15 Security policy (Basic128Rsa15, Basic256, Basic256Sha256)

Subsection “identity”

There are several types available for this subsection:

  1. anonymous
  2. username
  3. cert.PEM

This option of identity subsection is simplest.

Parameter Default value Description
type anonymous Type of identity on OPC-UA server.

This part of configuration will look like:

    "identity": {
      "type": "anonymous"
    },

Using this option you can provide the username and password for connection to OPC-UA server.

Parameter Default value Description
username user Username for logging into the OPC-UA server.
password [email protected]$sW0rD Password for logging into the OPC-UA server.

This part of configuration will look like:

    "identity": {
      "username": "user",
      "password": "[email protected]$sW0rD"
    },

This option for identity is safest.

Parameter Default value Description
type cert.PEM Type of identity on OPC-UA server.
caCert /etc/thingsboard-gateway/ca.pem Path to the CA certificate.
privateKey /etc/thingsboard-gateway/private_key.pem Path to the private key.
cert /etc/thingsboard-gateway/cert.pem Path to the certificate file.
mode SignAndEncrypt Security mode, there are 2 options – Sign and SignAndEncrypt.
username user Username for logging into the OPC-UA server.
password [email protected]$sW0rD Password for logging into the OPC-UA server.

Optionally, you can provide the username/password pair.

This part of configuration will look like:

    "identity": {
      "type": "cert.PEM",
      "caCert": "etc/thingsboard-gateway/ca.pem",
      "privateKey": "etc/thingsboard-gateway/private_key.pem", 
      "cert": "etc/thingsboard-gateway/cert.pem",
      "mode": "SignAndEncrypt",
      "username": "user",
      "password": "[email protected]$sW0rD"
    },

Section “mapping”

This configuration section contains array of nodes that the gateway will subscribe to after connecting to the OPC-UA server and settings about processing data from these nodes.

Parameter Default value Description
deviceNodePattern MyObject\d+ Regular expression, uses for looking the node for a current device.
deviceNamePattern Device ${MyVariable22} JSON-path expression, uses for looking the device name in some variable.

This part of configuration will look like:

        "deviceNodePattern": "MyObject\\d+",
        "deviceNamePattern": "Device ${MyVariable22}",

Optionally, you can add in this section parameter “converter” for using custom converter.

Subsection “attributes”

This subsection contains configurations for variables of the object, that will be interpreted as attributes for the device.

Parameter Default value Description
key Tag1 Tag, that will interpreted as attribute for ThingsBoard platform instance.
path ${MyVariable} JSON-path expression, uses for looking the value in some variable.

This part of configuration will look like:

        "attributes": [
          {
            "key": "Tag1",
            "path": "${MyVariable1}"
          }
        ],

Subsection “timeseries”

This subsection contains configurations for variables of the object, that will be interpreted as telemetry for the device.

Parameter Default value Description
key Tag1 Tag, that will interpreted as telemetry for ThingsBoard platform instance.
path ${MyVariable} JSON-path expression, uses for looking the value in some variable.

This part of configuration will look like:

        "timeseries": [
          {
            "key": "Tag3",
            "path": "${Tag3}"
          }
        ],

Subsection “rpc_methods”

This subsection contains configuration for RPC request from ThingsBoard platform instance.

Parameter Default value Description
method multiply Name of method on OPC-UA server.
arguments [2,4] Arguments for the method (if this parameter doesn’t exist, arguments will take from rpc request).

This part of configuration will look like:

        "rpc_methods": [
          {
            "method": "multiply",
            "arguments": [2, 4]
          }
        ],

Subsection “attributes_updates”

This subsection contains configuration for attribute updates request from ThingsBoard platform instance.

Parameter Default value Description
attributeOnThingsBoard t Name of server side argument.
attributeOnDevice MyVariable1 Name of variable that will change itself value with a value from attribute update request.

This part of configuration will look like:

        "attributes_updates": [
          {
            "attributeOnThingsBoard": "t",
            "attributeOnDevice": "MyVariable1"
          }
        ]

Next steps

Explore guides related to main ThingsBoard features: