For the purpose of this guide, we will use Raspberry Pi with OPC-UA server.
We will use OPC-UA connector to collect data.
The info available at this moment:
Parameter | Our value | Description |
---|---|---|
Url to server | 192.168.1.113:4840/server/ | OPC-UA server addres. |
Device node path | Device\d*$ | Regular expression for path to device object on server. |
Device name path | ${server.deviceName} | Relative path from the device object to variable contains device name. |
We want to write Humidity ( relative path is ${humidity_value} ) as the telemetry to ThingsBoard and batteryLevel ( relative path is ${Battery.Level} ) as the device client-side attribute.
In order to configure the connector, we must create OPC-UA setup file and put configuration there.
You may use default opcua.json file (from /etc/thingsboard-gateway/config in case of daemon installation or from folder with tb_gateway.yaml file in case you use python package).
Simply replace some parameters with our values.
For example:
{
"server": {
"name": "OPC-UA Default Server",
"url": "192.168.1.113:4840/server/",
"scanPeriodInMillis": 10000,
"timeoutInMillis": 5000,
"security": "Basic128Rsa15",
"identity": {
"type": "anonymous"
},
"mapping": [
{
"deviceNodePattern": "Device\\d*$",
"deviceNamePattern": "${server.deviceName}",
"attributes": [
{
"key": "batteryLevel",
"path": "${Battery.Level}"
}
],
"timeseries": [
{
"key": "Humidity",
"path": "${humidity_value}"
}
]
}
]
}
}
About sections of OPC-UA configuration file you can read more here.
Let’s analyze our settings:
Save the configuration file as opcua.json in configuration folder (the directory, that contains the general configuration file - tb_gateway.yaml).
To use the connector, we must turn it on in the main configuration file (tb_gateway.yaml)
In “connectors” section we should uncomment following strings:
-
name: OPC-UA Connector
type: opcua
configuration: opcua.json
Command for run depends on type of installation.
If you have installed the gateway as daemon, run the following command:
sudo systemctl restart thingsboard-gateway
If you have installed the gateway as a python module (using pip package manager or from sources), use following command or script to run the gateway.
Notice: You must place correct path to the main configuration file (tb_gateway.yaml) in the command/script.
sudo python3 -c 'from thingsboard_gateway.gateway.tb_gateway_service import TBGatewayService; TBGatewayService("YOUR_PATH_HERE")'
or script:
from thingsboard_gateway.gateway.tb_gateway_service import TBGatewayService
config_file_path = "YOUR_PATH_HERE"
TBGatewayService(config_file_path)
Check data in your ThingsBoard instance.
- Go to the your ThingsBoard instance and login.
- Go to the “Devices” tab. “Humidity Sensor” will be there.
Go to the device details, ATTRIBUTES tab, there you may see the attribute batteryLevel with some value.
Go to the device details, LATEST TELEMETRY tab, to see your telemetries data: Humidity with some value.