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.

Aurora0001
  • 18,520
  • 13
  • 55
  • 169

2 Answers2

8

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/

mico
  • 4,351
  • 1
  • 18
  • 27
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 !

kalyanswaroop
  • 1,208
  • 5
  • 16