Regular readers definitely noticed that in our IBM Watson IoT example codes for ESP32 Arduino, we have used both MQTT and HTTP. Also we talked about HTTP POST method. HTTP POST is easy, is not it? It is really easy to write code for Arduino to construct HTTP POST request. Because all of us more or less used with HTTP based API and cURL. It will appear that as MQTT is complex and HTTP is better to use. It is not that easy to decide!
If you see log of bandwidth consumption on IBM Watson IoT platform, it will be clear to you that MQTT is sucking more bandwidth with DHT11 sensor compared to HTTP. ESP32 with DHT11 will take just few days to end full quota of free tier of IBM Watson IoT platform! MQTT was designed to allow the client to be connected always providing a two way communication in client-server model.
HTTP transfers a large number of tiny packets. Protocol overhead of HTTP causes serious problems, such as consumption of network resources and large delays. Since HTTP is operated over TCP/IP, reliable communication is provided. MQTT provides three transfer modes based on the required reliability: QoS0 (Non assured transmission), QoS1 (Assured transmission), and QoS2 (Assured service on applications). QoS1 is similar to HTTP from a reliability point of view.
If you have possibility to send data in one HTTP request – it will be the best option. MQTT is on the second place and HTTP with per-message delivery is much less power efficient and slower then MQTT. Hence for things like button press notification like doorbell, HTTP POST request is easy and practical.
In case of MQTT, the initial connection setup increases the response time for sending single messages to the level that equals the response time of sending a single message over HTTP. In terms of data amount sent is even more significant for MQTT case, which is larger than for HTTP. But we can compress the size for MQTT with optional additional layer of compression. MQTT is not just easy! Of course MQTT is easier than HTTP but our basic examples with ESP32 not closest to “professional grade design”.