loader image

MQTT

MQTT MQTT is a lightweight, open publish-subscribe messaging protocol in which devices send messages to a central broker that distributes them to subscribers. It is widely used in IoT and IIoT, and in industry it is often combined with OPC UA, which adds a data model and semantics.

Context

MQTT is the messenger of the indus­trial internet of things. It moves data from sensors, gate­ways and PLCs to appli­ca­tions with very little over­head, over unre­li­able networks and at large scale. What MQTT does not do is describe what the data means. That is why the ques­tion “OPC UA vs MQTT” comes up in almost every IIoT archi­tec­ture, and why the best answer is often: OPC UA and MQTT together.

Essen­tials
  • What it is: a light­weight, open publish-subscribe messaging protocol for IoT and IIoT
  • Created: 1999 by Andy Stan­ford-Clark (IBM) and Arlen Nipper
  • Stan­dards: OASIS stan­dard (versions 3.1.1 and 5.0) and ISO/IEC 20922
  • Core concepts: broker, topics, three Quality of Service levels, retained messages and last will
  • In industry: often combined with OPC UA or Spark­plug B, which add struc­ture and seman­tics

What is MQTT?

The MQTT protocol is an open, event-driven commu­ni­ca­tion protocol based on publish-subscribe. A sensor, a gateway or a PLC (the publisher) sends messages to topics on a broker. Appli­ca­tions (subscribers) subscribe to the topics they care about, and the broker forwards matching messages. Publishers and subscribers do not need to know each other, which decou­ples the archi­tec­ture: a new appli­ca­tion can consume data without changing the device.

MQTT was created in 1999 by Andy Stan­ford-Clark of IBM and Arlen Nipper to monitor oil pipelines over satel­lite links. It is now an OASIS stan­dard, with versions 3.1.1 and 5.0, and an ISO/IEC stan­dard (ISO/IEC 20922). The name orig­i­nally came from MQ Telemetry Trans­port (some­times wrongly expanded as Message Queuing Telemetry Trans­port), but today it is used as a name, not an acronym.

How MQTT works

  • Broker: the central middle­ware that receives and distrib­utes all messages. Clients connect via TCP, usually on port 1883, or on port 8883 with TLS encryp­tion.
  • Topics: hier­ar­chical strings such as plant1/line2/press4/temperature that orga­nize the data.
  • Quality of Service: three levels, from “at most once” (QoS 0) to “exactly once” (QoS 2).
  • Retained messages and last will: new subscribers get the last value imme­di­ately, and a client can define a message that the broker sends if the client discon­nects unex­pect­edly.

The protocol is payload-agnostic: the message can be JSON, binary or anything else. This flex­i­bility is a strength and a weak­ness. Without agree­ments on the payload, every appli­ca­tion has to inter­pret every device’s data indi­vid­u­ally.

Spark­plug B: adding struc­ture to MQTT

Spark­plug B, an Eclipse Foun­da­tion spec­i­fi­ca­tion, addresses this gap for indus­trial use and is the basis of many unified name­space archi­tec­tures, in which all sensor data and machine data of a company is orga­nized in one topic struc­ture. It defines a topic name­space, a binary payload format and state manage­ment through birth and death certifi­cates, so that a SCADA system knows which devices are online and which metrics they provide. Spark­plug makes MQTT more inter­op­er­able, but it describes far less seman­tics than an OPC UA infor­ma­tion model or an Asset Admin­is­tra­tion Shell.

OPC UA vs MQTT: the key differ­ences

OPC UA vs MQTT is not a compar­ison of two equal tools. One is a full indus­trial automa­tion stan­dard with a data model, the other a lean trans­port. The table shows the ua vs mqtt differ­ences at a glance:

MQTTOPC UA
Commu­ni­ca­tion modelPublish-subscribe via a brokerClient-server, plus PubSub
Data modelNone, payload is free (Spark­plug adds basics)Rich infor­ma­tion model with types and seman­tics
Foot­printVery light­weightHeavier, scal­able from embedded to cloud
Secu­rityTLS and broker authen­ti­ca­tionBuilt-in certifi­cates, signing and encryp­tion
Typical useDevice-to-cloud, telemetry, event distri­b­u­tionMachine and controller inte­gra­tion, shop floor to MES
Stan­dardOASIS, ISO/IEC 20922IEC 62541, OPC Foun­da­tion

When should you use MQTT or OPC UA?

Use MQTT when many IoT devices and gate­ways send data to many consumers, when band­width is limited, or when data flows from the factory floor to cloud plat­forms, analytics and big data tools. Use OPC Unified Archi­tec­ture (often written OPC-UA) when appli­ca­tions need to browse a machine, read histor­ical data, under­stand its data model, call methods or commu­ni­cate securely with PLCs and controllers. In most manu­fac­turing facil­i­ties, both are present: the OPC UA protocol connects machines and SCADA systems on the shop floor, while MQTT distrib­utes data to MES, ERP and the cloud, for use cases from predic­tive main­te­nance to energy reporting.

Can MQTT and OPC UA be used together?

Yes, and that is the common archi­tec­ture today, because it lets compa­nies unify shop floor and cloud data without giving up seman­tics. OPC UA PubSub can use MQTT as its trans­port: messages keep the OPC UA infor­ma­tion model, while the MQTT broker handles distri­b­u­tion. Gate­ways also trans­late OPC UA servers into MQTT topics. The Open Industry 4.0 Alliance builds on this combi­na­tion. OEC compli­ance requires a secu­rity-enabled data bus based on MQTT, with data exchange between appli­ca­tions based on MQTT and OPC UA PubSub. In the Product Change Noti­fi­ca­tion demon­strator, an MQTT broker noti­fies subscribers when a supplier updates a submodel in an Asset Admin­is­tra­tion Shell, and the AAS-based onboarding project connects MQTT devices auto­mat­i­cally.

Frequently asked ques­tions

What does MQTT stand for?

MQTT orig­i­nally stood for MQ Telemetry Trans­port, named after IBM’s MQ product line. Today the stan­dard simply uses MQTT as its name.

OPC UA vs MQTT: which is better?

Neither is better in general. MQTT is lighter and ideal for distrib­uting data at scale, OPC UA brings seman­tics, secu­rity and a full infor­ma­tion model. Many archi­tec­tures use OPC UA on the shop floor and MQTT for the trans­port to the cloud.

Is MQTT secure?

MQTT supports TLS encryp­tion and authen­ti­ca­tion at the broker. Secu­rity depends on config­u­ra­tion, and brokers in indus­trial networks should never run without authen­ti­ca­tion.