CREATING A MODBUS CONNECTION
Available since ThingPark X IoT Flow 1.6.1.
The Modbus connection writes the values of your devices to the registers of a Modbus slave embedded in the connection. The link is unidirectional (uplink only). Your partners connect to the Modbus slave and poll the register values with their own Modbus clients.
There are two ways to write a value to a register:
- Direct mapping: a data path of a device is mapped to a register address of a slave ID.
- Templated mapping: a device type (for example, Milesight AM103) is mapped to a range of addresses. Another set of rules maps each device to a slave ID.
See Direct Mapping Rules and Templated Rules.
Collecting Expected Information
| UI Field | Description |
|---|---|
| Name | Name of the connection. |
| Bind Address | IP address on which the embedded Modbus slave listens, when the server has several network interfaces. |
| Bind Port | Port on which the embedded Modbus slave listens, from 502 to 507. |
| Coils Size | Number of Modbus coils in the registry. A coil holds a true/false value. |
| Holding Registers Size | Number of Modbus holding registers in the registry. A holding register holds a 16-bit value. |
You set the mapping rules in the Mapping Rules and Templated Rules sections of the connection details.
Direct Mapping Rules
Direct mapping is strict, but you control the allocation of each address. Each rule maps a data value of a device to a register of a slave ID.

Templated Rules
Templated rules can be used together with direct mapping rules. They are more dynamic: the mapping is based on the output of the driver.
- In Driver Templating, map a data path of the output of a driver (protocol ID) to a register.

- In Device Mapping, map each device to a slave ID. You can also add an offset to use another area of the registry.

In the examples above, if the devices 74FE48FFFF5A3D9F and A81758FFFE04F27E are Advantech Wise 1, the registry can contain:
| Device | Data | Register | Slave ID |
|---|---|---|---|
| 74FE48FFFF5A3D9F | /LrrESP | 108 | 1 |
| A81758FFFE04F27E | /LrrESP | 208 | 1 |
| 24E124136B324566 | /LrrESP | 8 | 3 |
| 74FE48FFFF5A3D9F | /payload/Device/BatteryVolt | 116 | 1 |
| A81758FFFE04F27E | /payload/Device/BatteryVolt | 216 | 1 |
Even if 24E124136B324566 is not an Advantech Wise 1, some of its data is extracted by the rules whose protocol ID is *.
Data Types
Modbus coils hold boolean (true/false) values. If coilsSize is set to 1000, the registry can hold 1000 true/false values.
The Modbus connector writes each value taken from the uplink JSON with one of the following data types:
| Data type | API value | Description |
|---|---|---|
| BOOLEAN | BOOLEAN | A true/false value, written to a Modbus coil. The mapping rule gives the address of the coil. |
| INTEGER UNSIGNED (16BITS) | TWO_BYTE_INT_UNSIGNED | A 16-bit unsigned integer value, written to a Modbus holding register. |
| INTEGER SIGNED (16BITS) | TWO_BYTE_INT_SIGNED | A 16-bit signed integer value, written to a Modbus holding register. |
| INTEGER UNSIGNED (32BITS) | FOUR_BYTE_INT_UNSIGNED | A 32-bit unsigned integer value, written to two Modbus holding registers. |
| INTEGER SIGNED (32BITS) | FOUR_BYTE_INT_SIGNED | A 32-bit signed integer value, written to two Modbus holding registers. |
| FLOAT (32BITS) | FLOAT | A 32-bit floating point value, written to two Modbus holding registers. |
| DOUBLE (64BITS) | DOUBLE | A 64-bit floating point value, written to four Modbus holding registers. |
Older configurations use the type INTEGER, which is written as INTEGER SIGNED (32BITS).
A Modbus holding register is 16 bits long. A single holding register can hold one of the following values:
- A 16-bit signed integer value
- A 16-bit unsigned integer value
Other data types use several registers. How the data is written and read depends on the implementation.
Creating a Connection With UI
- In ThingPark Enterprise, click Connections -> + Add Connection -> ThingPark X IoT Flow.

- In ThingPark X IoT Flow, click Modbus in the list of connectors.

- Fill in the form as in the example below.

- Click Create. A notification confirms that the connection has been created.
- The connection details open.

Parameters marked with * are mandatory.
Changing the Settings After Creation
In the connection details, the Basic Settings section shows the settings of the connection.
- Click the Edit button next to the setting to change.

- Enter the new value and click the Confirm button.

- Confirm the update.

A notification confirms that the setting is updated.

Creating a Connection With API
To do this, you need to use the Connections group resource:
POST /connectionsto create a new Connection instancePUT /connectionsto update a Connection instanceDELETE /connectionsto delete a Connection instance
We follow the REST-full API pattern, when updating configuration properties for a connection resource. Thus, you must also provide the whole configuration again.
Example for creation of a new connection instance:
POST /connections
{
"connectorId": "actility-modbus-iot",
"name": "Modbus Slave",
"configuration": {
"bindAddress": "0.0.0.0",
"bindPort": 502,
"coilsSize": 1000,
"holdingRegistersSize": 1000,
"mappingRules": [
{
"devEUI": "0025CA0A00007E45",
"data": "/payload/TempHumi/SenVal",
"register": 100,
"type": "INTEGER",
"slaveId": 1
},
{
"devEUI": "0025CA0A00007E45",
"data": "/LrrSNR",
"register": 100,
"type": "FLOAT",
"slaveId": 1
},
{
"devEUI": "0025CA0A00007E45",
"data": "/wrongField",
"register": 120,
"type": "BOOLEAN",
"slaveId": 4
},
{
"devEUI": "0025CA0A00007E45",
"data": "/LrrESP",
"register": 140,
"type": "FLOAT",
"slaveId": 3
},
{
"devEUI": "0025CA0A00007E45",
"data": "/Late",
"register": 160,
"type": "BOOLEAN",
"slaveId": 3
}
],
"mappingTemplatedRules": {
"templatingRules": [
{
"data": "/DevEUI_uplink/LrrRSSI",
"protocolId": "*",
"register": 0,
"type": "FLOAT"
},
{
"data": "/LrrSNR",
"protocolId": "*",
"register": 4,
"type": "FLOAT"
},
{
"data": "/LrrESP",
"protocolId": "*",
"register": 8,
"type": "FLOAT"
},
{
"data": "/payload/TempHumi/SenVal",
"protocolId": "advantec:wise:1",
"register": 12,
"type": "INTEGER"
},
{
"data": "/payload/Device/BatteryVolt",
"protocolId": "advantec:wise:1",
"register": 16,
"type": "INTEGER"
},
{
"data": "/payload/Accelerometer/X-Axis/Peakmg",
"protocolId": "advantec:wise:1",
"register": 20,
"type": "FLOAT"
},
{
"data": "/payload/Accelerometer/Y-Axis/Peakmg",
"protocolId": "advantec:wise:1",
"register": 24,
"type": "FLOAT"
},
{
"data": "/payload/Accelerometer/Z-Axis/Peakmg",
"protocolId": "advantec:wise:1",
"register": 28,
"type": "FLOAT"
},
{
"tag": [
"Abeeway",
"nke"
],
"data": "/payload/Accelerometer/Z-Axis/Peakmg",
"register": 30,
"type": "FLOAT"
}
],
"deviceToSlaveIds": [
{
"deviceEUI": "74FE48FFFF5A3D9F",
"offset": 100,
"slaveId": 1
},
{
"deviceEUI": "A81758FFFE04F27E",
"offset": 200,
"slaveId": 1
},
{
"deviceEUI": "24E124136B324566",
"offset": 0,
"slaveId": 3
}
]
}
}
}
The following table lists the properties applicable to a connection instance.
| Field | Description |
|---|---|
connectorId | Must be set to actility-modbus-iot. |
configuration/bindAddress | IP address on which the embedded Modbus slave listens, when the server has several network interfaces. |
configuration/bindPort | Port on which the embedded Modbus slave listens. Only ports 502 to 507 are allowed. |
configuration/coilsSize | Number of Modbus coils (each coil holds a true/false value) in the registry. |
configuration/holdingRegistersSize | Number of Modbus holding registers (each register holds a 16-bit value) in the registry. |
configuration/mappingRules | Direct mapping rules: each rule writes the value at the path data of the uplinks of the device devEUI to the register register of the slave slaveId, with the data type type. |
configuration/mappingTemplatedRules/templatingRules | Driver templating rules: each rule maps a data path of the output of a driver (protocolId) to a base register address, with the data type type. |
configuration/mappingTemplatedRules/deviceToSlaveIds | Device mapping rules: each rule maps a device (deviceEUI) to a slave ID, with an offset added to the register addresses. |
All properties are not present in this example. You can check the rest of these properties in the common parameters section.
Associating Devices With the Connection
In ThingPark Enterprise, open Devices, select a device, and add the connection to the Connections of the device. You can also select the connection when you create a device, or for many devices at once with a CSV file in Devices -> Bulk Operations.
Displaying Information to Know if It Worked
This example uses a device A30958FFFE05A175 associated with the connection, and mapping rules that write its /payload/temperature to register 100 as FLOAT (32BITS) and its /payload/humidity to register 80 as INTEGER UNSIGNED (16BITS), on slave ID 1.
- Send the following uplink:
{
"DevEUI_uplink": {
"Time": "2021-10-28T17:04:09.387+00:00",
"DevEUI": "A30958FFFE05A175",
"FPort": 5,
"FCntUp": 69725,
"ADRbit": 1,
"MType": 2,
"FCntDn": 8733,
"payload_hex": "0100df022904002b0500070e4e",
"mic_hex": "aadbf8dd",
"Lrcid": "000000CB",
"LrrRSSI": -42.0,
"LrrSNR": 9.25,
"LrrESP": -42.48772,
"SpFact": 7,
"SubBand": "G1",
"Channel": "LC2",
"DevLrrCnt": 2,
"Lrrid": "10000035",
"Late": 0,
"Lrrs": {
"Lrr": [
{
"Lrrid": "10000035",
"Chain": 0,
"LrrRSSI": -42.0,
"LrrSNR": 9.25,
"LrrESP": -42.48772
},
{
"Lrrid": "100001F7",
"Chain": 0,
"LrrRSSI": -32.0,
"LrrSNR": 7.5,
"LrrESP": -32.710819
}
]
},
"CustomerID": "100002164",
"CustomerData": {
"alr": {
"pro": "ELSYS/A",
"ver": "1"
}
},
"ModelCfg": "1:TWA_100002164.1105.AS",
"DriverCfg": {
"mod": {
"pId": "elsys",
"mId": "ers",
"ver": "1"
},
"app": {
"pId": "elsys",
"mId": "generic",
"ver": "1"
}
},
"InstantPER": 0.0,
"MeanPER": 1.1E-5,
"DevAddr": "0512B338",
"AckRequested": 0,
"rawMacCommands": "",
"TxPower": 2.0,
"NbTrans": 1,
"Frequency": 867.3,
"DynamicClass": "A",
"payload": {
"temperature": 19.4,
"humidity": 46,
"light": 43,
"motion": 0,
"vdd": 3662
},
"points": {
"temperature": {
"unitId": "Cel",
"type": "double",
"record": 19.4
},
"humidity": {
"unitId": "%RH",
"type": "double",
"record": 46
},
"light": {
"unitId": "lx",
"type": "double",
"record": 43
},
"co2Level": {
"unitId": "ppm",
"type": "double",
"record": 43
},
"batteryVoltage": {
"unitId": "mV",
"type": "double",
"record": 3662
},
"batteryLevel": {
"unitId": "%",
"type": "double",
"record": 101.72
}
}
}
}
-
Download and unzip the latest release of Modbus Mechanic.
-
In the extracted ModbusMechanic folder, double-click the ModbusMechanic.jar file. The following window opens:

- Fill in IP and Port with the values of your Modbus connection. Set Slave Node to 1. Select the Read Holding Registers (0x03) function from the list.

- Enter 100 as the register number and select Float as the data value type. Click Transmit packet. The response value is 19.4.

- Enter 80 as the register number and select Unsigned Int16 as the data value type. Click Transmit packet. The response value is 46.

Limitations
When coilsSize or inputRegistersSize of the Modbus connection changes, the existing Modbus registry is wiped out and a new one is created: all the values in the registry are lost.
Troubleshooting
There is no known issue with the Modbus connector.