What is the difference between HTTP and MQTT for IoT gateway protocol ?

- Jun 28, 2020-

In the IoT world, the typical network architecture is as follows. First, the terminal device or sensor collects signals or information. For devices that cannot access the Internet or intranet network, the sensor first sends the detected information to the IoT gateway, and then the gateway sends the information to the server; some devices have their own functions to access the network, such as mobile phones, which can be directly connected to the server.

 

Sometimes, in order to decompress the server, we can choose some lightweight communication protocols, such as MQTT instead of HTTP, so why choose MQTT instead of HTTP? Because the header of the HTTP protocol is relatively large, and every time data is sent, a packet is sent to connect/disconnect TCP, so the more data sent, the greater the total data traffic.

 

The header of MQTT is relatively small, and it can also send and receive the next data while maintaining the TCP connection, so it can suppress the total data traffic more than HTTP.

 

In addition, when using MQTT, one should also pay attention to that, while maintaining the TCP connection of MQTT, the data should be sent and received. Because MQTT reduces the amount of communication by maintaining a TCP connection, if you disconnect the TCP connection every time data communication is performed, MQTT will perform the connection and disconnection processing every time data is sent, just like HTTP, but the result will increase communications volume.