All posts
opc-uamqttconnectivity

OPC UA vs MQTT: What Your Machine Really Needs

OPC UA vs MQTT from the PLC side: what your Siemens or Beckhoff PLC already has, when MQTT makes sense, and when the machine needs no changes.

A boxing ring in a plant with a packaging line: facing off in a friendly way, a blue figure made of light nodes, OPC UA, and a yellow one made of light capsules with an antenna, MQTT

OPC UA and MQTT do different jobs. OPC UA lets a client browse, read and subscribe to the data a machine exposes, with names and types. MQTT delivers messages through a broker and leaves the format of each message to whoever builds the system. In practice they work together: a gateway reads the PLC over OPC UA and publishes the values it needs to an MQTT broker.

Sooner or later a customer, or their IT team, asks the machine builder: “Can your machine send its data over MQTT?” The answer depends less on the protocols than on what your PLC¹ already has and on who will maintain the code afterwards.

What is the difference between OPC UA and MQTT?

OPC UA² is a standard from the OPC Foundation, also published as IEC³ 62541. A PLC with an OPC UA server exposes its data as nodes you can browse (Machine › Oven › Temperature), each with its name, its data type and, often, its engineering units. A client connects, browses and picks what it wants; it can also subscribe, so the server reports changes instead of being polled. The standard includes authentication, signing and encryption, which work when they are configured.

MQTT⁴ was created in 1999 to monitor oil pipelines over satellite links. Today it’s an OASIS standard (version 5.0 since 2019; 3.1.1 is also ISO/IEC 20922). Devices don’t talk to each other directly: they publish messages to a topic on a broker (plant1/line2/oven/temperature), and the clients subscribed to that topic, with permission to read it, receive them. The client opens the connection to the broker, and messages then flow both ways; if the broker is outside, nobody has to open a port into the plant. What MQTT doesn’t define is a data model: the topic names and the format of each message (often JSON⁵) are agreed for each project.

OPC UAMQTT
What it isA data model plus a way to communicateA way to deliver messages
How it talksClient and server (also publish-subscribe, see below)Publish and subscribe, through a broker
What the data looks likeVariables with name and type, often units, that you can browseTopics and payloads defined for each project
Finding out what data existsBrowse the serverNo standard way: you need the project’s documentation
Who starts the connectionThe client connects to the PLCThe device connects out to the broker
Where it fits bestInside the plant, for a SCADA⁶ or a gateway reading the PLCFrom the plant to the cloud, many devices, slow links
SecurityAuthentication, signing and encryption in the standard, once configuredTLS⁷ and broker authentication, set up per project

What does your PLC already have?

Most current PLCs already have an OPC UA server, in the CPU itself or through a module. MQTT is a different story:

PLCOPC UA serverMQTT
Siemens S7-1200 / S7-1500Built in (S7-1200 from firmware V4.4, S7-1500 from V2.0), with a runtime licenceSiemens LMQTT library, in the PLC program
Beckhoff TwinCAT 3TF6100 function, with its licenceTF6701 IoT Communication function
Rockwell ControlLogix 5580 / CompactLogix 5380Built in from firmware v36Not in the controller: separate software, such as FactoryTalk Optix
Schneider Modicon M241, M251, M262Built in (on the M580, with the BMENUA0100 module)Library in EcoStruxure Machine Expert; the M262 has it built in
Omron NJ/NX (NJ501, NX102, NX502, NX701)Built in, depending on the CPU versionOmron MQTT library (Sysmac Library)
Mitsubishi MELSEC iQ-R / iQ-FWith a module: RD81OPC96 (iQ-R) or FX5-OPC (iQ-F)iQ-F: FX5-ENET module
Panasonic FP seriesThrough its FP-I4C gateway, connected to the PLCThe same gateway

On Siemens, you enable the OPC UA server in TIA Portal, choose which variables to publish and download the project. On Beckhoff, the odd industrial PC with a real-time operating system doesn’t support the OPC UA server.

On almost all of them, publishing MQTT from the PLC takes a library, a function or a module. With Siemens’ MQTT client library or Beckhoff’s TF6701 IoT Communication function, for example, the job goes inside the PLC program: integrating the client block, building each message, loading the certificates, deciding the topics and the format, and testing what happens when the connection drops. In more than ten years programming machines with Siemens and Beckhoff, that’s where the cost turns up: the code has to be kept in every version of the machine’s program, and the next customer may ask for a different topic layout.

When is MQTT better than OPC UA?

MQTT fits when many devices publish to one broker or several applications need the same data, especially when it has to leave the plant:

  • From a gateway to the cloud. If the broker is outside, the gateway opens the connection from the plant, so no one has to open a port to come in.
  • Many devices sending data to one broker, such as a fleet of machines at different customers, or hundreds of sensors on a site.
  • Slow or unstable links, such as 4G or remote sites: messages can be very small, and the quality-of-service levels decide what is retried; what’s measured during an outage is only recovered if the gateway stores it.
  • Several systems that want the same data (a dashboard, a historian, the customer’s own software) without each one connecting to the PLC.

To read the PLC itself, inside the plant, OPC UA does the job better: the names and types are already there, and nobody has to agree on a message format first.

How do you send data over MQTT without touching the PLC?

If the PLC’s OPC UA server is already enabled and exposes the variables you need, a gateway in the plant can read them with no change to the PLC project, and send the data on over MQTT or whatever the destination uses. If the server has to be enabled or configured first, plan for a project download. Either way, the machine’s control logic stays as it is. That’s usually the quickest answer to “can your machine send MQTT?”: yes, through a gateway, without adding MQTT code to the PLC.

The same goes for equipment that only speaks Modbus, such as energy meters or compressors: the gateway reads it and puts the data next to the PLC’s. We compare those two in OPC UA vs Modbus TCP.

OPC UA or MQTT: which one should you use?

Your situationOur recommendation
Modern PLC with an OPC UA server (S7-1200, S7-1500, TwinCAT 3) and you want its dataRead it over OPC UA: check the licence and which variables it exposes. Don’t add MQTT to the PLC program just for this
The customer’s IT asks for MQTT to their brokerA gateway reads OPC UA and publishes to their broker. The control logic stays as it is
Data has to reach the cloudMQTT, or whatever the destination uses, from the gateway
A fleet of machines at different customersOne gateway per site that reads all its machines, and one common data format
No room for a gateway and the PLC must publish directlyMQTT in the PLC (Siemens library or TwinCAT TF6701), knowing it’s code you’ll maintain
Equipment with Modbus only (meters, auxiliary equipment)The gateway reads Modbus, alongside the PLC’s OPC UA

What is OPC UA over MQTT?

Strictly, it’s OPC UA PubSub (Part 14 of the standard) using an MQTT broker as its transport: the messages follow a format the standard defines, in JSON or in binary (UADP), and the metadata describing the data can be published separately. A gateway that reads an OPC UA server and publishes its own JSON is something else: a perfectly good OPC UA to MQTT integration, but not PubSub. And Sparkplug, from the Eclipse Foundation and published as ISO/IEC 20237, defines its own MQTT topics, payload and device state. Before you count on any of them, check that the publisher and the receiving system support the same one.

How we do it with coppioT

coppioT is engapplic’s no-code industrial IoT platform: it connects PLCs, energy meters and other equipment of any brand to the cloud, with no programming needed. It reads OPC UA and Modbus from the machine as it is, organises the data like your plant (Plant › Line › Machine), and your charts and reports live in Grafana or Power BI. You can see what the setup looks like in how it works.

If your customer asks for remote access as well as data, those are two different things: we explain why in remote machine monitoring vs remote access.

Frequently asked questions

Can OPC UA and MQTT work together?

Yes, and that’s the usual setup: OPC UA to read the PLC inside the plant, MQTT to carry the data from the gateway to the cloud. OPC UA PubSub can also travel over MQTT, if both ends support it.

Is MQTT still relevant?

Yes. It’s widely used to send device data to the cloud because it’s light and the connection goes out from the plant. What has changed is the standards built on top of it: OPC UA PubSub and Sparkplug, each in its own way, describe the data MQTT leaves undefined.

What are the disadvantages of MQTT?

It doesn’t describe the data: topics and formats have to be agreed and documented for each project. It depends on a broker, which someone has to run and secure. And on a PLC it means extra code to write and maintain.

Do I need to change my PLC program to publish over MQTT?

If the PLC has to publish MQTT itself, yes: you add the library or the TwinCAT function and program the messages. If a gateway reads the PLC over OPC UA and publishes the data, the control logic doesn’t change; at most, the OPC UA server is enabled and configured, and the project downloaded.

Does your customer ask for MQTT, OPC UA or “just the data”? Request a coppioT demo: complete the form, tell us which PLCs your machines have, and in 15 minutes we’ll show you how we would connect them.


Acronyms

¹ PLC (Programmable Logic Controller): the controller that runs the machine; for example, a Siemens S7 or a Beckhoff.

² OPC UA (Open Platform Communications Unified Architecture): an industrial standard to read data from a PLC or other device securely, with its name and type.

³ IEC (International Electrotechnical Commission): the international body that publishes electrical and electronic standards.

⁴ MQTT (Message Queuing Telemetry Transport): a lightweight protocol that sends messages through a broker; widely used to send device data to the cloud.

⁵ JSON (JavaScript Object Notation): a plain-text format for structured data, readable by people and by software.

⁶ SCADA (Supervisory Control and Data Acquisition): the system that displays and supervises the process in the plant.

⁷ TLS (Transport Layer Security): the encryption that protects the communication, the same one websites use with “https”.