Modbus Gateway Guide

Bring Modbus RTU / Modbus TCP devices into Virtuino Cloud — no native Modbus support needed, thanks to MQTT-to-Modbus gateways.

Virtuino Cloud does not speak Modbus directly. Instead, a small gateway device on your local network polls your Modbus equipment and republishes the values over MQTT — the same MQTT broker and topic format documented in our MQTT Connection Guide. To the platform, data coming from a Modbus gateway is indistinguishable from data coming from an ESP32 — it's just another MQTT publisher.

1How It Works

Most Modbus RTU devices live on an isolated RS-485 serial bus, and most Modbus TCP gateways sit behind your local router's firewall with no public IP — our cloud servers can't simply "dial in" to reach them. An MQTT-to-Modbus gateway solves this the other way around: it makes an outbound connection from your network to our broker, so no port-forwarding or exposing your equipment to the internet is required.

Modbus Devices
RTU (RS-485) or TCP
MQTT-Modbus Gateway
polls registers locally
cloud.virtuino.com
MQTT broker (outbound, TLS)
Your Dashboard
widgets update live
Why not connect Modbus TCP devices directly to the internet?
Modbus has no built-in authentication or encryption. Exposing a Modbus TCP gateway directly to the public internet (via port-forwarding) is a well-known security risk — it can be discovered and controlled by anyone who finds the open port. Always keep Modbus traffic local, and let a gateway relay it out over authenticated, encrypted MQTT instead.

2Gateway Connection Parameters

Configure your MQTT-to-Modbus gateway's MQTT client / MQTT publisher settings exactly as you would for any device connecting to Virtuino Cloud — see the full MQTT Connection Guide for details on every field. The essentials:

Parameter Value Notes
*Broker Host cloud.virtuino.com Same host for both plain and TLS connections
*Port 8883 TLS / SSL Recommended — most gateways support TLS out of the box. Use 1883 only for local testing.
*Username vr-abcd1234 Your Sub-account Key — found in Console → Keys & Sub Users
*Password your MQTT password Found in Console → Keys & Sub Users → MQTT Credentials
Client ID any name, e.g. modbus-gw-01 Any name you like, as long as no other connection on your account uses the same one — two connections with the same client ID keep kicking each other off. It is the name the gateway shows in My Virtuino World.

* Required field

3Mapping Modbus Registers to Topics

Most MQTT-Modbus gateways let you define, per register, which MQTT topic to publish or subscribe to. In Virtuino Cloud a topic is simply the name of a field — plc1/temperature is one field. There is nothing else to add to the topic; see Topic Structure for the full reference.

The field must exist first. Before mapping a register, create a Field with exactly that topic as its name in Console → Fields. It must match character for character. A message to a topic with no field is rejected — the Debug Monitor shows every rejected message and the reason.
Modbus addressModbus typeDirectionGateway actionTopic = field
30001 (temperature) Input register PLC → cloud Publish plc1/temperature
30002 (humidity) Input register PLC → cloud Publish plc1/humidity
40010 (setpoint) Holding register cloud → PLC Subscribe plc1/setpoint
00001 (relay) Coil cloud → PLC Subscribe plc1/relay1
Tip: start every topic of one PLC or gateway with the same prefix — plc1/…, boiler/…. The fields then sort together in the Console and in every field list, and the next PLC simply gets its own prefix.

Reading registers (PLC → cloud)

The gateway polls the register and publishes its value to the field's topic. The best payload is the plain value — 23.5, not {"value":23.5} — because it is stored exactly as it arrives.

Writing registers and coils (cloud → PLC)

For a register or coil the gateway must write — a setpoint, a relay — the gateway subscribes to the field's topic. Whenever a value is written to that field with Publish via MQTT on — by a dashboard widget, a rule, a script or a scheduler — the gateway receives it and writes it to the PLC.

4Choosing a Gateway

Any MQTT-to-Modbus gateway works, as long as it can publish/subscribe to a standard MQTT broker over TLS with username/password authentication. Common options:

Whichever option you choose, the connection to Virtuino Cloud is always the same: standard MQTT, TLS on port 8883, authenticated with your Sub-account Key and MQTT password, publishing and subscribing to the names of your fields.

5Troubleshooting

SymptomWhat to check
The gateway does not connect Host, port 8883 with TLS switched on in the gateway, username = Sub-account Key, MQTT password. Gateways that ask for a CA certificate need ISRG Root X1 (Let's Encrypt); no client certificate is needed. See the MQTT Connection Guide.
Connected, but no values appear Open the Debug Monitor. A rejected message shows the reason — usually a topic with no matching field, or a value longer than 512 characters sent to a historical field.
Values arrive but are 10× or 100× too large The register holds a scaled integer. Set the gateway's scale factor, or convert with a script (section 3).
A JSON text is stored instead of a number The gateway sends JSON. Set up a JSON Splitter, or switch the gateway to plain values if it can.
The PLC does not react to a dashboard button Publish via MQTT must be on in the widget; the gateway must subscribe to exactly the field's name, and accept a plain value.
The gateway keeps disconnecting Another connection on your account uses the same client ID. Give each gateway and board its own.