Skip to main content

Modbus TCP Overview

The 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.
Modbus TCP is one of the most widely supported industrial protocols. If your device supports Modbus, this route provides a reliable way to integrate it with MQTT.

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.

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.

Data Types

string
required
The data type determines how raw register values are interpreted:

TAG Configuration

Complete TAG Parameters

TAG Parameters Reference

string
required
Register or coil address (numeric value). This is the zero-based address in the Modbus address space.
string
required
Type of Modbus address: HOLDING_REGISTER, INPUT_REGISTER, COIL, or DISCRETE_INPUT.
double
Multiplier applied to raw value. Default: 1.0. Example: Raw value 245 with SCALING 0.1 becomes 24.5.
double
Value added after scaling. Default: 0.0. Formula: result = (raw * scaling) + offset.
integer
Number of decimal places in published value. Default: 2.
double
Minimum allowed value. Values below this threshold are not published.
double
Maximum allowed value. Values above this threshold are not published.
double
Minimum change required to publish a new value. Default: 0.0.
string
Topic where PLC values are published. Subscribe here to receive sensor data.
string
Output format: VALUE_ONLY or JSON. Default: VALUE_ONLY.
string
Engineering unit for documentation (e.g., °C, bar, RPM).
string
Human-readable description of the TAG.
boolean
Allow writing to this register/coil. Default: false.
string
Topic to send write commands. Publish a value here to write it to the PLC.
string
Byte order for multi-byte values: BIGENDIAN or LITTLEENDIAN. Default: BIGENDIAN.
string
Word order for 32/64-bit values: BIGENDIAN or LITTLEENDIAN. Default: BIGENDIAN.
Different manufacturers use different byte/word ordering. If values appear incorrect, try changing BYTE_ORDER or WORD_ORDER.

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

The WITH 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

Read temperature and pressure from a Modbus device:

Troubleshooting

  • 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
  • Verify ADDRESS matches device documentation
  • Check BYTE_ORDER and WORD_ORDER settings
  • Confirm DATA_TYPE matches register size
  • Verify SCALING and OFFSET calculations
  • Ensure WRITABLE is set to “true”
  • Verify ADDRESS_TYPE is HOLDING_REGISTER or COIL
  • Check device permissions for write operations
  • Verify value is within MIN_VALUE and MAX_VALUE
  • 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

Connect to RS-232/RS-485 Modbus RTU devices.

Industrial Overview

Learn common patterns for all industrial routes.
Last modified on July 3, 2026