Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples/gcoap-rust: Expose more functionality #20838

Merged
merged 9 commits into from
Oct 2, 2024

Conversation

chrysn
Copy link
Member

@chrysn chrysn commented Aug 27, 2024

Contribution description

The riot-coap-handler-demos has a few ready-made components that were not shown off in examples/rust-gcoap before. I think they are useful to have, as they point users to more example code and to things they can explore with safe Rust bindings. The added resources don't make the example's source code more complex (effectively they're all just adding a line), but obviously they increase code size.

Concretely, this exposes any board LEDs as individual resources (PUT CBOR values false or true, or POST (see maturity)), and also exposes /netif which roughly contains data from ifconfig (only MAC address and IP addresses so far).

Two non-src/lib.rs changes are an added note in the README on security (none is there, thus we only expose harmless things), updating various riot-wrappers related dependencies (so for example LEDs are properly wrapped in the first place), and a stack size increase.

The CoAP thread's stack size gets increased from 8k to 16k. This fixes an actual bug, where on the particle-xenon the stack usage of the /ps/ handler (that was already active) was around 11k. I've done some digging into it (with terrible methodology, a mix of interactive gdb, attempts to read the stack usage from a Python script in gdb, and eventually resorting to calling ps() over and over in various places because that's faster than breakpoints), and what I can tell so far is that it's not so much related to serialization (I've tried switching CBOR libraries but the effect was present but miniomal) but that a lot of stack is used already in request parsing. Clearly something to investigate further, but for now, easy to fix.

Testing procedure

  • Run the examples/rust-gcoap program and note the IP address it shows
  • pipx run --spec 'aiocoap[prettyprint]' aiocoap-client coap://[fe80::the-address-shown%relevant-netif]/.well-known/core (or just aiocoap-client if you have aiocoap installed) and from there interact with the other resources advertised

The prettyprinting will make sure you see the returned CBOR in a reasonable form; very recent (I think unpublished) versions even give you readable IP addesses such as this:

./aiocoap-client coap://'[fe80::a41b:b9ff:fe1f:0894%enxa61bb91f1494]'/netif
# CBOR message shown in Diagnostic Notation
[_ [6, h'a61bb91f0894', [54([ip'fe80::a41b:b9ff:fe1f:894', null, 6])]]]

(which would be a lot more readable even if tag 54's text notation had the capability of expressing zone identifiers).

Maturity

The LED resources are a bit weird so far in that toggling them requires sending a null value rather than an empty payload; I'd like to fix that before merging.

@github-actions github-actions bot added Area: doc Area: Documentation Area: examples Area: Example Applications labels Aug 27, 2024
@chrysn chrysn added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Aug 27, 2024
@riot-ci
Copy link

riot-ci commented Aug 27, 2024

Murdock results

✔️ PASSED

e94337b examples/rust-gcoap: Regenerate Makefile.ci

Success Failures Total Runtime
14 0 14 02m:24s

Artifacts

@chrysn chrysn force-pushed the rust-coap-expose-more branch 2 times, most recently from 20ac402 to 25fce0e Compare August 27, 2024 21:49
@chrysn chrysn force-pushed the rust-coap-expose-more branch from 25fce0e to 8aa3ede Compare August 29, 2024 14:56
@chrysn
Copy link
Member Author

chrysn commented Aug 29, 2024

LEDs can now be toggled with an empty POST, so the maturity concern there is done.

(Still doesn't say that all resource implementations are particularly high-quality -- but after all, this is a demo example).

@chrysn chrysn marked this pull request as ready for review August 29, 2024 14:59
@chrysn chrysn requested a review from jia200x as a code owner August 29, 2024 14:59
@chrysn
Copy link
Member Author

chrysn commented Aug 29, 2024

Before passing this will take another tour through generate-Makefile.ci, but I'd rather do that only after an initial review, because running that takes hours.

This updates riot-sys, riot-wrappers and the riot-example-modules in for
this example, as all those are needed for full LED exposure, as well as
coap-message-utils for better error responses. An update to
coap-handler-implementations enables the use of the latest
riot-examples-modules.
@chrysn chrysn force-pushed the rust-coap-expose-more branch from 8aa3ede to 84354ff Compare August 29, 2024 15:38
@Teufelchen1 Teufelchen1 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 5, 2024
@chrysn
Copy link
Member Author

chrysn commented Sep 16, 2024

I've taken the liberty to add a ping example.

@Teufelchen1, you may want to have fun with that from your console! Both ping and pinged are discoverable through CoAP if= properties, and while I make no promises on the textual format, the (anyway more-fun-because-it-has-more-data) CBOR that comes even with some documentation.

@chrysn chrysn force-pushed the rust-coap-expose-more branch from 26d29b0 to 8f5b48d Compare September 17, 2024 07:22
@chrysn
Copy link
Member Author

chrysn commented Sep 17, 2024

A new addition patches the try-lock crate to use its PR'd seanmonstar/try-lock#11 instead of its released version: as so often, armv6's lacking atomics bite and need a workaround.

Copy link
Contributor

@Teufelchen1 Teufelchen1 left a comment

Choose a reason for hiding this comment

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

Works on my nrf52840dk :)

chrysn added 3 commits October 2, 2024 13:25
This still leaves a comfortable 976 byte on the gcoap stack, and 812 on
main -- and makes the application fit on way more boards.
@chrysn
Copy link
Member Author

chrysn commented Oct 2, 2024

Thanks for the review, squashed.

@chrysn chrysn force-pushed the rust-coap-expose-more branch from 8aad919 to e94337b Compare October 2, 2024 11:25
@chrysn chrysn added this pull request to the merge queue Oct 2, 2024
Merged via the queue into RIOT-OS:master with commit 505433b Oct 2, 2024
25 checks passed
@chrysn chrysn deleted the rust-coap-expose-more branch October 2, 2024 11:51
@benpicco benpicco added this to the Release 2024.10 milestone Nov 27, 2024
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 CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants