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 6724e851ca Rust: Update riot-wrappers
This fixes a regression by merging https://github.com/RIOT-OS/rust-riot-wrappers/pull/55
(the "G" unit has been deprecated, but that deprecation was done wrong
in https://github.com/RIOT-OS/rust-riot-wrappers/pull/50).
2023-04-25 09:20:58 +02:00
..
src rust: Make examples / tests use any Rust RIOT modules 2022-07-10 21:27:13 +02:00
Cargo.lock Rust: Update riot-wrappers 2023-04-25 09:20:58 +02:00
Cargo.toml Rust examples: Update coap-handler-implementations dependency 2023-04-24 11:41:13 +02:00
Makefile rust: Run all examples on stable 2022-11-24 11:07:45 +01:00
Makefile.ci examples/rust-gcoap: blacklist GD32V boards 2023-02-21 15:04:13 +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'