This guide will help you to get familiar with Modbus connector configuration for ThingsBoard IoT Gateway.
Use general configuration to enable this connector.
We will describe connector configuration file below.
In order to connect to Modbus server, the one must set required parameters of section “server”. Due to the nature of preferred way of communication with Modbus server there are 2 options how to configure this part: if using TCP/UDP or via Serial port.
There are 2 variants of server section:
|
|
This sub-section provides array of configurations for devices.
This configuration contains common connection parameters and settings for data processing. Available parameters are as follows:
Parameter | Default value | Description |
---|---|---|
unitId | 1 | Id of current device on Modbus. |
deviceName | Temp Sensor | Name of the current device |
attributesPollPeriod | 5000 | Period in milliseconds for check the attributes on device. |
timeseriesPollPeriod | 5000 | Period in milliseconds for check the telemetry on device. |
sendDataOnlyOnChange | true | Sending only if data changed from last check, if no – data will send after every check |
Example:
"devices": [
{
"unitId": 1,
"deviceName": "Temp Sensor",
"attributesPollPeriod": 5000,
"timeseriesPollPeriod": 5000,
"sendDataOnlyOnChange": true,
Configuration in this unit provides settings for processing data on Modbus server, which will be interpreted in ThingsBoard platform instance as attribute of device.
Parameter | Default value | Description |
---|---|---|
tag | test | Tag, which will use as attribute key for ThingsBoard platform instance. |
type | 32int | Type of value. Available data types |
functionCode | 4 | Function to use in processing data. Modbus functions |
objectsCount | 1 | Count of objects to read. |
address | 1 | Object address to check. |
Optional parameters:
multiplier - result of reading will be multiplied by value of this parameter.
divider - result of reading will be divided by value of this parameter.
Example:
"attributes": [
{
"tag": "test",
"type": "32int",
"functionCode": 4,
"objectsCount": 1,
"address": 1
}
],
Configuration in this unit provides settings for processing data on Modbus server, which will be interpreted in ThingsBoard platform instance as telemetry of device.
Parameter | Default value | Description |
---|---|---|
tag | test | Tag, which will use as attribute key for ThingsBoard platform instance. |
type | 16uint | Type of value. Available data types |
functionCode | 4 | Function to use in processing data. Modbus functions |
objectsCount | 1 | Count of objects to read. |
address | 1 | Object address to check. |
Example:
"timeseries": [
{
"tag": "test",
"type": "16uint",
"functionCode": 4,
"objectsCount": 1,
"address": 1
}
],
Configuration in this unit provides settings for Attribute update requests from ThingsBoard platform instance.
Parameter | Default value | Description |
---|---|---|
tag | shared_attribute_write | Shared attribute name. |
type | 32int | Type of value. Available data types |
functionCode | 6 | Function to use in processing data. Modbus functions |
objectsCount | 2 | Count of objects to write. |
address | 1 | Object address. |
Example:
"attributeUpdates": [
{
"tag": "shared_attribute_write",
"type": "32int",
"functionCode": 6,
"objectsCount": 2,
"address": 1
}
],
Configuration in this unit provides settings for RPC requests from ThingsBoard platform instance to device.
Parameter | Default value | Description |
---|---|---|
tag | setValue | RPC method name. |
type | bits | Type of value. Available data types |
functionCode | 5 | Function to use in processing data. Modbus functions |
objectsCount | 1 | Count of objects to write. |
address | 1 | Object address. |
Example:
"rpc": [
{
"tag": "setValue",
"type": "bits",
"functionCode": 5,
"objectsCount": 1,
"address": 1
}
],
Additional information about Modbus functions and supported data types.
The Modbus connector supports the following Modbus functions:
Modbus function code | Description |
Read data | |
1 | Read Coils |
2 | Read Discrete Inputs |
3 | Read Multiple Holding Registers |
4 | Read Input Registers |
Write data: | |
5 | Write Coil |
6 | Write Register |
15 | Write Coils |
16 | Write Registers |
A list and description of the supported data types for reading/writing data.
Type | Function code | Objects count | Note |
---|---|---|---|
string | 3-4 | 1-… | Read bytes from registers and decode it (‘UTF-8’ coding). |
bytes | 3-4 | 1-… | Read bytes from registers. |
bits | 1-4 | 1-… | Read coils. If objects count 1 - result will be interpret as a boolean, else the result will be an array with bits. |
16int | 3-4 | 1 | Integer 16 bit. |
16uint | 3-4 | 1 | Unsigned integer 16 bit. |
16float | 3-4 | 1 | Float 16 bit. |
32int | 3-4 | 2 | Integer 32 bit. |
32uint | 3-4 | 2 | Unsigned integer 32 bit. |
32float | 3-4 | 2 | Float 32 bit. |
64int | 3-4 | 4 | Integer 64 bit. |
64uint | 3-4 | 4 | Unsigned integer 64 bit. |
64float | 3-4 | 4 | Float 64 bit. |
Explore guides related to main ThingsBoard features: