MQTT vs. HTTP: Differences and Bridge Functionality
Advertisement
Introduction
IoT devices often rely on two protocols, MQTT and HTTP, to connect and communicate with IoT cloud cores. To facilitate this communication, devices require either an MQTT bridge or an HTTP bridge, a configuration set during device creation in the device registry. This article compares MQTT and HTTP, highlighting their differences and explaining the functionalities of MQTT and HTTP bridges.
What is MQTT Bridge?
MQTT (Message Queuing Telemetry Transport) is a standard publish/subscribe protocol commonly used by embedded devices and for general machine-to-machine (M2M) interactions. It maintains a persistent, full-duplex TCP connection.
Figure 1 illustrates a simple broker-based MQTT protocol architecture.
Key features of the MQTT protocol include:
- It operates over TCP.
- It uses SSL/TLS for security.
- It uses various messages like CONNECT, PUBLISH, SUBSCRIBE, and DISCONNECT.
- It uses Username/Password authentication in the ‘connect’ message.
- It encrypts the payload, meaning it is payload agnostic.
- It typically uses port 1883.
MQTT protocol benefits:
- Lower bandwidth usage.
- Low latency.
- High throughput.
- Support for raw binary data.
What is HTTP Bridge?
HTTP (Hypertext Transfer Protocol) is a connectionless protocol. The HTTP protocol sends requests and receives responses, without maintaining a continuous connection with the cloud core. The cloud core supports specific versions of the HTTP protocol.
Figure 2 shows an HTTP connection between a client (web user) and a web server.
HTTP uses standard IP headers for packet routing, and data isn’t encrypted before transmission.
Key features of the HTTP protocol include:
- It is lightweight.
- It presents fewer firewall issues.
- In HTTP, binary data must be base64 encoded, increasing CPU and network resource usage.
Tabular Comparison: MQTT vs. HTTP
Both MQTT and HTTP bridges utilize public key device authentication and JWTs (JSON Web Tokens). In MQTT, the JWT is transmitted in the “password” field of the “CONNECT” message, while in HTTP, it’s sent in the “Authorization” header of the “HTTP Request” message.
Both protocols push telemetry events to the cloud using a Publish/Subscribe mechanism.
The following table highlights the differences between MQTT and HTTP protocols:
Features | MQTT | HTTP |
---|---|---|
Full Form | Message Queue Telemetry Transport | Hyper Text Transfer Protocol |
Design Methodology | Data-centric | Document-centric |
Architecture | Publish/subscribe architecture | Request/response architecture |
Complexity | Simple | More complex |
Data security | YES | NO (HTTPS is used for security) |
Upper layer protocol | Runs over TCP | Runs over UDP |
Message size | Small, binary with 2-byte header | Large, ASCII format |
Device Connection Status | Reported | Not reported |
Service levels | 3 | 1 |
Libraries | 30KB C, 100KB Java | Large |
Port number | 1883 | 80 or 8080 |
Data distribution | 1 to 0/1/N | One to one |
Conclusion
When choosing between MQTT and HTTP, carefully consider the specific requirements of your IoT application.
MQTT is excellent for scenarios requiring low latency, minimal bandwidth, and reliable message delivery. This makes it ideal for IoT devices, sensors, and real-time applications. Its lightweight design and efficient use of network resources make MQTT the preferred choice for constrained environments.
HTTP, with its widespread adoption and simplicity, is better suited for web-based applications prioritizing robust data exchange and compatibility with existing web infrastructure. However, it may be less efficient in terms of bandwidth and power consumption, which are critical factors for IoT deployments.