Connecting the IoT: What is MQTT and How is it Different from CoAP?

By ·Categories: Industrial IoT, Tech Explained·Published On: July 11th, 2023·4.9 min read·

Every day, an increasing number of devices join the ever-growing internet of things (IoT). According to Statista, there are expected to be over 29 billion IoT-connected devices by 2030.

Getting those billions of devices to interact with each other is no small feat, especially when you consider the unique character of many IoT devices, which are often small, remotely deployed, and infrequently serviced. These devices are also often network-constrained and limited in both computing resources and power consumption. 

Any system designed to let IoT devices interact must be smart, efficient, and economical. Today, two widely adopted protocols address IoT data connectivity: Message Queuing Telemetry Transport (MQTT) and Constrained Application Protocol (CoAP). Let’s take a look at some of the strengths and weaknesses of each.

What is MQTT?

MQTT is a messaging protocol designed for lightweight machine-to-machine communication, and is largely considered to be the gold standard in IoT messaging protocols. Developed in 1999 by IBM to enable a supervisory control and data acquisition (SCADA) system for a remote pipeline project, MQTT has evolved into an open standard maintained by the OASIS standards body. MQTT follows a publish/subscribe message exchange pattern in which devices create topics at a central broker that client devices can then subscribe to. 

When a device sends a message related to a specified topic, the message is pushed to any client subscribed to it. The centralized broker architecture can simplify management, help ensure delivery, and ease the challenge of IoT devices communicating across firewalls. Running over TCP/IP, MQTT conversations can be secured using the same SSL/TLS scheme employed for websites, though it is considered too heavyweight for many constrained scenarios.

MQTT use cases

Originally developed for use in oil and gas applications, MQTT is now used in a wide variety of industries, all the way from manufacturing, smart cities, and agriculture, to more consumer-based applications like home automation and wearable smart devices. Some of the most common use cases for MQTT include:

  • Manufacturing: With bi-directional messaging support, MQTT enables communication from clients on the factory floor (such as equipment or a SCADA system) to the cloud, and enables that same communication from the cloud back down to the factory floor.
  • Connected cities: Smart cities utilize IoT devices to gather data that can help to improve things like public safety, transportation, and environmental impact. MQTT can be used to enable these devices to transmit data and communicate with each other.
  • Agriculture: With the growing need for scalability in the agricultural sector, more and more businesses are turning to IoT solutions over manual processes. Sensors in the field can automatically collect data (such as the soil’s PH and moisture levels, for example) and forward that information to the cloud using the MQTT protocol.
  • Home automation: With automated smart homes, users can utilize MQTT to communicate with devices such as thermostats, appliances, and security systems from the convenience of their phone.
  • Wearable smart devices: Because MQTT is designed for lightweight communication and features low power usage, it’s often used for wearable devices such as fitness trackers or smart watches.

What is CoAP?

CoAP is a newer standard developed by the IETF Constrained Resource Environments (CoRE) group, and is often described as a lightweight analog to HTTP. Highly scalable and interoperable with the RESTful protocol, CoAP trades off the transmission guarantees of TCP (used by MQTT) for the smaller packets and lower overhead of UDP. 

TCP (Transmission Control Protocol) is a connection-based protocol under the IP (Internet Protocol) suite. TCP is stream-oriented, and is one of the most commonly used protocols designed to transmit data over networks. UDP (User Datagram Protocol) is also a part of the IP suite, but unlike TCP, UDP is connectionless and packet-oriented.

CoAP employs a client-server model and request/response message pattern, where client devices send information requests directly to server devices, which then respond. Support for an Observer message pattern enables clients to receive an update whenever a requested state changes, for example a valve opening or closing, while confirmed message delivery provides some level of assurance under the connectionless UDP transport.

At the end of the day, the decision of what protocol to adopt depends entirely on the specifics of your particular device deployment. In some cases, the hub-and-spoke, brokered architecture of MQTT may offer advantages, while in others, the decentralized approach employed by CoAP may be best. In the same vein, CoAP’s UDP foundation is generally friendlier to battery-powered devices, while MQTT based on TCP can offer greater assurance of message delivery.

CoAP can also be used in some of the previously mentioned MQTT applications, such as in connected cities, agriculture, and wearables. Many of these applications utilize battery-powered sensors. With the low-power benefits of CoAP, these kinds of applications can benefit from CoAP and may allow for longer operation in the field vs. MQTT depending on the specifics of the deployment.

Here are some of the key distinctions between these two popular protocols at a glance.

CoAP vs MQTT

MQTT

CoAP

Established1999 (2013 OASIS standard)2014
Messaging PatternPublish/subscribe via message brokerRequest/response (client-server)
TransportTransmission Control Protocol (TCP)User Datagram Protocol (UDP)
SecuritySSL/TLS over TCPDTLS over UDP
StrengthsBroker architecture can simplify management; TCP and quality of service options enable robust message deliveryFast and efficient due to reliance on low-overhead UDP; RESTful model is welcoming to developers and provides for integrated resource discovery
ChallengesAlways-on TCP connections limit utility for low-power devices; SSL/TLS encryption a poor match for constrained clientsLacks the reliability and service guarantees of TCP-based MQTT

Regardless of whether you choose MQTT or CoAP IoT protocols, you’ll need the right hardware. Check out  our full line of versatile, highly reliable industrial PCs, ideally suited for IIoT deployments, and contact us today with any questions.

Note: This blog post was originally published November 7th, 2016. It was revised on July 11th, 2023.

Get the Latest Tech Updates

Subscribe to our newsletters to get updates from OnLogic delivered straight to your inbox. News and insights from our team of experts are just a click away. Hit the button to head to our subscription page.

Share

About the Author: Darek Fanton

Darek is the Communications Manager at OnLogic. His passion for both journalism and technology has led him from the newsrooms of local papers to the manufacturing floor of IBM. His background in news gathering has him always on the lookout for the latest in emerging tech and the best ways to share that information with readers. In addition to his affinity for words, Darek is a music lover, juggler and huge fan of terrible jokes.