This comprehensive guide is designed to familiarize you with the Modbus connector configuration for ThingsBoard IoT Gateway. In the following sections, we will provide a detailed description of the connector configuration, covering all aspects necessary for successful implementation and customization.
The Modbus connector is a powerful tool that allows seamless integration between Modbus devices and the ThingsBoard platform.
Please note: If you are new to IoT Gateway, use the “Basic” configuration mode. If you are familiar with configuring IoT Gateway, you can use the “Advanced” configuration mode.
Connector configuration
Connector configuration is a UI form that contains information about how to connect to Modbus slaves. Let’s look at all the available settings and explain each one clearly. This will help you understand how everything works.
Please note: Connect the gateway before creating the connector. Otherwise, the UI will display the old configuration fields for backward compatibility.
Section “General”
This configuration section contains general connector settings, such as:
Name - connector name for logs and saving to persistent devices;
Logs configuration:
Enable remote logging - enabling remote logging for connector;
Logging level - logging level for local and remote logs: INFO, DEBUG, WARNING, ERROR, CRITICAL, TRACE, NONE;
The general tab is the same for both the basic and advanced configurations.
Section “Master Connections”
A Modbus Master is used to query data from Modbus servers (slaves). In order to configure servers for data retrieving, you need to specify list of slaves.
To add new configuration for connection to server, navigate to the “Master Connections” tab and click the “plus” icon:
Due to the nature of preferred way of communication between Modbus master there are 2 options how to configure this part: if using TCP, UDP or via Serial port.
The table below describes the parameters required to configure TCP connection for slave:
Parameter
Default value
Description
Host
127.0.0.1
Hostname or ip address of Modbus server
Port
5021
Port of Modbus server for connection
Method
Socket
Type of a framer Socket or RTU, if needed
Unit ID
1
ID of current slave on Modbus
Device name
Temp Sensor
Name of the current slave
Device profile
default
Device profile of the current slave
The table below describes the parameters required to configure UDP connection for slave:
Parameter
Default value
Description
Host
127.0.0.1
Hostname or ip address of Modbus server
Port
5021
Port of Modbus server for connection
Method
Socket
Type of a framer Socket or RTU, if needed
Unit ID
1
ID of current slave on Modbus
Device name
Temp Sensor
Name of the current slave
Device profile
default
Device profile of the current slave
The table below describes the parameters required to configure serial connection for slave:
Parameter
Default value
Description
Port
Port of Modbus server for connection
Method
Socket
Type of a framer Socket or RTU, if needed
Baudrate
4800
Baudrate for The baud rate to use for the serial device
Bytesize
5
The number of bits in a byte of serial data. This can be one of 5, 6, 7, or 8
Stopbits
1
The number of bits sent after each character in a message to indicate the end of the byte
Parity
None
The type of checksum to use to verify data integrity. This can be on of the following: (E)ven, (O)dd, (N)one
Strict
true
Use Inter char timeout for baudrates <= 19200
Unit ID
1
ID of current slave on Modbus
Device name
Temp Sensor
Name of the current slave
Device profile
default
Device profile of the current slave
To add new configuration for connection to server, navigate to the “Configuration” tab.
Due to the nature of preferred way of communication between Modbus master there are 2 options how to configure this part: if using TCP, UDP or via Serial port.
You can configure additional settings like: TLS connection, polling time, byte order and word order, and other. The table below describes the parameters for this purpose:
Parameter
Default value
Description
Connection timeout (s)
35
Timeout in seconds for connecting to Modbus server
Byte order
LITTLE
Order of bytes to read
Word order
LITTLE
The order of words when reading several registers
Retries
true
Retrying sending data to the master. The values can be either: true or false
Retries on empty
true
Retrying sending data to the master if it is empty
Retries on invalid
true
Retrying sending data to the master if it is failed
Poll period (ms)
5000
Period in milliseconds to check the attributes and the telemetry on the slave
Connect attempt time (ms)
5000
A waiting period in milliseconds before connecting to the master
Connect attempt count
5
The number of connection attempts made through the ThingsBoard gateway
Wait after failed attempts (ms)
300000
A waiting period in milliseconds before trying to send data to the master
Click on the “Advanced connection settings” subsection to open it;
Make the necessary settings.
Also, you can configure TLS connection (can be used only for TCP/UDP connection type). The table below describes the parameters required to configure TLS connection:
Parameter
Description
Path to client certificate file
Path to certificate file in filesystem with gateway
Path to private key file
Path to private key file
Password
Server password
Server hostname
Server hostname (Should match with hostname in certificate)
You can configure additional settings like: TLS connection, polling time, byte order and word order, and other. The table below describes the parameters for this purpose:
Parameter
Default value
Description
timeout
35
Timeout in seconds for connecting to Modbus server
byteOrder
LITTLE
Order of bytes to read
wordOrder
LITTLE
The order of words when reading several registers
retries
true
Retrying sending data to the master. The values can be either: true or false
retriesOnEmpty
true
Retrying sending data to the master if it is empty
retriesOnInvalid
true
Retrying sending data to the master if it is failed
pollPeriod
5000
Period in milliseconds to check the attributes and the telemetry on the slave
connectAttemptTimeMs
5000
A waiting period in milliseconds before connecting to the master
connectAttemptCount
5
The number of connection attempts made through the ThingsBoard gateway
waitAfterFailedAttemptsMs
300000
A waiting period in milliseconds before trying to send data to the master
The configuration in this unit provides settings for processing data on Modbus server. These settings will be interpreted in ThingsBoard platform instance as attributes/time series of the device. For adding new attribute or time series use the following steps:
Click on “pencil” icon in the “Attributes” or “Time series” section (depends on the selected section);
In the opened window click “Add attribute” or “Add time series” (depends on selected section);
Fill in key, type, function code, objects count and address fields. Click “Apply”.
Also, modifier for attribute/time series value can be applied using the following settings:
Parameter
Description
Type
multiplier - the result of reading will be multiplied by the value of this parameter. divider - the result of reading will be divided by the value of this parameter
Value
The value that will be used to modify the read value
The configuration in this unit provides settings for processing data on Modbus server. These settings will be interpreted in ThingsBoard platform instance as attributes/time series of the device.
The table below describes the attributes and time series parameters:
Parameter
Description
tag
Key name
type
Type of value
functionCode
The function to use in data processing, specifically Modbus functions
ThingsBoard allows to provision device attributes and fetch some of them from the device application. You can treat this as a remote configuration for devices. Your devices are able to request shared attributes from ThingsBoard. See user guide for more details.
The “attributeUpdates” configuration allows configuring the format of the corresponding attribute request and response messages.
To add new requests mapping, navigate to the “Attribute updates” section and click the “pencil” icon;
In the opened window click “Add attribute update”;
Set an attribute key name, type, function code, objects count, and address. Then, click “Apply”.
The table below describes the attribute updates parameters:
Parameter
Description
Key
Shared attribute name
Type
Type of value
Function code
The function to use in data processing, specifically Modbus functions
Objects count
Count of objects to write
Address
Object address
For example, create a new attribute “maxTemperature” and give it a value “25”.
Go to the “Devices” page. Click on your device to open the device details, then navigate to the “Attributes” tab. Select “Server attributes” as the entity attributes scope. Then, click the “plus” icon to add a new attribute;
Name the attribute “maxTemperature”, select “Integer” as the value type, and set the value to 25;
Shared attribute is added.
The table below describes the attribute updates parameters:
Parameter
Description
tag
Shared attribute name
type
Type of value
functionCode
The function to use in data processing, specifically Modbus functions
ThingsBoard allows sending RPC commands to the device that is connected to ThingsBoard directly or via Gateway.
Configuration, provided in this section is used for sending RPC requests from ThingsBoard to device.
Section “Server configuration”: description and configuration parameters
Gateway can run as a Modbus slave. Configuration section for the Modbus server, storing data and sending updates to the platform when changes occur or at fixed intervals.
Due to the nature of preferred way of communication between Modbus master there are 2 options how to configure this part: if using TCP/UDP or via Serial port.
The table below describes the parameters required to configure TCP connection for slave:
Parameter
Default value
Description
Host
127.0.0.1
Hostname or ip address of Modbus server
Port
5021
Port of Modbus server for connection
Method
Socket
Type of a framer Socket or RTU, if needed
Unit ID
1
ID of current slave on Modbus
Device name
Temp Sensor
Name of the current slave
Device profile
default
Device profile of the current slave
Send data to ThingsBoard
false
If set to TRUE, the Gateway will perform autoconfiguration and send values to ThingsBoard every poll period
Poll period (ms)
5000
Period in milliseconds for checking the attributes and the telemetry
The table below describes the parameters required to configure UDP connection for slave:
Parameter
Default value
Description
Host
127.0.0.1
Hostname or ip address of Modbus server
Port
5021
Port of Modbus server for connection
Method
Socket
Type of a framer Socket or RTU, if needed
Unit ID
0
ID of current slave on Modbus
Device name
Modbus Slave Example
Name of the current slave
Device profile
default
Device profile of the current slave
Send data to ThingsBoard
false
If set to TRUE, the Gateway will perform autoconfiguration and send values to ThingsBoard every poll period
Poll period (ms)
5000
Period in milliseconds for checking the attributes and the telemetry
The table below describes the parameters required to configure serial connection for slave:
Parameter
Default value
Description
Port
Port of Modbus server for connection
Method
Socket
Type of application data unit - RTU or ASCII
Baudrate
4800
Baudrate for The baud rate to use for the serial device
Strict
true
Use Inter char timeout for baudrates <= 19200
Unit ID
1
ID of current slave on Modbus
Device name
Temp Sensor
Name of the current slave Don’t use “Gateway” as the value of “Device name” parameter!
Device profile
default
Device profile of the current slave
Send data to platform
false
If set to TRUE, the Gateway will perform autoconfiguration and send values to ThingsBoard every poll period.
Due to the nature of preferred way of communication between Modbus master there are 2 options how to configure this part: if using TCP/UDP or via Serial port.
You can configure additional settings like: TLS connection, byte order, word order, and other. The table below describes the parameters for this purpose:
Parameter
Description
Byte order
LITTLE
Word order
LITTLE
Vendor name
Product code
Vendor URL
Product name
Model name
Click on the “Advanced connection settings” subsection to open it;
Make the necessary settings.
You can configure additional settings like: TLS connection, byte order, word order, and other. The table below describes the parameters for this purpose:
Parameter
Description
Byte order
LITTLE
Word order
LITTLE
Vendor name
Product code
Vendor URL
Product name
Model name
Subsection “Values”
In this section you can specify initial values for registers and coils. Each value refers to a specific type of
register. There are:
Holding registers
Coils initializer
Input registers
Discrete inputs
Depending on which value the register belongs to, you must add it to the appropriate array.