IoT publish subscribe protocols vs RESTful HTTP

0 votes
I have an Arduino, which I'm using to send GPS coordinates every minute through HTTP POST request to REST API in the OpenShift on-premise PaaS and the data is then stored on a MySQL database. So, I wanted to know if the publish/subscribe protocols like XMPP or MQTT that are commonly used in IoT would better suit my needs rather than Restful HTTP? If yes, please do tell me why it is better and what exactly would be the advantages, like will I be saving a significant amount of battery on using these IoT protocols?

If I'm not wrong, according to these IoT protocols a machine would "publish" data to a broker and my app would "subscribe" to it. And, in the case of gathering data every minute in my app, I think I would need a CRON job that will subscribe to that data every minute. But, I'm not at all sure about it, can anyone also suggest how data gathering can be achieved?
Nov 19, 2018 in IoT (Internet of Things) by Bharani
• 4,660 points
1,450 views

1 answer to this question.

0 votes
At a small scale, i.e, with just a few sensors where they will have plenty of power (CPU and electrical), or say if the communication cost is low then you really don't need to use MQTT. But at larger scales, i.e, with many sensors where the power (CPU/electricity) is limited for them or let's say when the cost of communication is very high, then these IoT protocols like MQTT will make a difference by offering you all needed advantages. Also, you could implement MQTT with just a simple embedded CPU, whereas HTTP would be more complex to implement.

And, yes! You'll definitely save a considerable amount of battery power with MQTT compared to the 3G network as you'd have less protocol overhead from publishing MQTT data over a persisting TCP connection from MQTT client to broker than you'd have for every REST POST that usually needs you to establish an SSL connection, post data using the elaborate HTTP, and then, delete the SSL connection. And, since MQTT connection is inherently bidirectional, you'll natively have the ability to send commands to your sensors. But, for doing the same using REST/HTTP, you'll have to configure your server for long polling first.

Check out this comparison of long-polling HTTPS vs MQTT over SSL: http://stephendnicholas.com/posts/power-profiling-mqtt-vs-https.
It says here that 4.1% battery power was saved per day using MQTT in contrast to the slow-polling HTTPS. That means you do save significant battery energy. And, using MQTT, you'd also be able to send very small messages, i.e, just a few bytes of binary data, with low overhead. Whereas, using REST/HTTP wraps a lot of HTTP protocol around the data, with much higher overhead. Also, if you have many devices, the overhead bytes will add up, resulting in a lot more data to be sent, costing you more money. So, for large scales, using compact protocols like MQTT and designing your data transfers carefully will save you a lot of money.

When using MQTT, your app usually has a persistent subscription to topics and gets automatically notified of any updates. Now, to give you a summary every minute, your app saves all updates to, say, a database and report from that database. It is usually the same database where all your data is saved in and you can subscribe to wildcard topics, which means you design your topics to make sure that your app subscribes to only the required set of sensors and the broker sends data from all connected devices without needing your app to poll the sensors individually.
answered Nov 19, 2018 by DataKing99
• 8,250 points

Related Questions In IoT (Internet of Things)

0 votes
1 answer

What protocols are used for Long Distance Communication in IoT ?

Azure IoT Hub supports three protocols: AMQP, ...READ MORE

answered Sep 11, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
1,807 views
0 votes
1 answer
0 votes
1 answer

testing protocols using IoT simulation

To test and analyze any protocol information ...READ MORE

answered Sep 17, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
726 views
0 votes
1 answer

Difference between particle.publish event and particle.subscribe event in particle.cloud

Particle.publish() Publish an event through the Particle Cloud ...READ MORE

answered Sep 18, 2018 in IoT (Internet of Things) by anonymous2
• 4,240 points
1,557 views
0 votes
1 answer

How to add https security for Node js?

You need to add the key and cert to the createServer function. const options ...READ MORE

answered Aug 10, 2018 in Blockchain by digger
• 26,740 points
818 views
0 votes
1 answer

ESP8266: RTC vs HTTP request - Battery Consumption

A project I work on uses both ...READ MORE

answered Jan 23, 2019 in IoT (Internet of Things) by DataKing99
• 8,250 points
889 views
0 votes
1 answer

Autostart published Application on Windows 10 IoT

It can be done by making changes ...READ MORE

answered Jul 13, 2018 in IoT (Internet of Things) by DataKing99
• 8,250 points
1,799 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP