Skip to main content
Industrial automation · PLC to MQTT

Get PLC data to MQTT and the cloud, without touching the PLC program.

If your PLC speaks Modbus TCP or Modbus RTU, an AppBlocks gateway can poll its registers, scale the values, and publish them to any MQTT broker, an HTTP API, Azure IoT, or AppBlocks Cloud. The gateway is a separate device, and its logic is a flowchart your whole team can read.

What the gateway does

Everything between the register map and the broker.

Read any register

Coils, discrete inputs, holding and input registers, over Modbus TCP or RTU on RS-485 or RS-232.

Poll on your schedule

Fast tags every half second, slow ones every minute. Each poll is just a timer block.

Scale and filter at the edge

Turn raw counts into engineering units, and publish only when a value changes enough to matter.

Publish anywhere

Your MQTT broker, an HTTP endpoint, Azure IoT, or AppBlocks Cloud, from the same flow.

Secure transport

MQTT over TLS with QoS 0, 1, or 2, and HTTPS for API calls.

Write back when you choose

Subscribe to a topic and write setpoints to the PLC, with limits checked in the flow first.

How it works

A gateway is four or five blocks.

These sketches use real block names. Open the Designer and you’ll find each one in the palette.

Poll the PLC and publish

A timer sends a Modbus Request. When the PLC answers, On Modbus Response scales the value and publishes it. If the PLC stops answering, On Modbus Timeout lets you publish a status topic, so your dashboard knows the difference between zero and offline.

  • Modbus TCP on port 502, or RTU on a serial port
  • Function codes 01–06, 15, and 16
  • Poll several slaves on one RS-485 bus by address
Modbus master in the docs
On Time Periodevery 1 s
Modbus RequestPLC 192.168.1.10 · FC03 · 40001, 8 regs
On Modbus Response
Variable Set/Mathmotor_amps = value × 0.01
MQTT Publishsite/line2/motor_amps
AppBlocks Cloud Metricmotor_amps
On Modbus Timeout
MQTT Publishsite/line2/status = offline

Report by exception

Publishing every value every second is fine on a LAN and expensive on a cellular plan. Compare each reading with the last value sent, and publish only when it moves by more than a deadband you choose.

On Variable Changedtank_level
Variable Set/Mathdelta = tank_level − last_sent
IF Compound Conditiondelta > 2 OR delta < −2
yes
MQTT Publishsite/tank1/level
Variable Set/Mathlast_sent = tank_level

Send setpoints back to the PLC

Subscribe to a topic and write the value to a holding register. Check the range in the flow before it goes anywhere near the PLC, and log anything out of range. You decide which registers are writable; everything else stays read-only.

MQTT in AppBlocks
MQTT Subscribesite/line2/setpoint → setpoint
IF Compound Conditionsetpoint ≥ 20 AND setpoint ≤ 80
yes
Modbus RequestPLC · FC06 · 40101 = setpoint
no
Add to Event Logsetpoint rejected

One gateway, a whole panel

Modbus RTU puts up to 247 slaves on one RS-485 bus, so a single gateway can read the PLC, the energy meter, and the drives in the same cabinet. Each device gets its own polling schedule, and each Modbus Request names the slave address it’s meant for.

  • Fast tags every second, slow ones every minute
  • Slave addresses 1–247 on one bus
  • Handle the answers in On Modbus Response
On Time Periodevery 1 s
Modbus Requestslave 2 · VFD, pump 1
On Time Periodevery 1 s
Modbus Requestslave 3 · VFD, pump 2
On Time Periodevery 5 s
Modbus Requestslave 10 · PLC status
On Time Periodevery 60 s
Modbus Requestslave 1 · energy meter
FAQ

Questions, answered.

Do I need to change my PLC program?

Not if the data you want is already mapped to Modbus registers. If it isn’t, you enable the PLC’s Modbus server and map the tags once. After that, the gateway only reads, unless you choose to write setpoints.

My PLC uses PROFINET, EtherNet/IP, or S7. Will this work?

AppBlocks talks Modbus. Many PLC families offer Modbus TCP as a built-in feature or an add-on; for those that don’t, a Modbus protocol converter bridges the gap.

Which MQTT brokers are supported?

Standard MQTT brokers such as Mosquitto, HiveMQ, and EMQX, with username and password authentication, TLS on port 8883, and QoS 0, 1, or 2. Azure IoT has its own telemetry and command blocks. MQTT in AppBlocks.

Can I send data to a REST API or a historian instead?

Yes. The HTTP Request block calls any HTTP or HTTPS endpoint, so you can post readings to your own back end, an ERP, or a historian with an HTTP interface.

What hardware do I use for the gateway?

A Tibbo Project System device with an Ethernet port and an RS-485 module is the usual choice, in a DIN-rail enclosure. Add a 4G LTE module for sites without a network. AppBlocks also runs on Zephyr boards such as the ESP32. Supported boards.

White-glove onboarding included

Ready to build your first firmware?

Start free in your browser, follow the tutorials, or book a free one-on-one session. No board yet? We’ll demonstrate everything on ours.