CoAP

Hi ! To use CoAP in my R21 boards should I rite the code of socket programming (open a udp port ,etc) or just use the coap library and it takes care about the socket?

Thank you in advance!!!

Hi Illias,

There is an example of the use of microcoap [1] but it hasn't been updated with the new network stack so it might not work. No microcoap doesn't take care about socket so you have to register a new UDP socket which will be redirected to your microcoap handle function.

[1] https://github.com/RIOT-OS/applications/blob/master/microcoap/main.c

Hi Baptiste,

do you know if libcoap is working on the new stack?

Best,

Ilias

I didn't try it since it's big comparing to microcoap (because it implements both client and server). There is no example for libcoap so you will have to register an UDP socket to the new network stack as well. IMHO, if you don't need a CoAP client , you should use microcoap.

Baptiste

Hi Ilias,

To use CoAP in my R21 boards should I rite the code of socket programming (open a udp port ,etc) or just use the coap library and it takes care about the socket?

all the microcoap library does is create and parse payloads (CoAP packets), and it let's you register callback functions for each URI.

You have to handle all the networking stuff, i.e. sending and receiving UDP packets, yourself.

I'm currently working on the mostly absent documentation of microcoap, you can find it in this fork:

https://github.com/i2ot/microcoap

It's not finished yet, but it might help you. For the networking stuff on RIOT OS, check out

and

if you haven't already done so.

The example code Baptiste pointed you to is indeed out of date, but the CoAP parts in it are still correct and should work, so you'd just have to change the socket calls etc.

Regarding libcoap: It's a *lot* more code than microcoap, and yes, it does all the socket stuff for you. But its documentation, too, is pretty much nonexistent. Also, you'd probably have to port it to RIOT first, so I suggest you use microcoap for devices that will run RIOT OS.

If you run into problems with microcoap, feel free to send me an e-mail.

Best, Lennart

Hi Lennart,

Also, you'd probably have to port it to RIOT first

Just to let you know, libcoap has already been ported to RIOT (as a pkg as microcoap) [1] Yes it does network registering automatically but I don't if this port does it with the new network stack, need testing.

[1] https://github.com/RIOT-OS/RIOT/tree/master/pkg/libcoap

I am used to testing, It would be my pleasure.

Debugging since 2013 on android :slight_smile:

Hi, as libcoap uses POSIX sockets it should work without any porting effort to gnrc. But since the socket API does not support options at the moment, there might be some unexpected problems.

Cheers, Martine