An MES is connected to a line’s PLC, then a historian, then energy monitoring software and finally a dashboard. Each opens its own OPC UA session, and each reads the same tags at different intervals. One day the PLC’s communication load rises, the HMI screens start lagging and nobody knows why. This is usually where the protocol debate begins.
OPC UA and MQTT are the two names that come up most often in this debate; however, they solve different problems. The choice is made according to which layer the data is used at and by which application.
OPC UA: the protocol that carries meaning
OPC UA is a standard developed for platform-independent data exchange between industrial devices and software (IEC 62541). Its greatest strength is the information model: data is presented not just as a number, but together with its unit, type, hierarchy and relationships. In addition, thanks to industry-specific common models (companion specifications), machines from different manufacturers can present data in a similar structure.
- Client–server model; receiving changing data via subscriptions
- Built-in security: certificate-based authentication, signing and encryption
- Support for writing and method calls as well as reading
- A built-in OPC UA server on many current PLCs and machines
In the field, OPC UA problems come from configuration, not from the protocol. The first is the security mode. During commissioning, security mode “None” is selected to get the connection working, and it stays that way when the project ends. Traffic is then unencrypted and the client is not authenticated. In production, at least “Sign”, and preferably “SignAndEncrypt”, should be used; client certificates should be added to the server’s trust list deliberately. When a certificate rejected error appears, enabling the “trust all certificates” option does not solve the problem; it switches security off.
The second problem is sampling and publishing intervals. In a subscription, the “sampling interval” determines how often the server checks the value, and the “publishing interval” how often notifications are sent to the client. Monitoring thousands of tags at 100 ms wastes PLC CPU and communication resources if 100 ms resolution is not really needed. For temperature data, the order of seconds is usually enough. Fast data is given to the signals that need to be fast.
MQTT: the lightweight distribution protocol
MQTT is a publish/subscribe protocol that works through a broker. The side producing data publishes a message to a topic; every interested system subscribes to that topic. Producer and consumer do not need to know each other.
- Efficient on low-bandwidth and intermittent connections
- Easily distributes one data source to many consumers (MES, dashboards, cloud)
- The structure of message content is not defined; meaning and naming are left to the project
- Specifications such as Sparkplug B provide a common data structure and state management on top of MQTT
If three concepts in MQTT are not set up correctly, data loss or wrong data is inevitable. The QoS level (0: at most once, 1: at least once, 2: exactly once) determines how a message is delivered between the client and the broker; it does not guarantee that a transaction will be written exactly once in the MES or ERP; with QoS 1 the same message may arrive twice, and the consumer must tolerate this. A retained message immediately gives a newly subscribing system the last value of the topic; if left on for the wrong topic, a value from days ago is read as if it were current. A Last Will message announces through the broker that a gateway whose connection dropped is “offline”. If this is not set up, the dashboard keeps showing the last value. The screen stays green while the line has stopped.
Sparkplug B was defined to close these gaps: it standardises device state with BIRTH and DEATH messages, naming with a fixed topic structure and data types with a binary (Protobuf) payload format. If the project will include gateways from several suppliers, considering Sparkplug B instead of free-form JSON prevents naming disputes later on.
Comparison
| Criterion | OPC UA | MQTT |
|---|---|---|
| Communication model | Client–server (also PubSub) | Publish–subscribe via a broker |
| Data model | Rich, standardised | Free-form; can be structured with Sparkplug B |
| Typical location | Machine and line level | Site, enterprise and cloud level |
| Scaling | Each client connects to the server | Adding consumers does not open new connections to the source |
| Security | Defined within the standard | Configured with TLS and broker authorisation |
The “PubSub” note in the table matters: the PubSub part of OPC UA defines carrying the OPC UA information model in publish–subscribe form over MQTT or UDP. So the two worlds are not closed to each other; however, PubSub support in field devices and software is still not as widespread as client–server. Verify it in the manufacturer’s documentation before buying.
Using them together: a typical architecture
A common and healthy structure looks like this: machines and PLCs connect via OPC UA (or their own protocols) to an edge gateway. The gateway normalises the data, places it in a topic hierarchy with meaningful names (e.g. site/line/machine/signal) and publishes it to the MQTT broker. MES, historian, dashboard and cloud services subscribe to the data they need from the broker. This way, the number of clients connecting to the PLC does not grow, and adding a new consumer does not require touching the production side.
Network levels also become clear in this architecture. The gateway sits on the OT side, close to the cell; the broker is usually located in the industrial DMZ. The connection direction is from OT to the DMZ: the gateway connects to the broker, and consumers on the IT side also connect to the broker. No IT system opens a session to the PLC. We described the boundaries of this structure in the article IT/OT network separation with the Purdue model.
Because the broker is a single point, it must be designed too: TLS (usually port 8883; unencrypted 1883 only in an isolated test environment), an identity per client, topic-based read/write permissions, and the gateway buffering data locally when the broker is unavailable (store and forward). Without a buffer, broker maintenance means a hole in the historian.
Questions for the choice
- How many systems will consume the data? If there are many consumers, MQTT makes distribution easier.
- Will commands or recipes be written to the machine? OPC UA is more suitable for such operations.
- Which protocols do the devices support? Older devices need a gateway.
- From which network level will the data leave? This must be planned together with the IT/OT boundary and DMZ design.
- Who owns the naming standard? Regardless of protocol, this is the hardest topic.
The last item is usually the last to be addressed. If “Hat2_Mak3_Temp”, “L2M3_Sicaklik” and “line02/machine03/temperature” describe the same signal, the consumer side struggles with mapping tables whatever the protocol. Put the topic hierarchy and tag naming rule in writing at the start of the project, and configure the gateway according to this rule. The primary sources for up-to-date documentation of the standards are the OPC Foundation and mqtt.org.
Frequently asked questions
Are OPC UA and MQTT competitors?
In most projects, they are complementary rather than competitors. OPC UA provides a meaningful data model on the machine and PLC side; MQTT is used to distribute this data lightly to many consumers.
What can be done to get data from old PLCs?
For devices without OPC UA or MQTT support, an edge gateway reads data using the PLC’s own protocol (e.g. S7, Modbus, EtherNet/IP) and exposes it as OPC UA or MQTT.
Is MQTT secure?
MQTT’s security depends on its configuration. Brokers set up without TLS encryption, client authentication and topic-based authorisation create risk.