Integrate libCoAP into RIOT

Hi everyone.

I’ve been taking a look at this blog (Respected Professor: A CoAP server for the riot operating system using libcoap) where an example of a libCoAP server in RIOT is used. Also, in the following libCoAP repository (libcoap/examples/riot/examples_libcoap_server at develop · obgm/libcoap · GitHub) there are similar client and server examples.

As the latest RIOT update doesn’t include pkg/libcoap I wonder which is the necessary setup in order to flash the libCoAP server illustrated in the blog. In this link I’ve found a version from 3 years ago (RIOT/pkg at f5b2c80bd68b6f3ddb9090405f589798975ab0e1 - RIOT - RIOT-OS git forge) with that package, but after making some proofs I don’t get to make the example work on a nRF52840DK board.

So I would be grateful to know some tips :slight_smile:

Hi,

libcoap got removed from RIOT in pkg/libcoap: remove by maribu · Pull Request #17163 · RIOT-OS/RIOT · GitHub as it had been unmaintained for 8 years at that point in time.

There is a open PR that would add it again in pkg/libcoap: Add in libcoap CoAP library support by mrdeep1 · Pull Request #19889 · RIOT-OS/RIOT · GitHub that you might want to check out.

Note: That PR is doing the work of porting a recent version of libcoap to RIOT. It is not a revert of the drop, but actually addressing the issue why libcoap was removed.

If you do not want to specifically libcoap but rather are interested in CoAP in general: There are three competing implementations already upstream:

  1. nanoCoAP small CoAP library
  2. GCoAP
  3. GitHub - 1248/microcoap: A small CoAP implementation for microcontrollers

Note that 1. and 2. are developed within the RIOT repo, so you need to use them using USEMODULE += nanocoap and USEMODULE += gcoap, while 3 is developed externally and only integrated into RIOT as package, so you need to use USEPKG += microcoap for that.

If you have interest in libcoap, maybe drop a friendly note in the PR. Knowing that a PR has users waiting for them can motivate both reviewers and contributors to prioritize a given PR :slight_smile:

Hi,

@Iotvan11 I have been developing a new unified and modular CoAP suite for RIOT: #20792 – Overhauled CoAP Stack and API. unicoap aims to solve many issues with nanoCoAP and GCoAP: a modular transport abstraction, more versatile functions for CoAP options, easier packet APIs, integrated block-wise transfer support, convenience functions, better documentation.

I will open a Pull Request this week.

1 Like

We still support microcoap :flushed:? It has been unmaintained for nearly a decade.

Yes. We even have the most recent version of it packaged! :rofl: (Which is 10 years old…)

But to be fair: That package is < 500 lines of codes. Software projects with a clearly defined and narrow scope as well as a low complexity just tend to be “finished” at some point. And the package did not cause any maintenance pain yet.

Hi Maribu, thanks for your answer! I’ll definitely look at that PR.

I have worked with GCoAP in recent tasks, so I was interested in taking a step further using libCoAP. I’ll check if I find microcoap to be useful, or else I’ll try to add libcoap manually as in the PR.

May I ask what you are trying to do that doesn’t work with nanoCoAP?

Hi. I just wanted to check CoAP connectivity between my PC and nrf52840DK board, that I have already done with gCoAP (and I assume nanoCoAP would work as well), but using libCoAP since it has built-in Oscore.

However, I haven’t found yet an older version of RIOT repository that haves the package libcoap and supports a libCoAP example nrf52840dk. For instance, I have had trouble in order to do makeusing 2018.01 or 2020.01 versions.

Hello again.

I was able to flash the examples for RIOT in obgm/libcoap successfully, but I have encountered an issue I didn’t face when using gcoap. Basically I have the libCoAP server starting on a Pyterm console:

coaps start
Jan 01 00:30:31.483 INFO Server IP [fe80::64b3:7881:5633:4d32]
Jan 01 00:30:31.489 INFO libcoap server ready

While the libCoAP client is activated on another console, and there is ping between them. But when I do the following request for resource time (which is defined in server-coap.c):

coapc coap://[fe8064b3:7881:5633:4d32]/time

I get…

WARN Failed to create options

And I don’t know why the URI is not being submitted. I have also proven with this format: coap://[ip]/time?ticks coap://[ip]/.well-known/core that it’s specified in README, same answer.

I would be grateful if anyone has an idea about what it can be happening :slight_smile:

I think this would be best if you could move this to the PR. This does sound like a bug to me, but probably something that can be fixes easily.

Btw: Have you seen net/unicoap: Unified and Modular CoAP stack: Parser and Message APIs (pt 1) by carl-tud · Pull Request #21390 · RIOT-OS/RIOT · GitHub ? While it is a new player, it does indeed look very promising IMHO.

Thanks. Regarding unicoap, at first glance it seems like something very complete and could certainly be up to date. I’ll have to watch how far it goes.