29

I am developing a device which makes temperature, humidity and mass measurements. Currently it uses HTTPS to upload data to a remote server. Now I know that there is a protocol called MQTT which is claimed to be the "protocol of Internet of Things".

In what case and why should I switch from HTTPS to MQTT?

27

MQTT is a "messenger" between devices:

  • your device measures at time T a temperature of X degrees
  • it connects (itself or via the zwave hub) to the MQTT broker
  • it create a message with the topic /domotics/myplace/mydevice/temperature
  • within the message it just puts X (as the "payload")

Elsewhere in your house:

  • your Raspberry Pi is connected to the MQTT broker (it can be the MQTT instance itself)
  • it subscribes to the topic /domotics/+/+/temperature to receive ALL temperature information from all the devices that use this topic format. See the MQTT spec for more information on MQTT topic wildcards (+ and #).
  • it will receive a message with the payload X and do whatever it wants !

Elsewhere in your house:

  • your computer is connected to the MQTT broker and subscribes to the topic /domotics/myplace/mydevice/# to get ALL the information from your device and log it
  • it will receive a message with the payload X and do whatever it wants !

MQTT is very useful to avoid putting web services and sockets all around your servers. Node-RED uses MQTT and Domoticz can be configured to get in and set out signals.

I personally use MQTT at my home to switch off computers: /house/computers/mycomputer payload: 0

  • Good point that I do not have to bother with sockets and other web services. – Bence Kaulics Dec 6 '16 at 18:54
  • Can you comment on the security aspects? Is traffic plaintext? – Mawg Dec 7 '16 at 11:34
  • 1
    Another answer says MQTT supports TLS ; iot.stackexchange.com/a/69/39 – Goufalite Dec 7 '16 at 12:06
19

MQ Telemetry Transport Protocol known as MQTT is designed for devices which run on low power and low bandwidth. It is a lightweight publish/subscribe messaging protocol which means any other device can subscribe to a particular topic.

HTTP/HTTPS is designed as a request-response protocol for client-server computing which never bother about power usage and has lot of data overhead.

Use MQTT if:

  • The device you are using is running on battery cell and you don't want to replace that every x number days (MQTT is optimized for battery usage while HTTP/S is not)
  • Need faster response
  • Need to have pub/sub mechanism ( If you want to push messages to many clients)
  • Need to send data reliably with different levels of QoS

Do MQTT offer as much security as HTTPS?

MQTT relies on TCP as transport protocol, which means by default the connection does not use an encrypted communication. To encrypt the whole MQTT communication, most many MQTT brokers – like HiveMQ – allow to use TLS instead of plain TCP.

Ref: HiveMQ

  • 1
    Do MQTT offers as much security as HTTPS? – Bence Kaulics Dec 6 '16 at 18:55
  • 2
    It could use SSL/TLS so it should be as secure as HTTPS. – Ghanima Dec 6 '16 at 18:59
  • 1
    Exactly as @Ghanima said, I updated the answer with reference article to check which talks about securing MQTT. – bravokeyl Dec 6 '16 at 19:00
11

MQTT (Message Queue Telemetry Transport) seems to be well suited for the proposed application.

It is lightweight both with respect to bandwidth (smallest packet size with a header of just 2 bytes) and client code footprint (enabling it to run on thin clients like the ESP8266, typical IoT client). Reduced transmitted data is beneficial to longer battery life for off-grid battery powered clients like sensors.

MQTT also offers simple methods (verbs) that suit IoT tasks well, like durable subscriptions that recover connections after unexpected client disconnections. Compared to HTTP/HTTPS it is also simpler to extract data from the package (no parser needed).

5

Here I wrote an article which shows and evolution in communications system we had in our project. It about micro-services, but you can consider any sensor to be micro-service with its job to gather and publish any kind of telemetry data.

So most important conclusion is that it is better to use MQTT when you just need to send event somewhere and you know nothing about recipient. And it's much better to use HTTP (usually REST) when you know something about recipient and need some response - e.g. in case of commands of whatever.

From traffic, CPU, memory and energy consumption perspectives MQTT and HTTP are basically the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.