I'm working on a device that sense and collect information from the environment such as temperature, humidity, etc.
The device is not connected to any power source, but it has a battery, and a solar panel to charge it.
It's almost in a deep sleep state most of the time, and it only wake up when it need to sense and transfer data. This operation takes about 1-2 minutes, and then it goes to sleep again.
I'm not an expert in this area, but I think MQTT should be a good option if the device need to be accessible to receive messages from a topic all the time, but in my scenario it only read sensors, and send data to a server periodically.
Currently I'm sending the data through HTTP, but I'm wondering if it makes sense to implement MQTT? Should I get any advantage over HTTP for this scenario?
There is a rich literature around MQTT vs. HTTP which you should delve into for details, but here are some of the high points for your application.
MQTT
In summary, MQTT has many features which would seem to be perfect for your application. That said, you could likely replicate many of them using HTTP but it would require more work.
HTTP
Pretty much supported everywhere which ensures easier compatibility with firewalls. This could be important if you are deploying on networks you do not control.
It is a more common protocol so you (and your end users) may already feel comfortable with it. Similarly you may already understand the security model which would make it easier to secure.
There are some differences between different MQTT implementations which might cause difficulties (i.e I use Mosquitto and sometimes find it confusing when people talk about their HiveMQ setup). HTTP strikes me as more universal and has a much larger community of people available to help you.
So HTTP has some inherent disadvantages versus MQTT but it will get the job done and may be more practical if the specific features of MQTT don't appeal to you.
But really if this is a large-scale project it is worth trying both and running some benchmarks and tests in your particular application and environment. It wouldn't be hard to set up a test environment and get some metrics. If this is more of a hobby / one-off project then I would use whichever one you are more comfortable with or find more interesting.
Sources / Further Reading:
http://stephendnicholas.com/posts/power-profiling-mqtt-vs-https https://www.ibm.com/developerworks/community/blogs/sowhatfordevs/entry/using_mqtt_protocol_advantages_over_http_in_mobile_application_development5?lang=en https://medium.com/@shubhanshusingh/http-vs-mqtt-9008d448bf88 https://www.slideshare.net/paolopat/mqtt-iot-protocols-comparison https://mobilebit.wordpress.com/2013/05/03/rest-is-for-sleeping-mqtt-is-for-mobile/ http://bec-systems.com/site/1200/iot-protocols-mqtt-vs-coap-vs-http
We have tested MQTT vs HTTP(REST) over SSL from normal server and Raspberry Pi boards both from performance point of view and from energy consumption. The results depend on use-case and device where process is running.
Regarding your use case we have special test as well => delivering many messages (multiple probes) via HTTP, HTTP-batch or MQTT. The results are quite simple, 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With