1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/examples/rust-gcoap
chrysn 86dc086379 rust: Bring lock files in sync with toml files
The riotmodules dependency was missed in bc8ec6d5, and while generally
it does not severly harm builds, it does harm builds riotdocker CI where
branches are switched, which is blocked by dirty files in the checkout.

The riot-wrappers version was missed when what is now 5e75f4bd was
rebased onto fdc4e11a.
2022-08-01 16:28:12 +02:00
..
src rust: Make examples / tests use any Rust RIOT modules 2022-07-10 21:27:13 +02:00
Cargo.lock rust: Bring lock files in sync with toml files 2022-08-01 16:28:12 +02:00
Cargo.toml rust: Make examples / tests use any Rust RIOT modules 2022-07-10 21:27:13 +02:00
Makefile rust: Explicitly select nightly 2022-06-22 12:07:45 +02:00
Makefile.ci examples/rust-gcoap: Increase gcoap stack 2022-03-08 12:27:40 +01:00
README.md examples: Add second Rust example (gcoap) 2021-12-16 13:29:30 +01:00
vfs.c examples: Add second Rust example (gcoap) 2021-12-16 13:29:30 +01:00

gcoap used with Rust

This is the advanced Rust example; see ../rust-hello-world/ for the basics.

In extension to the basic example, it shows:

  • C code can be mixed with Rust code easily; any C file is built and linked as in applications without Rust.

    While it's technically possible to have header files for that code, it is easier (and likewise often done in C applications) to just translate the entry function's signature manually, as is done with the do_vfs_init() function.

  • Code of Rust applications can be spread out into modules, even if it builds on RIOT components.

    The CoAP handler built in the main function combines generic CoAP components (from coap_message_demos) with RIOT specific components (from riot-coap-handler-demos).

  • Many features of RIOT are exposed to Rust through the riot-wrappers crate, which provides safe wrappers around RIOT structures.

    In this example, the abovementioned CoAP handler is run on the gcoap server, for which the wrappers provide adaptation to the platform independent handler interface.

    Then, ztimer is used to sleep until the network interfaces are expected to be ready.

    Finally, the available network interfaces are iterated over and queried for their IP addresses, which makes it easier (in absence of an interactive shell) to find which address CoAP requests can be directed at.

How to use

$ make all flash term
[...]
main(): This is RIOT! (Version: 2022.01-devel-560-g7f8ed-rust-application)
constfs mounted successfully
CoAP server ready; waiting for interfaces to settle before reporting addresses...
Active interface from PID KernelPID(6) ("gnrc_netdev_tap")
    Address fe80:0000:0000:0000:1234:56ff:fe78:90ab
    Address 2a02:0b18:c13b:8018:1234:56ff:fe78:90ab

Once that is ready, in a parallel shell, run:

$ aiocoap-client 'coap://[2a02:0b18:c13b:8018:1234:56ff:fe78:90ab]/.well-known/core'