obgm / libcoap

A CoAP (RFC 7252) implementation in C
Other
802 stars 424 forks source link

Approach for support of No OS or FreeRTOS and No Sockets? #406

Open andygikling opened 5 years ago

andygikling commented 5 years ago

My silly platform uses a PIC32 and we don't have TCP/IP support currently built in. We currently run bare metal with no OS but FreeRTOS could be added.

Looking at the code, when a message gets to the bottom, for example, on its way out the door, we end up in coap_io.c -> coap_network_send. At that point the data hits POSIX/Win32 socket.

Can anyone help me think through a approach which would allow me to modify the library so that it only operates on coap frames as byte streams in and out. External code would manage the endpoint routing. Or is this a contrived idea due to tracking async/pending message from multiple sources? I'd like to use a Zigbee network with a serial stream to send and receive coap frames, so in this use case, I won't be wrapping the coap with UDP, rather I need to wrap it with a special frame my radio understands.

Also, quick question, I wanted to run this on a bare metal micrcontroller, I simply setup a server just like how the example server code shows, then I just call "coap_run_once" over and over correct?

If there's documentation about these ideas I haven't seen yet, please point me in that direction.

Any other guidance from the community would be much appreciated!

mrdeep1 commented 5 years ago

There is an abstraction layer where the variables network_send and network_read are set up in coap_new_context()

  c->network_send = coap_network_send;
  c->network_read = coap_network_read;

and then c->network_send and c->network_read should be used elsewhere in the code to call the underlying sockets logic. You will certainly need your own equivalent functions to coap_network_send() and coap_network_read() which need to be installed into the coap context.

In terms of the server - yes. "coap_run_once" is a confusing name, think of it as "coap_io_process".

andygikling commented 5 years ago

Thank you @mrdeep1. I'll try that out and get back to you.

ASL07 commented 5 years ago

@andygikling Could you share your progress on this with us, if you have made any?

I am also interested on porting the library to a bare metal ARM system, and possibly Arduino or FreeRTOS, but I have not been able to find find any documentation on how to port this library.

My application will handle the sending and reception of CoAP packets over UDP.

I will analyze the code and try the examples on the next couple of days, and I would appreciate if you can point me towards the main things that are OS dependent.

I have also been researching about alternative libraries but I found most of them too simple or poorly documented, eg:

https://github.com/1248/microcoap https://github.com/RIOT-Makers/YaCoAP https://github.com/darconeous/libnyoci https://github.com/staropram/cantcoap

Thanks in advance for your help!

andygikling commented 5 years ago

@ASL07

I haven't begun work on bringing up the library yet for my PIC32/FreeRTOS project. When I try it I'll post info about the method here.

I've personally used cantcoap, the name is funny because the library is full of bugs and memory leaks! Steer clear of that!

Also, a company I contract for has a very light weight and highly standards-compliant library they developed internally which they plan on open sourcing on Github in the next few weeks. PM me for more information.

ASL07 commented 5 years ago

@andygikling

Actually I am developing my own Coap parser after taking some ideas from cantcoap now. I will implement the network layer in my app.

I found it quite hard to decouple libcoap from BSD sockets, and I don't really want to include other libraries as lwIP as they would bloat my codebase too much, and also I would need to port lwIP to different mcus.

Our firmware is targeted towards low power IoT devices that just use a single UDP socket and communicate as a basic Coap client. So having to port all that code seems overkill.

The documentation is very scarce for both libcoap and lwIP. However, if I can get some help on that I might give it a try

ESP-IDF has a libcoap port for ESP32 devices here https://github.com/espressif/esp-idf/tree/master/components/coap

Also, a company I contract for has a very light weight and highly standards-compliant library they developed internally which they plan on open sourcing on Github in the next few weeks. PM me for more information.

This looks good, I'll send you a PM

andygikling commented 5 years ago

@ASL07 - Zepto has been working on a very simple CoAP server designed for microcontrollers.

It has just recently been open-sourced: https://github.com/zeptolife/zcoap-server

Let us know if you have any questions about how you might use this library on your micro.

In the meantime, I'm going to try using libcoap and zcoap on a PIC32 and I'll post back here my findings.

obgm commented 5 years ago

@andygikling Thank you, please keep us posted!