The Internet of Things (IoT) is the technology that allows us to transmit data from and commands to smart devices in real-time. IoT is a network of devices connected via the Internet, with a hub that can analyze the aggregated data. The IoT endpoints can be a person, an animal, a home, a farm, a building, or a whole city. But in all cases, these things “talk” to each other without any human intervention via an IoT protocol.
There are different protocols for the different layers in an IoT architecture and in this paper, we take a look at just a few of them, including MQTT, HTTP and CoAP.
The popularity of IoT data transport protocol in 2018 (Source: t-mobile.com)
Message Queuing Telemetry Transport (MQTT)
What is MQTT?
MQTT is a machine-to-machine Internet of Things connectivity protocol.
The world of M2M (Machine to Machine)
It is a publish and subscribe system where we can publish and receive messages as a client. It makes it easy to communicate between multiple devices.
It is a simple messaging protocol designed for constrained devices and with low bandwidth, so it’s a perfect solution for Internet of Things applications.
It is an extremely lightweight and publish-subscribe messaging transport protocol. It is useful for the connection with the remote location where the bandwidth is a premium. These characteristics make it useful in various situations, including constant environments such as for communication machine to machine and Internet of Things contexts.
Characteristics of MQTT
The MQTT has some unique features which are hardly found in other protocols. Some of the features of an MQTT are given below:
It does not require that both the client and the server establish a connection at the same time.
It allows the clients to subscribe to a narrow selection of topics so that they can receive the information they are looking for.
It provides faster data transmission, like how WhatsApp/messenger provides faster delivery. It’s a real-time messaging protocol.
It is designed as a simple and lightweight messaging protocol that uses a publish/subscribe system to exchange information between the client and the server.
It is a machine-to-machine protocol, it provides communication between the devices.
MQTT architecture
To understand the MQTT architecture, we first look at the components of the MQTT: message, client, server and topic.
Message
The message is the data that is carried out by the protocol across the network for the application. When the message is transmitted over the network, then the message contains the following parameters:
Payload data
Quality of Service (QoS)
Collection of Properties
Topic Name
Client
In MQTT, the subscriber and publisher are the two roles of a client. The clients subscribe to the topics to publish and receive messages. In simple words, we can say that if any program or device uses an MQTT, then that device is referred to as a client. A device is a client if it opens the network connection to the server, publishes messages that other clients want to see, subscribes to the messages that it is interested in receiving, unsubscribes to the messages that it is not interested in receiving, and closes the network connection to the server.
In MQTT, the client performs two operations:
Example illustrating data retrieval and transmission (temperature) in MQTT
Publish: When the client sends the data to the server, then we call this operation a publish.
Subscribe: When the client receives the data from the server, then we call this operation a subscription.
Server
The device or a program that allows the client to publish the messages and subscribe to the messages. A server accepts the network connection from the client, accepts the messages from the client, processes the subscribe and unsubscribe requests, forwards the application messages to the client, and closes the network connection from the client.
Topic
The name of the Topic
The label provided to the message is checked against the subscription known by the server known as TOPIC.
MQTT applications
Facebook currently uses MQTT for its Messenger app, not only because the protocol conserves battery power during mobile phone-to-phone messaging, but also because the protocol enables messages to be delivered efficiently in milliseconds (ms), despite inconsistent internet connections across the globe.
Most major cloud services providers, including Amazon Web Services (AWS), Google Cloud, IBM Cloud and Microsoft Azure, support MQTT.
MQTT is well suited to applications using M2M and IoT devices for purposes such as real-time analytics, preventative maintenance and monitoring in environments, including smart homes, healthcare, logistics, industry and manufacturing
Advantages and disadvantages of the MQTT protocol
Advantages of MQTT protocol
Efficient data transmission and quick to implement due to its being a lightweight protocol;
Low network usage, due to minimizing data packets;
Efficient distribution of data;
Successful implementation of remote sensing and control;
Fast and efficient message delivery;
Usage of small amounts of power, which is good for the connected devices;
Reduction of network bandwidth
Disadvantages of the MQTT protocol
MQTT has slower transmit cycles compared to CoAP.
MQTT’s resource discovery works on flexible topic subscription, whereas CoAP uses a stable resource discovery system.
MQTT is unencrypted. Instead, it uses TLS (Transport Layer Security)/SSL (Secure Sockets Layer) for security encryption.
It is difficult to create a globally scalable MQTT network.
Hypertext Transfer Protocol (HTTP)
What is HTTP?
HTTP stands for Hypertext Transfer Protocol, an application protocol for distributed, collaborative, hypermedia information systems that allow users to communicate data on the World Wide Web. Example: http://www………: URL beginning with HTTP scheme.
To be more specific, HTTP is a stateless request/response protocol where clients request information from a server and the server responds to these requests accordingly (each request is independent of the other). It allows the fetching of resources, such as HTML documents.
HTTP request/response pattern
What is the purpose of HTTP?
HTTP was invented alongside HTML to create the first interactive, text-based web browser: the original World Wide Web. Today, the protocol remains one of the primary means of using the Internet.
Data through the internet
How does HTTP work?
HTTP data rides above the TCP protocol, which guarantees the reliability of delivery, and breaks down large data requests and responses into network-manageable chunks.
This is how it works: at first, clients send an SYN packet to the server and then the web server will respond with an SYN-ACK packet to confirm the success of receiving. After which, the client again sends an ACK packet, concluding a connection establishment – this is also commonly referred to as a 3-way handshake. In addition, the client sends an HTTP request to the server for a resource and waits for it to respond to a request. Then the web server will process the request, find the resource and send the response to the client. If no more resources are required by the client, it sends a FIN packet to close the TCP connection.
HTTP applications
HTTP protocol is used to bootstrap the World Wide Web to transmit data in the form of text, audio, images, and video from the Web Server to the user’s web browser and vice versa. HTTP is currently the data transmission platform of today’s web browsing applications and is widely used in Internet of Things systems. Even though HTTP protocol has many disadvantages in transmitting data and is not as suitable as those proficient protocols such as MQTT, CoAP, and AMQP used for IoT, this protocol is still popular in the smart-home industry as well as many advanced microcontrollers and microprocessors.
For example, systems which are based on the new generation of raspberry pi use HTTP protocol to transmit data. Arduino also uses this protocol to communicate with other devices. Besides, there are 3 more new versions of HTTP which have manifested to compensate for the downsides of the old one and to be applied for particular situations.
Advantages and disadvantages of HTTP
Advantages of applying HTTP
Search capabilities: Although HTTP is a simple messaging protocol, it includes the ability to search a database with a single request. This allows the protocol to be used to carry out SQL searches and return results conveniently formatted in an HTML document.
Ease of programming: HTTP is coded in plain text and therefore is easier to follow and implement than protocols that make use of codes that require lookups. Data is formatted in lines of text and not as strings of variables or fields.
Security: HTTP 1.0 downloads each file over an independent connection and then closes the connection. So this reduces the risk of interception during transmission significantly
Disadvantages of applying HTTP protocol
Not suitable for small devices: As small devices, such as wireless sensors, do not require much interaction and consume very little power, HTTP is too heavy to be a good fit for these devices. An HTTP request requires a minimum of nine TCP packets, even more, when you consider packet loss from poor connectivity, and plain text headers can get very verbose.
Not designed for event-based communication: Most IoT applications are event-based. The sensor devices measure for some variables like temperature, and air quality and might need to take event-driven decisions like turning off a switch HTTP was designed for a request-response-based communication rather than an event-driven communication. Also, programming these event-based systems using HTTP protocol becomes a big challenge especially because of the limited computing resources on the sensor devices.
Real-time problem: After requesting a resource from the server, the client has to wait for the server to respond, leading to a slow transfer of data. IoT sensors are small devices with very limited computing resources and hence cannot work efficiently in a synchronous manner. All the widely used IOT protocols are based on asynchronous models.
Constrained Application Protocol (CoAP)
What is CoAP?
CoAP is a simple protocol with low overhead specifically designed for constrained devices (such as microcontrollers) and constrained networks. This protocol is used in M2M data exchange and is very similar to HTTP, even if there are important differences that we will discuss later.
CoAP has the following main features:
Constrained web protocol fulfilling M2M requirements.
Security binding to Datagram Transport Layer Security (DTLS).
Asynchronous message exchanges.
Low header overhead and parsing complexity.
URI and Content-type support.
Simple proxy and caching capabilities.
Optional resource discovery.
UDP (User Datagram Protocol) binding with optional reliability supporting unicast and multicast requests.
CoAP structure model
CoAP interactive model is similar to HTTP’s client/server model. CoAP employs a two layers structure. The bottom layer is a message layer that has been designed to deal with UDP and asynchronous switching. The request/response layer concerns communication methods and deals with request/response messages.
Abstract Layer of CoAP
CoAP messages model
Message Layer supports 4 types of messages: CON (Confirmable), NON (Non-confirmable), ACK (Acknowledgement), RST (Reset).
Reliable message transport: A CON message is retransmitted until the recipient sends an ACK message with the same message ID. Using default timeout and decreasing counting time exponentially when transmitting a CON message. If a recipient is not able to process a message, it responds by replacing the ACK message with an RST message.
Reliable message delivery
Unreliable message transport: A message that does not require reliable delivery, can be sent as a NON message. These are not acknowledged but still have a message ID for duplicate detection. Figure 3 shows unreliable message transport.
Unreliable message delivery
CoAP request/ response model
Piggy-backed: The request is sent using a CON or NON-message, and if immediately available, the response to a request carried in a CON message is carried in the resulting ACK message. For a successful response, ACK contains response messages (identified by using a token), for a failure response, ACK contains a failure response code.
Two GET requests with immediate responses, one successful, one not found
Separate response: If a server receives a CON message type message but is not able to respond to this request immediately, it will send an empty ACK message in case the client resends this message. When the server is ready to respond to this request, it will send a new CON message to the client and the client reply to a CON message with acknowledgement. The ACK message from the client is just to confirm the CON message from the server.
A GET request with a separate response
Advantages and disadvantages of CoAP
Advantages of CoAP protocol
It is a simple protocol and uses less overhead due to operation over UDP. It allows short wake-up times and long sleepy states. This helps in achieving long battery life for use in
It uses IPSEC (IP Security) or DTLS (Datagram Transport Layer Security) to provide secure communication.
Synchronous communication is not necessary for the CoAP protocol.
It has lower latency compared to HTTP.
It avoids unnecessary retransmissions so it consumes less power than HTTP.
CoAP protocol is used as the best protocol choice for home communication networks. It is used in information appliances, communication equipment and control equipment in smart home networks.
Disadvantages of CoAP protocol
CoAP is an unreliable protocol due to the use of UDP. Hence CoAP messages reach unordered or will get lost when they arrive at the destination
It acknowledges each receipt of the message and hence increases processing time. Moreover, it does not verify whether the received message has been decoded properly or not.
It is an unencrypted protocol like MQTT and uses DTLS to provide security at the cost of implementation overhead.
CoAP has communication issues for devices behind NAT (Network Address Translation).
CoAP application for Smart home
Information appliances, control equipment and communication equipment in Smart home networks have the characteristics of low-cost and lightweight. Thus, CoAP could be seen as the best protocol choice for home communication networks.
The smart home network provides controlling and monitoring energy for home devices. Energy control systems employ smart socket management and monitor power-consuming equipment to provide voltage, current and other energy information. It could realize accident warnings, remote control and dynamic energy saving. Every data collection node with a CoAP client could exchange information with other nodes. CoAP could be installed on LAN or the internet.
Unlike many wireless protocols for home automotive devices, CoAP is designed not constrained to a local network but to provide the fundamental basis of the web.
Energy control system
In system networking, data collection nodes consist of one proxy, smart socket and wireless data collection module. Energy information and environment information of equipment is collected by the smart socket and transported to a data collection module through a wireless channel, then sent serial data to a proxy to process and pack data. The control server analyzes all the data and stores it in a database. The system integrates the home network and the Internet, users can access the system webpage to remotely control switches, manage configuration, query energy consumption, etc.
SummaryCriteriaMQTTHTTPCoAPYear199919972010FormMessage Queue Telemetry TransportHypertext Transfer ProtocolConstrained Application ProtocolArchitectureClient/BrokerClient/ServerClient/ServerPatternPublish/SubscribeRequest/ResponseRequest/ResponseHeader Size2 ByteUndefined4 ByteMessage SizeSmall and Undefined (up to 256 MB maximum size)Large and Undefined (depends on the web server)Small and Undefined (normally small to fit in single IP datagram)Semantics/MethodsConnect, Disconnect, Publish, Subscribe, Unsubscribe, CloseGet, Post, Head, Put, Patch, Options, Connect, DeleteGet, Post, Put, DeleteCache and Proxy SupportPartialYesYesQuality of Services (QoS)/ReliabilityQoS 0 – At most once
(Fire and Forget)
QoS 1 – At least once
QoS 2 – Exactly onceLimited (via Transport Protocol – TCP)Confirmable Message (similar to At most once) or Non-confirmable (similar to At least once)Transport ProtocolTCPTCPUDP, (Stream Control Transmission Protocol)
SecurityTLS /SSLTLS/SSLDTLS, IPsecDefault Port1883/8883 (TLS/SSL)80/443 (TLS/SSL)5683 (UDP Port)Encoding FormatBinaryTextBinaryLicensing ModelOpen SourceFreeOpen SourceOrganizational SupportIBM, Facebook, Eurotech, Cisco, Red Hat, Software AG, Tibco, ITSO, M2Mi, Amazon Web Services (AWS), InduSoft, FioranoGlobal Web Protocol StandardLarge Web Community Support, Cisco, Contiki, Erika, IoTivity
Conclusion
In general, numerous different IoT protocols support the Internet of Things and HTTP, MQTT, and CoAP are the three main dominant protocols in the IOT market nowadays because of their superb benefits which we have already discussed above. However, it is noticeable that while the HTTP protocol is suitable for web browsing applications, the other two are more fitting for the IoT purposes such as real-time communication, preventative maintenance and monitoring in environments, including smart homes and the manufacturing industry.
Overall, what is important in applying the IoT technique is the awareness of the business’s requirements as well as the advantages and drawbacks of the protocols offered by the market, and the ability to choose to best suit specific cases. Thanks for reading this article. If you have any questions, feel free to contact us at email: info@daviteq.com
Comments