Modbus TCP Client
This page documents the client route (
MODBUS_TCP)—the broker connects to a remote Modbus device and polls registers over MQTT. To expose MQTT topics to Modbus masters instead (SCADA, HMIs connect to the broker), see Modbus TCP Server.MODBUS_TCP route enables communication with PLCs, RTUs, and industrial devices using the Modbus TCP/IP protocol. It supports reading and writing registers and coils with configurable polling intervals and automatic batch optimization.
Basic Syntax
Connection Configuration
MODBUS_CONFIG Parameters
Modbus TCP server hostname or IP address.
Modbus TCP port. Default: 502.
Modbus slave/unit ID (1-247). Default: 1.
Connection timeout in milliseconds. Default: 5000.
Read operation timeout in milliseconds. Default: 1000.
Write operation timeout in milliseconds. Default: 1000.
Number of retry attempts on failure. Default: 3.
Delay between retries in milliseconds. Default: 100.
Treat plain numeric tag addresses as one-based (address
1 = PDU register 0). Modicon-style addresses (400001+, 300001+, 100001+) are always decoded regardless of this flag. See Modbus addressing.Connection Example
Address Types
Modbus defines four address spaces:| Address Type | Description | Function Codes | Typical Use |
|---|---|---|---|
HOLDING_REGISTER | Read/Write 16-bit registers | FC03, FC06, FC16 | Setpoints, configuration |
INPUT_REGISTER | Read-only 16-bit registers | FC04 | Sensor values, measurements |
COIL | Read/Write single bits | FC01, FC05, FC15 | Digital outputs, controls |
DISCRETE_INPUT | Read-only single bits | FC02 | Digital inputs, status |
Most Modbus devices use Holding Registers for configuration and Input Registers for measured values. Check your device documentation for the correct address type.
Modbus Addressing
Modbus addressing varies by vendor. Coreflux supports three styles—choose the one that matches your device documentation.Style 1 — Zero-based PDU offsets (default)
The Modbus protocol uses zero-based addresses in the PDU. This is the default (ONE_BASED_ADDRESSES = false).
| Device manual label | Tag ADDRESS |
|---|---|
| Register 1 | "0" |
| Register 100 | "99" |
0, or when targeting integration tests that follow PDU numbering.
Style 2 — One-based plain addresses
Most device manuals label the first holding register as 1, not 0. SetWITH ONE_BASED_ADDRESSES true on MODBUS_CONFIG to use those labels directly in tag addresses.
| Device manual label | Tag ADDRESS |
|---|---|
| Register 1 | "1" |
| Register 100 | "100" |
Style 3 — Modicon notation
Traditional Modicon prefix notation is always accepted. The prefix determines the address type automatically:| Modicon range | Address type | Example |
|---|---|---|
| 400001–465536 | Holding register | 400001 → PDU 0 |
| 300001–365536 | Input register | 300001 → PDU 0 |
| 100001–165536 | Discrete input | 100001 → PDU 0 |
Modicon-style addresses are decoded the same way regardless of
ONE_BASED_ADDRESSES. The flag only affects plain numeric addresses (those without a Modicon prefix).Conversion reference
| Device manual label | ONE_BASED_ADDRESSES false | ONE_BASED_ADDRESSES true | Modicon notation |
|---|---|---|---|
| Register 1 | "0" | "1" | "400001" |
| Register 100 | "99" | "100" | "400100" |
| Register 1000 | "999" | "1000" | "401000" |
FLOAT, INT32, and so on) occupy consecutive registers from the resolved starting address.
Data Types
The data type determines how raw register values are interpreted:
| Data Type | Size | Description |
|---|---|---|
BOOL | 1 bit | Boolean value (for coils/discrete inputs) |
BIT | 1 bit | Alias for BOOL |
INT8 | 8 bits | Signed 8-bit integer |
UINT8 | 8 bits | Unsigned 8-bit integer |
INT16 | 16 bits | Signed 16-bit integer (1 register) |
UINT16 | 16 bits | Unsigned 16-bit integer (1 register) |
INT32 | 32 bits | Signed 32-bit integer (2 registers) |
UINT32 | 32 bits | Unsigned 32-bit integer (2 registers) |
INT64 | 64 bits | Signed 64-bit integer (4 registers) |
UINT64 | 64 bits | Unsigned 64-bit integer (4 registers) |
FLOAT | 32 bits | 32-bit floating point (2 registers) |
DOUBLE | 64 bits | 64-bit floating point (4 registers) |
STRING | Variable | ASCII string across multiple registers |
TAG Configuration
Complete TAG Parameters
TAG Parameters Reference
Address Configuration
Address Configuration
Register or coil address. Plain numeric (0–65535 zero-based by default, or 1–65536 when
ONE_BASED_ADDRESSES true), or Modicon notation (400001+, 300001+, 100001+). See Modbus addressing.Type of Modbus address:
HOLDING_REGISTER, INPUT_REGISTER, COIL, or DISCRETE_INPUT.Value Transformation
Value Transformation
Filtering
Filtering
Publishing
Publishing
Write Configuration
Write Configuration
Event-Based Operations
For on-demand Modbus operations (not polling), use the EVENT syntax. Publish a message to SOURCE_TOPIC to trigger the operation; the route executes it and publishes the result to DESTINATION_TOPIC.Query Syntax
TheWITH QUERY value uses LoT object syntax: unquoted keys, unquoted identifiers, and numeric values. The entire query is wrapped in double quotes.
| Element | Format | Example |
|---|---|---|
| Keys | Unquoted | operation, start_address, count |
| Operation values | Unquoted identifiers | READ_HOLDING_REGISTERS, READ_COILS |
| Numeric values | Unquoted | 0, 10, 100 |
| String values | Unquoted (addresses) | address: 100 |
Supported Operations
| Operation | Description |
|---|---|
READ_HOLDING_REGISTERS | Read holding registers (FC03) |
READ_INPUT_REGISTERS | Read input registers (FC04) |
READ_COILS | Read coils (FC01) |
READ_DISCRETE_INPUTS | Read discrete inputs (FC02) |
WRITE_SINGLE_REGISTER | Write single holding register (FC06) |
WRITE_MULTIPLE_REGISTERS | Write multiple holding registers (FC16) |
WRITE_SINGLE_COIL | Write single coil (FC05) |
WRITE_MULTIPLE_COILS | Write multiple coils (FC15) |
Query Parameters by Operation
| Operation | Parameters | Example |
|---|---|---|
READ_HOLDING_REGISTERS | start_address, count | {operation: READ_HOLDING_REGISTERS, start_address: 0, count: 10} |
READ_INPUT_REGISTERS | start_address, count | {operation: READ_INPUT_REGISTERS, start_address: 0, count: 5} |
READ_COILS | start_address, count | {operation: READ_COILS, start_address: 0, count: 8} |
READ_DISCRETE_INPUTS | start_address, count | {operation: READ_DISCRETE_INPUTS, start_address: 0, count: 8} |
WRITE_SINGLE_REGISTER | address, value | {operation: WRITE_SINGLE_REGISTER, address: 100, value: 42} |
WRITE_MULTIPLE_REGISTERS | start_address, values | {operation: WRITE_MULTIPLE_REGISTERS, start_address: 0, values: [100, 200]} |
WRITE_SINGLE_COIL | address, value | {operation: WRITE_SINGLE_COIL, address: 0, value: true} |
WRITE_MULTIPLE_COILS | start_address, values | {operation: WRITE_MULTIPLE_COILS, start_address: 0, values: [true, false, true]} |
Complete Examples
- Basic Sensor Reading
- Multiple Polling Rates
- Bidirectional Control
- Coils and Digital I/O
- Combined (Cyclic + On-Demand)
Read temperature and pressure from a Modbus device:
Troubleshooting
Connection Timeout
Connection Timeout
- Verify IP address and port are correct
- Check firewall settings (port 502 must be open)
- Ensure device is powered on and connected to network
- Try increasing
CONNECTION_TIMEOUT
Incorrect Values
Incorrect Values
- Verify
ADDRESSmatches device documentation—tryWITH ONE_BASED_ADDRESSES trueif the manual labels registers starting at 1 - Use Modicon notation (
400100) when the datasheet shows prefixed addresses - Check
BYTE_ORDERandWORD_ORDERsettings - Confirm
DATA_TYPEmatches register size - Verify
SCALINGandOFFSETcalculations
Write Operations Fail
Write Operations Fail
- Ensure
WRITABLEis set to “true” - Verify
ADDRESS_TYPEisHOLDING_REGISTERorCOIL - Check device permissions for write operations
- Verify value is within
MIN_VALUEandMAX_VALUE
Slave ID Errors
Slave ID Errors
- Confirm correct
SLAVE_ID(usually 1 for TCP devices) - Some gateways use different slave IDs for different devices
- Check device documentation for correct unit ID
Next Steps
Modbus Serial Client
Connect to RS-232/RS-485 Modbus RTU devices.
Modbus TCP Server
Expose MQTT topics as Modbus registers for SCADA and HMIs.

