Skip to content

Modbus TCP Driver

Simple IoT includes a built-in Modbus TCP polling driver that reads registers on a schedule and reports them as telemetry.

Modbus config list

How it works

The platform acts as a Modbus Master, connecting to slave devices at a configured interval, reading register values, and mapping them to TSL model properties via the standard messageUp pipeline (InfluxDB persistence + rule chains + WebSocket push).

Create a config

  1. Go to Modbus -> Modbus TCP, click Add Config.
  2. Select the associated device (must already exist with TSL properties defined).
  3. Fill in slave connection info (Host, Port, Unit ID).
  4. Fill in the register mapping JSON (see below).
  5. Set the poll interval and save.

Modbus config edit

Configuration fields

FieldDescriptionExample
DeviceAssociated platform deviceModbus THP Sensor
HostModbus slave IPmodbus-sim or 192.168.1.100
PortModbus TCP port502 (standard), 5020 (demo)
Unit IDModbus slave address1
Interval (ms)How often to poll, default 50005000
Register MapJSON array defining which registers to readsee below
EnabledWhether polling is activetrue

Register mapping explained

The register map is a JSON array. Each item defines "which register to read, how to read it, and which property it maps to":

json
[
  {
    "identifier": "temperature",
    "function": 3,
    "address": 0,
    "count": 2,
    "dataType": "DOUBLE",
    "scale": 0.01
  }
]

Field reference

FieldTypeRequiredDescription
identifierstringyesTSL property identifier - must match a property defined in the device's TSL model
functionintyesModbus function code (see table below)
addressintyesStart register address (0-based)
countintyesNumber of registers to read (1 register = 16 bit = 2 bytes)
dataTypestringyesData type: BOOL / INT / FLOAT / DOUBLE
scaledoublenoScale factor, final = raw × scale, default 1.0

Function codes

functionR/WRegister typeRange
1readCoil0 or 1
2readDiscrete Input0 or 1
3readHolding Register0-65535
4readInput Register0-65535

Data types and register counts

dataTypeBytesRegisters(count)Notes
BOOL11Typically used with function=1 (coils)
INT2-41-216-bit: count=1, 32-bit: count=2
FLOAT42IEEE 754 single precision
DOUBLE84IEEE 754 double precision

Scale factor

Many Modbus devices return integers that need multiplication to get the real physical value. E.g. a temperature sensor returns 2040 but the real temperature is 20.4°C, so scale = 0.01.

Note: when scale != 1.0, the system automatically promotes the data type to DOUBLE.

Full example

A temp/humidity/pressure sensor + switch, 4 properties:

json
[
  {
    "identifier": "temperature",
    "function": 3,
    "address": 0,
    "count": 2,
    "dataType": "DOUBLE",
    "scale": 0.01
  },
  {
    "identifier": "humidity",
    "function": 3,
    "address": 2,
    "count": 1,
    "dataType": "INT"
  },
  {
    "identifier": "pressure",
    "function": 3,
    "address": 4,
    "count": 2,
    "dataType": "DOUBLE",
    "scale": 0.1
  },
  {
    "identifier": "switch",
    "function": 1,
    "address": 100,
    "count": 1,
    "dataType": "BOOL"
  }
]

Meaning:

  • Holding registers 0-1 -> temperature (DOUBLE, ÷100)
  • Holding register 2 -> humidity (INT)
  • Holding registers 4-5 -> pressure (DOUBLE, ÷10)
  • Coil 100 -> switch (BOOL)

Demo simulator

Docker Compose includes a modbus-sim container with the above config pre-seeded:

ItemValue
Containermodbus-sim
Port5020 (container port 502 mapped to 5020)
Unit ID1
Devicemodbus-thp-001

After deploy, you can see live data on the dashboard: temperature ≈ 20°C, humidity ≈ 60%, pressure ≈ 101kPa.

Testing & troubleshooting

  • Test button: clicking "Test" in the config list triggers an immediate poll - check logs to verify connectivity.
  • Device offline: check if Host/Port is reachable, Unit ID is correct.
  • No data: check that identifier exactly matches the TSL property ID.
  • Wrong values: check scale and dataType - 32-bit integers need count=2.
  • Frequent timeouts: increase the poll interval or check network quality.

Released under the MIT License.