Skip to content

pkg/libcoap: Add in libcoap CoAP library support#19889

Open
mrdeep1 wants to merge 1 commit into
RIOT-OS:masterfrom
mrdeep1:libcoap_add
Open

pkg/libcoap: Add in libcoap CoAP library support#19889
mrdeep1 wants to merge 1 commit into
RIOT-OS:masterfrom
mrdeep1:libcoap_add

Conversation

@mrdeep1

@mrdeep1 mrdeep1 commented Aug 15, 2023

Copy link
Copy Markdown
Contributor

Contribution description

Adds in support for using the libcoap CoAP library with version 4.3.4, as per https://github.com/obgm/libcoap with documentation at https://libcoap.net/doc/reference/develop/ .

pkg/libcoap contains the information for the libcoap library to be included and built as appropriate.
examples/libcoap-client provides an example CoAP client.
examples/libcoap-server provides an example CoAP server.
pkg/Kconfig updated to include libcoap.

Testing procedure

test/pkg/libcoap provided which does a loop-back test with libcoap client logic sending request to libcoap server logic and sanity checks the response.

Issues/PRs references

None, other than adding in new functionality.

@github-actions github-actions Bot added Area: doc Area: Documentation Area: pkg Area: External package ports Area: examples Area: Example Applications Area: Kconfig Area: Kconfig integration labels Aug 15, 2023
@mrdeep1 mrdeep1 force-pushed the libcoap_add branch 2 times, most recently from 3dc435e to a04974a Compare August 18, 2023 13:49

@JKRhb JKRhb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of minor suggestions below to get rid of the warnings.

Comment thread examples/libcoap-client/client-coap.c Outdated
Comment thread examples/libcoap-client/client-coap.c Outdated
Comment thread examples/libcoap-server/server-coap.c Outdated
Comment thread examples/libcoap-server/server-coap.c Outdated
Comment thread examples/libcoap-server/server-coap.c Outdated
Comment thread examples/libcoap-server/server-coap.c Outdated
Comment thread examples/libcoap-server/server-coap.c Outdated
Comment thread examples/libcoap-server/server-coap.c Outdated
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Sep 7, 2023
@riot-ci

riot-ci commented Sep 7, 2023

Copy link
Copy Markdown

Murdock results

✔️ PASSED

4a73a8d pkg/libcoap: Add in libcoap CoAP library support

Success Failures Total Runtime
11166 0 11166 10m:37s

Artifacts

@mrdeep1 mrdeep1 force-pushed the libcoap_add branch 11 times, most recently from fd8dd7f to 0e71780 Compare September 9, 2023 16:38
@github-actions github-actions Bot added the Area: sys Area: System label Sep 10, 2023
@mrdeep1 mrdeep1 force-pushed the libcoap_add branch 6 times, most recently from a83ac87 to 53a12f4 Compare September 11, 2023 10:15
@mrdeep1 mrdeep1 force-pushed the libcoap_add branch 5 times, most recently from 2cebb3c to d1b223e Compare March 5, 2024 10:38
@miri64 miri64 requested a review from chrysn March 7, 2024 09:19
@miri64

miri64 commented Mar 7, 2024

Copy link
Copy Markdown
Member

@chrysn could you maybe have a look?

@mrdeep1 mrdeep1 force-pushed the libcoap_add branch 2 times, most recently from 239cd10 to f6e909c Compare May 9, 2024 12:54
@mrdeep1

mrdeep1 commented May 9, 2024

Copy link
Copy Markdown
Contributor Author

I guess I do not understand why the Murdock test build failed for libcoap - msb-430 is definitely defined in tests/pkg/libcoap/Makefile.ci as a BOARD_INSUFFICIENT_MEMORY entry. It appears that size_t in this case is only 2 bytes wide.

@maribu

maribu commented May 9, 2024

Copy link
Copy Markdown
Member

This is correct behavior. The BOARD_INSUFFICIENT_MEMORY is used to flag boards that have too little RAM and/or flash for the linking step to succeed. Hence, the CI will do all compilation steps (to still confirm that the code is otherwise valid and portable C code), but skip the final linking step.

We do have two platforms where size_t is 16 bits wide: AVR and MSP430.

Note that size_t is defined to be able to hold any array index for an in-memory C array. So it may even not be possible to cast any pointer to size_t and back without loosing information, as the address space may be larger than anything that can be stored in RAM in a contiguous fashion.

Hence, size_t is not a suitable type for lengths of files written to e.g. SD cards and transferred over network e.g. using CoAP blockwise transfers.

But given that this bug is likely upstream, you could just add FEATURES_REQUIRED_ANY += arch_32bit|arch_64bit to the Makefile.dep of the package and prevent it from being compiled on our 8 bit and 16 bit boards.

@mrdeep1

mrdeep1 commented May 9, 2024

Copy link
Copy Markdown
Contributor Author

Thanks for the information, It looks like only a compile issue in one place, which I will get fixed shortly.

@maribu

maribu commented May 9, 2024

Copy link
Copy Markdown
Member

I only took a quick peek, but this looks good to me. @chrysn might be interested in this, as this would also provide an alternative implementation of OSCORE.

One thing: Most (if not all) of the KConfig parts can be dropped now, (see https://forum.riot-os.org/t/last-chance-for-kconfig-dependency-modelling/4068 for details). Selection of modules and packages and the dependency resolution via KConfig has been removed from upstream; but you can still use KConfig to expose configuration knobs (such as buffer sizes, ports to listen on, etc.).

I can take an in-depth look tomorrow, if you think this is ready for review? Would be cool to get this back in :)

@mrdeep1

mrdeep1 commented May 9, 2024

Copy link
Copy Markdown
Contributor Author

I can take an in-depth look tomorrow, if you think this is ready for review?

I have just found an OSCORE issue that needs to get fixed. I will fix this and have everything pushed for Monday.

Most (if not all) of the KConfig parts can be dropped now

I will look at doing this, probably not by Monday though.

@mrdeep1

mrdeep1 commented May 9, 2024

Copy link
Copy Markdown
Contributor Author

I have just found an OSCORE issue that needs to get fixed. I will fix this and have everything pushed for Monday.

Just pushed the fix. Do you want all these commits squashed?

@maribu

maribu commented May 9, 2024

Copy link
Copy Markdown
Member

Just pushed the fix. Do you want all these commits squashed?

Do as you prefer. Some other maintainers are a bit picky about when to squash, but I only look at the diff to upstream (or to when I last checked). So as long as only I am reviewing, you can squash (or not squash) during the review as works best for you.

@mrdeep1

mrdeep1 commented Jun 6, 2024

Copy link
Copy Markdown
Contributor Author

@maribu I have just pushed libcoap v4.3.5rc1 for review.

I have left in the Kconfig stuff for now - certainly users can just modify app.config to get the same results for configuring things.

@Ivrawn1109

Copy link
Copy Markdown

Hi, I may have found a bug (or an issue easy to solve).

I was able to flash both examples for RIOT successfully, each one on a nRF52840DK console. Having libCoAP server started in a Pyterm console:

coaps start
INFO Server IP [fe80::64b3:7881:5633:4d32]
INFO libcoap server ready

While the libCoAP client is activated on another console. 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

I don’t know why the URI is not being submitted. This format doesn't work as well: coap://[ip]/time?ticks coap://[ip]/.well-known/core, which it’s specified in README.

Grateful for any clues!

@mrdeep1

mrdeep1 commented Apr 13, 2025

Copy link
Copy Markdown
Contributor Author

@Ivrawn1109

Looks like this change is needed - I will get it fixed

diff --git a/examples/libcoap-client/client-coap.c b/examples/libcoap-client/client-coap.c
index bdf8db7151..f3a636ac90 100644
--- a/examples/libcoap-client/client-coap.c
+++ b/examples/libcoap-client/client-coap.c
@@ -219,7 +220,7 @@ client_coap_init(int argc, char **argv)
     }

     res = coap_uri_into_optlist(&uri, &dst, &optlist, 1);
-    if (res) {
+    if (res != 1) {
         coap_log_warn("Failed to create options\n");
         goto fail;
     }

@maribu

maribu commented Apr 14, 2025

Copy link
Copy Markdown
Member

It looks like something has gone wrong in the latest rebase, as unrelated commits are now showing up. Could you just do another rebase on top of master and see if that fixes the issue?

@mrdeep1

mrdeep1 commented Apr 14, 2025

Copy link
Copy Markdown
Contributor Author

Just pulled latest master and rebased my PR against it. git log --oneline master and git log --oneline libcoap_add is only showing 1 commit difference (the addition of libcoap_add).

I see that Murdock has a failure that needs to be fixed, which I will do now.

@crasbe crasbe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for picking up the PR again. Some things (style related) have changed since the original PR was submitted, so some updates and migrations have to be applied before merging.

The comments I gave are only exemplary, please adapt the remaining files yourself given the patterns.

Comment thread examples/networking/libcoap/libcoap_client/client_coap.c
Comment thread examples/networking/libcoap/libcoap_client/client_coap.c
Comment thread examples/networking/libcoap/libcoap_client/client_coap.h Outdated
Comment thread examples/networking/libcoap/libcoap_client/client_coap.h Outdated
Comment thread examples/networking/libcoap/libcoap_client/Kconfig Outdated
Comment thread examples/networking/libcoap/libcoap_client/main.c Outdated
Comment thread examples/networking/libcoap/libcoap_server/server_coap.c Outdated
Comment thread pkg/libcoap/Makefile Outdated
Comment thread pkg/libcoap/Makefile.libcoap Outdated
@mrdeep1

mrdeep1 commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

Is there a way to stop dist/tools/whitespacecheck/check.sh failing on a pkg .patch file where the external library follows a different coding standard, or the git diff adds a leading blank for a no change line?

As in

./dist/tools/whitespacecheck/check.sh x
  Command output:
  
  	pkg/libcoap/patches/0001-RIOT-Handle-ints-being-16-bits.patch:22: trailing whitespace.
  	+ 
  	pkg/libcoap/patches/0001-RIOT-Handle-ints-being-16-bits.patch:34: trailing whitespace.
  	+ 
  	pkg/libcoap/patches/0001-RIOT-Handle-ints-being-16-bits.patch:37: trailing whitespace.
  	+-- 
  	pkg/libcoap/patches/0001-RIOT-Handle-ints-being-16-bits.patch:39: new blank line at EOF.
  	ERROR: This change introduces new whitespace errors
  
  Error: trailing whitespace.
  Error: trailing whitespace.
  Error: trailing whitespace.
  Error: new blank line at EOF.

I have added pkg/*/patches/*.patch in dist/tools/whitespacecheck/ignore_list.txt for now. Doing this removes a significant number of warnings when just running dist/tools/whitespacecheck/check.sh with no parameter.

@Teufelchen1

Teufelchen1 commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

@crasbe seems to work fine.

@mrdeep1 Is it expected behavior that coapc does not respect interface ids? e.g. coap://[fe80::1%5]/
I also disliked that the coapc command is silent until timeout. This is an ux issue as someone not familiar with that tool will not understand what is going on while their riot node seemingly has frozen / became non-responsive. A little "trying coap get on " will be enough to fix that.

@mrdeep1

mrdeep1 commented Apr 22, 2026

Copy link
Copy Markdown
Contributor Author

@Teufelchen1

Is it expected behavior that coapc does not respect interface ids? e.g. coap://[fe80::1%5]/

This works for me provided the interface number is correct (was 5 also for me) and a valid IPv6 address is entered for where a server is running.

Brief Help documentation on usage has now been added to the client and server.

@crasbe crasbe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second (and last?) review round with more style related comments.

Comment thread examples/networking/libcoap/libcoap_client/Kconfig Outdated
Comment thread examples/networking/libcoap/libcoap_server/Kconfig Outdated
Comment thread examples/networking/libcoap/libcoap_client/client_coap.c Outdated
Comment thread tests/pkg/libcoap/libcoap-test.c Outdated
Comment thread examples/networking/libcoap/libcoap_client/main.c Outdated
Comment thread tests/pkg/libcoap/Kconfig Outdated
Comment thread tests/pkg/libcoap/libcoap-test.c
Comment thread tests/pkg/libcoap/libcoap-test.h Outdated
Comment thread tests/pkg/libcoap/main.c Outdated
Comment thread pkg/libcoap/Makefile.dep Outdated
libcoap version develop #244b0c2be4b3d30e62f0c13a51a845046b3e69ac

Using Sock interface.

examples/networking/libcoap Includes a CoAP client and CoAP server example.

tests/pkg/libcoap: Simple CoAP over DTLS loopback test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: doc Area: Documentation Area: examples Area: Example Applications Area: Kconfig Area: Kconfig integration Area: pkg Area: External package ports Area: tests Area: tests and testing framework CI: no fast fail don't abort PR build after first error CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants