Marcio Cunha

How to connect legacy PLCs to the cloud using MQTT brokers

Learn how to build a data bridging architecture between traditional programmable logic controllers and the cloud using the lightweight MQTT protocol for real-time telemetry.

Marcio Cunha•4 min
Also available in:PortuguêsEspañol
Summary
  • The bridge architecture translates closed industrial protocols into lightweight cloud packets.
  • Edge connectors read internal controller registers and publish them to structured topics.
  • Local buffering prevents data loss during temporary internet connection drops.
  • Security requires TLS encryption and strong digital certificates to shield industrial traffic.
  • Monitoring telemetry latency ensures critical decisions are made at the right time.

Why bridge the factory floor to the cloud?

Modern industries generate a massive amount of data every day. However, a large portion of this information remains locked inside old control cabinets, running on equipment that was never designed to communicate with the internet. In practice, this means engineers must walk up to the machine to read panels or extract data using USB drives, which delays decision-making. This is where real-time telemetry comes in, consisting of collecting sensor readings and motor states and sending them continuously to a central dashboard or cloud system.

To make this magic happen without having to discard legacy machinery, we use a data bridging architecture. This bridge acts as a universal translator: it communicates with the programmable logic controller, which is the rugged computer responsible for commanding conveyor belts, valves, and robots on the shop floor, and packs this information into a lightweight format that the cloud understands. Before starting any such project, however, it is essential to ensure that local readings are accurate, as explained in our guide on how to calibrate industrial sensors via Modbus in the field to prevent sending corrupted data to servers.

Understanding the role of the MQTT protocol in industry

When talking about sending data to the cloud, the traditional HTTP protocol we use to browse the web tends to be too heavy for industrial environments. It consumes too much bandwidth and requires equipment to wait for a long response with each transmission. In contrast, MQTT was designed for slow and unstable networks. It works like a topic-based community radio system, where a device publishes information, such as an oven temperature, and any interested system subscribes to that channel to receive the message instantly.

The heart of this communication is the broker, a central server that receives all messages published by controllers and distributes them to anyone listening, whether they are visualization dashboards, cloud databases, or artificial intelligence algorithms. In practice, the PLC does not need to know who will read the data; it simply drops the information into the correct topic and continues its control work. This separation ensures that a failure in a cloud analytics system never interferes with the physical and safe operation of the factory.

Building the bridge between the PLC and the Broker

To implement this architecture in practice, we usually install a small edge computer, such as an industrial Raspberry Pi or a dedicated gateway, close to the electrical panels. This gateway connects to the PLC's local network using traditional protocols, periodically reads memory registers, and translates these raw values into structured JSON messages. Furthermore, when the network suffers severe fluctuations, it is important to monitor infrastructure health to avoid packet loss, following the recommendations in unstable network? how to map packet loss and jitter in critical communication routes.

Below we present a functional Python example running on the edge gateway, which performs the simulated reading of a PLC's Modbus register and publishes the updated value to the local MQTT broker:

import time
import json
import paho.mqtt.client as mqtt

BROKER_HOST = '192.168.1.150'
BROKER_PORT = 1883
TOPIC = 'factory/line1/temperature'

client = mqtt.Client()
client.connect(BROKER_HOST, BROKER_PORT, 60)

print('Starting MQTT bridge for PLC...')
while True:
    # Simulating reading a PLC register
    current_temp = 75.4
    payload = json.dumps({'sensor': 'extruder_01', 'value': current_temp, 'timestamp': time.time()})
    
    client.publish(TOPIC, payload)
    print(f'Published data: {payload}')
    time.sleep(5)

Security and resilience challenges at the edge

Connecting industrial systems to the internet opens formidable doors for productivity, but it also creates security vulnerabilities that can paralyze an entire plant if not treated seriously. Therefore, we should never expose an MQTT broker directly to the public internet without barriers. The use of strong password authentication, strict permission controls by topics, and TLS encryption is mandatory to shield packets against interception along the way.

Another critical point is operational resilience. Industrial internet often drops at the most unexpected moments due to electromagnetic interference or network maintenance. To overcome this, the edge gateway must have temporary disk storage, called a local buffer. If the cloud connection drops, data continues to be recorded locally, and as soon as the link is re-established, the gateway flushes the accumulated queue in chronological order, ensuring no valuable history is lost.

Final thoughts on industrial telemetry

The integration between traditional PLCs and MQTT messaging platforms represents an elegant bridge between the physical world of automation and the flexibility of cloud analytics. By translating rigid protocols into lightweight, asynchronous messages, we manage to extract maximum performance from consolidated equipment without compromising its operational stability. With a well-planned architecture, robust security, and strategies to handle network failures, the factory floor ceases to be an isolated island and begins feeding the company's digital ecosystem with accurate, real-time data.