Skip to main content
Version: 1.8.5

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:

  1. Direct mapping: a data path of a device is mapped to a register address of a slave ID.
  2. 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 FieldDescription
NameName of the connection.
Bind AddressIP address on which the embedded Modbus slave listens, when the server has several network interfaces.
Bind PortPort on which the embedded Modbus slave listens, from 502 to 507.
Coils SizeNumber of Modbus coils in the registry. A coil holds a true/false value.
Holding Registers SizeNumber 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.

Direct mapping rules

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.

  1. In Driver Templating, map a data path of the output of a driver (protocol ID) to a register.

Driver templating rules

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

Device mapping rules

In the examples above, if the devices 74FE48FFFF5A3D9F and A81758FFFE04F27E are Advantech Wise 1, the registry can contain:

DeviceDataRegisterSlave ID
74FE48FFFF5A3D9F/LrrESP1081
A81758FFFE04F27E/LrrESP2081
24E124136B324566/LrrESP83
74FE48FFFF5A3D9F/payload/Device/BatteryVolt1161
A81758FFFE04F27E/payload/Device/BatteryVolt2161

Even if 24E124136B324566 is not an Advantech Wise 1, some of its data is extracted by the rules whose protocol ID is *.

Data Types​

Note on coils

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 typeAPI valueDescription
BOOLEANBOOLEANA true/false value, written to a Modbus coil. The mapping rule gives the address of the coil.
INTEGER UNSIGNED (16BITS)TWO_BYTE_INT_UNSIGNEDA 16-bit unsigned integer value, written to a Modbus holding register.
INTEGER SIGNED (16BITS)TWO_BYTE_INT_SIGNEDA 16-bit signed integer value, written to a Modbus holding register.
INTEGER UNSIGNED (32BITS)FOUR_BYTE_INT_UNSIGNEDA 32-bit unsigned integer value, written to two Modbus holding registers.
INTEGER SIGNED (32BITS)FOUR_BYTE_INT_SIGNEDA 32-bit signed integer value, written to two Modbus holding registers.
FLOAT (32BITS)FLOATA 32-bit floating point value, written to two Modbus holding registers.
DOUBLE (64BITS)DOUBLEA 64-bit floating point value, written to four Modbus holding registers.

Older configurations use the type INTEGER, which is written as INTEGER SIGNED (32BITS).

Note on holding registers

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​

  1. In ThingPark Enterprise, click Connections -> + Add Connection -> ThingPark X IoT Flow.

Add a ThingPark X IoT Flow connection in ThingPark Enterprise

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

Select the Modbus connector

  1. Fill in the form as in the example below.

Set your Modbus connection

  1. Click Create. A notification confirms that the connection has been created.

Notification of the connection creation

  1. The connection details open.

Modbus connection details

Note

Parameters marked with * are mandatory.

Changing the Settings After Creation​

In the connection details, the Basic Settings section shows the settings of the connection.

  1. Click the Edit button next to the setting to change.

Edit a setting of the Modbus connection

  1. Enter the new value and click the Confirm button.

Confirm the new value

  1. Confirm the update.

Confirm the update

A notification confirms that the setting is updated.

Notification of the update

Creating a Connection With API​

To do this, you need to use the Connections group resource:

  • POST /connections to create a new Connection instance
  • PUT /connections to update a Connection instance
  • DELETE /connections to delete a Connection instance
Note

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.

FieldDescription
connectorIdMust be set to actility-modbus-iot.
configuration/bindAddressIP address on which the embedded Modbus slave listens, when the server has several network interfaces.
configuration/bindPortPort on which the embedded Modbus slave listens. Only ports 502 to 507 are allowed.
configuration/coilsSizeNumber of Modbus coils (each coil holds a true/false value) in the registry.
configuration/holdingRegistersSizeNumber of Modbus holding registers (each register holds a 16-bit value) in the registry.
configuration/mappingRulesDirect 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/templatingRulesDriver 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/deviceToSlaveIdsDevice mapping rules: each rule maps a device (deviceEUI) to a slave ID, with an offset added to the register addresses.
Important note

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.

  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
}
}
}
}
  1. Download and unzip the latest release of Modbus Mechanic.

  2. In the extracted ModbusMechanic folder, double-click the ModbusMechanic.jar file. The following window opens:

Modbus Mechanic

  1. 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.

Connection settings in Modbus Mechanic

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

Read a float value in Modbus Mechanic

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

Read an unsigned 16-bit value in Modbus Mechanic

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.