MQTT
MQTTBest for: Sensors that report often
- Connect, from Sensor
- 21 C, from Sensor
- 22 C, from Sensor
- Fan on, from Broker
Compare protocols
Best for: Sensors that report often
Best for: Devices that report now and then
MQTT keeps one connection open to a broker, and devices publish tiny messages to topics that other devices subscribe to, so updates are pushed at once. HTTP is request and response: a device must ask each time, with larger headers. MQTT suits sensors on weak links and batteries. HTTP suits occasional uploads and devices that talk to web APIs.
Tick everything that is true for you.
Your pick shows here
Tick one or more lines and we weigh them for you.
| What differs | MQTT | HTTP |
|---|---|---|
| Pattern | Publish and subscribe through a broker | Request and response, client to server |
| Smallest header | 2 bytes | Often hundreds of bytes |
| Connection | Kept open, with a keepalive ping | Opened for requests, reused with keep-alive |
| Server sends first | Yes, the broker pushes to subscribers | No, the client must ask or poll |
| Delivery options | QoS 0, 1 or 2 | One request, one response |
| Offline notice | Last Will message when a device drops | None built in |
| Ports | 1883, 8883 with TLS | 80, 443 with TLS |
| Standard | OASIS MQTT 3.1.1 and 5.0 | RFC 9110 |
Each page plays the real packets on a map, step by step, with every header explained.
Each line describes one of the two. Which one?
Question 1 of 8
Pattern
Publish and subscribe through a broker
For many small messages, yes. There is no new request each time and the header is tiny. For one big file, HTTP is just as good.
Yes, a broker. Devices never talk to each other directly. They publish to the broker, which sends each message to every subscriber of that topic.
Yes, through MQTT over WebSockets, which most brokers support.
Plain MQTT on port 1883 is not encrypted. Use port 8883 with TLS, plus usernames or client certificates.