8

I recently read a Quora question about whether CoAP or MQTT is more lightweight, but the answers don't seem particularly satisfying and all contradict each other: the top answer says MQTT takes fewer resources, and another below that says CoAP is less demanding.

From what I've found, it would make sense that CoAP would be less demanding than MQTT, since CoAP only requires UDP, and its messages are mainly fire-and-forget, unlike MQTT which functions over TCP (and hence would be much more involved).

Which protocol requires the least resources to function?


By resources, I'm primarily thinking of required processor power, RAM and data to be transmitted. For example, in the Quora question I linked, the top answer points out that a simple ESP8266 chip could run MQTT, which only has a 80MHz processor and less than 1MB of RAM. I'm curious as to whether CoAP could run on something like this, or an even more constrained environment.

The sort of use case I'm envisaging is where the device would mostly be receiving data from another device (e.g. commands to switch on/off), but may need to infrequently (perhaps a few times an hour) send updates with the device's status. I'd like to use as little processing power as possible to reduce device costs, and transmit relatively infrequency to reduce power usage as much as possible.

4
  • 1
    To avoid apples and oranges comparisons it would be useful if you could lay out a very, very specific use case. What task would you like to use as a basis for comparison?
    – goobering
    Jan 16, 2017 at 18:04
  • @goobering I've edited with some more info about a more concrete use case; let me know if you need anything more.
    – Aurora0001
    Jan 16, 2017 at 18:11
  • At the server/hub, or the endpoint? Your example device seems way over-spec for a constrained endpoint. Jan 16, 2017 at 18:13
  • @SeanHoulihane At the endpoint. The resources needed at the hub aren't so much of a factor in my question; just aiming to minimise the endpoint resources.
    – Aurora0001
    Jan 16, 2017 at 18:15

2 Answers 2

7

CoAP and MQTT have both equal RAM usage, measured in 10kbits [1].

Difference is in cpu and network usage: [2]

Every client supports TCP and holds a connection open to the broker.

So, CoAP has fewer foot print and according to the whole use case (small data once in a while) it seems to be your best choice.

As you referred, CoAP uses UDP. It does not guarantee data delivery. Still it performs 'excellent' in lossy conditions, while MQTT is only 'good'. So, I would not worry much on that.

Sources:

[1] http://embedded-computing.com/articles/internet-things-requirements-protocols/

[2] http://www.altencalsoftlabs.com/blogs/2016/08/08/analyzing-mqtt-vs-coap/

2
  • Your reference doesn't appear to support your conclusion: “an additional 20 KB of flash and 8 KB of RAM to upgrade to TCP”. If you round to 10kbits, or even to 10kB, it does mean that the difference in RAM usage between CoAP and MQTT is non-negligible. May 27, 2017 at 20:14
  • Depends if TCP is a selection criteria. It opposes the normal case for the protocol, which is UDP. Taking CoAP almost means accepting UDP.
    – mico
    May 27, 2017 at 20:33
2

One of the answers above says that CoAP uses UDP and hence does not guarantee data delivery. This is not completely true. CoAP has a non-confirmed mode and a confirmed mode of sending messages. In confirmed mode, CoAP will do retries to try to ensure delivery. You can tune the timeout and retry attempt count. The non-confirmed mode does not retry and is the 'fire-and-forget' mode you mention above.

In terms of memory footprint, the code itself can take 5-200k depending on what library you use and what options you use. The runtime data use depends on what features you use such as confirmed mode, block transfer, security, named resources, etc. For a tightly constrained trial, see https://www.mdpi.com/1424-8220/16/3/358 where the CoAP part of the code is about 5k !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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