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.
    1. {
    2. "server": {
    3. "name": "OPC-UA Default Server",
    4. "url": "localhost:4840/freeopcua/server/",
    5. "timeoutInMillis": 5000,
    6. "scanPeriodInMillis": 5000,
    7. "disableSubscriptions":false,
    8. "subCheckPeriodInMillis": 100,
    9. "showMap": false,
    10. "security": "Basic128Rsa15",
    11. "identity": {
    12. "type": "anonymous"
    13. },
    14. "mapping": [
    15. {
    16. "deviceNodePattern": "Root\\.Objects\\.Device1",
    17. "deviceNamePattern": "Device ${Root\\.Objects\\.Device1\\.serialNumber}",
    18. "attributes": [
    19. {
    20. "key": "temperature °C",
    21. "path": "${ns=2;i=5}"
    22. }
    23. ],
    24. "timeseries": [
    25. {
    26. "key": "humidity",
    27. "path": "${Root\\.Objects\\.Device1\\.TemperatureAndHumiditySensor\\.Humidity}"
    28. },
    29. {
    30. "key": "batteryLevel",
    31. "path": "${Battery\\.batteryLevel}"
    32. }
    33. ],
    34. "rpc_methods": [
    35. {
    36. "method": "multiply",
    37. "arguments": [2, 4]
    38. }
    39. ],
    40. "attributes_updates": [
    41. {
    42. "attributeOnThingsBoard": "deviceName",
    43. "attributeOnDevice": "Root\\.Objects\\.Device1\\.serialNumber"
    44. }
    45. ]
    46. }
    47. ]
    48. }
    49. }

    Section “server”

    Configuration in this section uses for connecting to OPC-UA 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 OPC-UA server.
timeoutInMillis 5000 Timeout in seconds for connecting to OPC-UA server.
scanPeriodInMillis 5000 Period to rescan the server.
disableSubscriptions false If true - the gateway will subscribe to interesting nodes and wait for data update and if false - the gateway will rescan OPC-UA server every scanPeriodInMillis
subCheckPeriodInMillis 100 Period to check the subscriptions in the OPC-UA server.
showMap true Show nodes on scanning true or false.
security Basic128Rsa15 Security policy (Basic128Rsa15, Basic256, Basic256Sha256)

Subsection “identity”

There are several types available for this subsection:

  1. anonymous
  2. username
  3. cert.PEM | anonymous
    (recommended if all servers in the local network)
    | username
    (recommended as basic level of security)
    | cert.PEM
    (recommended as better level of security)
    | | —- | —- | —- |

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:

  1. "identity": {
  2. "type": "anonymous"
  3. },

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 5Tr0nG?@$sW0rD Password for logging into the OPC-UA server.

This part of configuration will look like:

  1. "identity": {
  2. "username": "user",
  3. "password": "5Tr0nG?@$sW0rD"
  4. },

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 5Tr0nG?@$sW0rD Password for logging into the OPC-UA server.

Optionally, you can provide the username/password pair.
This part of configuration will look like:

  1. "identity": {
  2. "type": "cert.PEM",
  3. "caCert": "etc/thingsboard-gateway/ca.pem",
  4. "privateKey": "etc/thingsboard-gateway/private_key.pem",
  5. "cert": "etc/thingsboard-gateway/cert.pem",
  6. "mode": "SignAndEncrypt",
  7. "username": "user",
  8. "password": "5Tr0nG?@$sW0rD"
  9. },

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 Root\.Objects\.Device1 Regular expression, uses for looking the node for a current device.
deviceNamePattern Device ${Root\.Objects\.Device1\.serialNumber} Path to variable with device name, uses for looking the device name in some variable.

This part of configuration will look like:

  1. "deviceNodePattern": "Root\\.Objects\\.Device1",
  2. "deviceNamePattern": "Device ${Root\\.Objects\\.Device1\\.serialNumber}",


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 temperature °C Tag, that will interpreted as attribute for ThingsBoard platform instance.
path ${ns=2;i=5} Name of the variable in the OPC-UA object, uses for looking the value in some variable. *

* You can put here some expression for search like:

  1. Full path to node - ${Root.Objects.Device1.TemperatureAndHumiditySensor.Humidity}
  2. Relative path from device object - ${TemperatureAndHumiditySensor.Humidity}
  3. Some regular expression to search - ${Root.Objects.Device\d*.TemperatureAndHumiditySensor.Humidity}
  4. Namespace identifier and node identifier - ${ns=2;i=5}

This part of configuration will look like:

  1. "attributes": [
  2. {
  3. "key": "temperature °C",
  4. "path": "${ns=2;i=5}"
  5. }
  6. ],

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 humidity Tag, that will interpreted as telemetry for ThingsBoard platform instance.
path ${Root\.Objects\.Device1\.TemperatureAndHumiditySensor\.Humidity} Name of the variable in the OPC-UA object, uses for looking the value in some variable. *

* You can put here some expression for search like:

  1. Full path to node - ${Root.Objects.Device1.TemperatureAndHumiditySensor.Humidity}
  2. Relative path from device object - ${TemperatureAndHumiditySensor.Humidity}
  3. Some regular expression to search - ${Root.Objects.Device\d*.TemperatureAndHumiditySensor.Humidity}
  4. Namespace identifier and node identifier - ${ns=2;i=5}

This part of configuration will look like:

  1. "timeseries": [
  2. {
  3. "key": "humidity",
  4. "path": "${Root\\.Objects\\.Device1\\.TemperatureAndHumiditySensor\\.Humidity}"
  5. }
  6. ],

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:

  1. "rpc_methods": [
  2. {
  3. "method": "multiply",
  4. "arguments": [2, 4]
  5. }
  6. ],

Subsection “attributes_updates”

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

Parameter Default value Description
attributeOnThingsBoard deviceName Name of server side argument.
attributeOnDevice Root\.Objects\.Device1\.serialNumber Name of variable that will change itself value with a value from attribute update request.

This part of configuration will look like:

  1. "attributes_updates": [
  2. {
  3. "attributeOnThingsBoard": "deviceName",
  4. "attributeOnDevice": "Root\\.Objects\\.Device1\\.serialNumber"
  5. }
  6. ]