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
string
required
Modbus TCP server hostname or IP address.
integer
Modbus TCP port. Default: 502.
integer
Modbus slave/unit ID (1-247). Default: 1.
integer
Connection timeout in milliseconds. Default: 5000.
integer
Read operation timeout in milliseconds. Default: 1000.
integer
Write operation timeout in milliseconds. Default: 1000.
integer
Number of retry attempts on failure. Default: 3.
integer
Delay between retries in milliseconds. Default: 100.
boolean
default:"false"
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: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).
Use this when documentation labels the first register as
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.
Style 3 — Modicon notation
Traditional Modicon prefix notation is always accepted. The prefix determines the address type automatically: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
Multi-word types (
FLOAT, INT32, and so on) occupy consecutive registers from the resolved starting address.
Data Types
string
required
The data type determines how raw register values are interpreted:
TAG Configuration
Complete TAG Parameters
TAG Parameters Reference
Address Configuration
Address Configuration
string
required
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.string
required
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.
Supported Operations
Query Parameters by Operation
To write a value on demand, publish a message to SOURCE_TOPIC. The route executes the write and publishes the result to DESTINATION_TOPIC:
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.

