OPC UA vs MQTT: architecture, data model and when to use each
Part of the OPC UA guide
OPC UA and MQTT solve different halves of the same problem. OPC UA is a client and server protocol with a built-in information model: a client connects to the device or server that owns the data and reads typed nodes from it. MQTT is a publish and subscribe transport: devices send messages to a broker under a topic name, and the broker forwards them to whoever subscribed, without knowing what the bytes mean. In the OPC UA vs MQTT comparison, the usual result is that plants use both, OPC UA to get data out of controllers and MQTT to move it between sites and applications.
This page is part of the OPC UA guide. MQTT itself is covered in the MQTT guide.
OPC UA vs MQTT at a glance
| OPC UA (client and server) | MQTT | |
|---|---|---|
| Standard | OPC Foundation, IEC 62541 | OASIS MQTT 3.1.1 and 5.0 |
| Pattern | Client connects to server; request and response, plus subscriptions | Clients connect to a broker; publish and subscribe |
| Who opens the connection | The data consumer, inbound to the data source | Both publisher and subscriber, outbound to the broker |
| Default ports | 4840 (opc.tcp) | 1883, and 8883 over TLS |
| Address of a value | NodeId in the server’s address space | Topic string chosen by the publisher |
| Payload | Defined: typed value, status code, timestamps | Not defined: any bytes, commonly JSON |
| Discovery | Browse the address space | None in the protocol; wildcard subscriptions show what is being published |
| Delivery | Monitored item queues, sequence numbers, Republish | QoS 0, 1 or 2 per message; retained messages |
| Source offline | Session and status codes report it | Will message, if the publisher set one |
| Writes and commands | Write and Call services with a per-node result | A message on a command topic; any reply is by convention |
| Security | Application certificates, signing and encryption, user tokens | TLS to the broker, user name and password or client certificates, broker access control per topic |
| Consumers per source | Limited by the server’s session count | Limited by the broker, not the device |
Architecture: who connects to whom
An OPC UA client connects to the server, which means toward the PLC. Each consumer holds its own session and its own subscriptions on that server. This is direct and needs no extra component, and it has two consequences. The server’s port has to be reachable from every consumer, so a consumer outside the plant needs an inbound path through the firewall. And each additional consumer is additional load on a controller that may accept only a few sessions.
In MQTT nothing connects to the device. The device, or a gateway beside it, opens one outbound connection to a broker and publishes. Consumers open their own connections to the broker and subscribe. A site firewall only has to allow outbound connections, the device serves one connection however many consumers there are, and a new consumer can be added without touching the device. The broker becomes a component that has to be run, secured and kept available.
Data model: nodes against topics
OPC UA defines what a value is. A read or a notification carries the value with its data type, a status code and a source timestamp, and the server’s address space describes how nodes relate, as the address space page explains. Two clients from different vendors interpret the same node the same way.
MQTT defines only the envelope. A topic is a string with levels separated by slashes, and a subscriber can use + for one level and # for the rest:
plant1/line3/filler/temperature a topic
plant1/line3/+/temperature every machine on line 3
plant1/# everything under plant1The payload is whatever the publisher sent. One device may publish 23.5, another this:
{ "value": 23.5, "unit": "degC", "ts": 1795269787250 }Both are valid MQTT. The topic structure, field names, units, timestamp format and the way bad quality is signalled all have to be agreed between publisher and subscriber outside the protocol.
Sparkplug B: a data model for MQTT
The Eclipse Sparkplug specification fills that gap for industrial use. It fixes three things on top of MQTT:
- A topic namespace:
spBv1.0/group_id/message_type/edge_node_id/device_id. - A payload format, encoded with Protocol Buffers, in which each metric has a name, a data type, a timestamp and a value.
- Session state. An edge node publishes a birth message (
NBIRTH, andDBIRTHfor each device) that lists every metric it will send, then data messages (NDATA,DDATA) with only the metrics that changed. Its MQTT Will message is a death message (NDEATH), so the broker announces the node as offline if the connection is lost.
With Sparkplug B, a subscriber learns what a node offers from its birth message and learns when its data is stale, which brings MQTT close to what an OPC UA subscription provides, while keeping the broker architecture.
OPC UA PubSub
The OPC UA specification has its own publish and subscribe model, Part 14, added alongside the client and server services. A publisher sends data set messages, built from the same typed values, either directly over UDP or through a broker using MQTT or AMQP, with a binary or a JSON encoding.
OPC UA PubSub over MQTT therefore exists as a third option: OPC UA’s data model on MQTT’s transport. Support is much less common in controllers than the client and server services, so check the specific device before designing around it. A server that offers opc.tcp on port 4840 does not necessarily offer PubSub.
Delivery and state
MQTT’s quality of service levels cover one hop each, publisher to broker and broker to subscriber: QoS 0 delivers at most once, QoS 1 at least once, QoS 2 exactly once. A retained message gives a new subscriber the last value on a topic immediately. Neither says anything about whether the value is still current, which is why the Will message and Sparkplug’s birth and death messages matter.
An OPC UA subscription numbers its notification messages. The client acknowledges them in its next Publish request and can call Republish for one it missed. The server sends keep-alive messages when nothing changes, so silence beyond the keep-alive period means the connection has failed. Each value also carries its own status, so a failed sensor behind a working connection is visible.
OPC UA vs MQTT: when to use each
Use OPC UA client and server when the consumer is on the same network as the controller, when it needs to browse and select tags, when it writes setpoints or calls methods and needs the result of each, and when the PLC already runs a server.
Use MQTT when data has to leave the site through a firewall that allows only outbound connections, when many applications consume the same data, when devices are on cellular or intermittent links, and when the sources are small devices that cannot host a server.
The common combination uses each where it fits. A gateway on the plant network is an OPC UA client to the PLCs, and the same gateway publishes outbound to a broker or a cloud platform. The PLC’s OPC UA port stays inside the plant, and nothing outside needs a path in.
One caution applies to both: neither a broker port nor an OPC UA port belongs on the open internet without authentication. The OPC UA security page covers the OPC UA side.
How ControlCom uses each
ControlCom Connect is the hosted platform, and the ControlCom Edge Server is the on-site component that talks to equipment. For OPC UA, the Edge Server is the client: it connects to the server’s endpoint, for example opc.tcp://192.168.1.100:4840, and reads the configured nodes into platform variables.
MQTT appears in two documented places. A device that you integrate yourself can publish straight to ControlCom Connect over MQTT, using the broker, port, topic and client ID shown for that device in the platform and one of two JSON payload formats. And the Edge Server has a SparkplugB Listener rule, which accepts inbound spBv1.0 messages from an external publisher on its local MQTT broker and routes their metrics to platform variables.
The OPC UA client documentation , the MQTT documentation and the SparkplugB Listener documentation describe each path, and the platform overview shows where the data goes next.
PLC nodes read over OPC UA, Sparkplug B metrics and devices that publish MQTT directly all become variables in one ControlCom Connect account.