forked from ariel-os/ariel-os
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(examples/coap): Split out minimal server example
- Loading branch information
Showing
8 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[package] | ||
name = "coap-server" | ||
version = "0.1.0" | ||
authors = ["Christian Amsüss <[email protected]>"] | ||
license.workspace = true | ||
edition.workspace = true | ||
publish = false | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
embassy-net = { workspace = true, features = ["udp"] } | ||
embassy-sync = { workspace = true } | ||
heapless = { workspace = true } | ||
ariel-os = { path = "../../src/ariel-os", features = [ | ||
"override-network-config", | ||
"coap", | ||
] } | ||
ariel-os-boards = { path = "../../src/ariel-os-boards" } | ||
coap-message = "0.3.2" | ||
coap-message-demos = { version = "0.4.0", default-features = false } | ||
coap-handler = "0.2.0" | ||
coap-handler-implementations = "0.5.0" | ||
|
||
static-alloc = { version = "0.2.5", features = ["polyfill"] } | ||
|
||
ariel-os-coap = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# coap server demo | ||
|
||
## About | ||
|
||
This application starts a minimal CoAP server. | ||
|
||
The server offers a single resource, `/hello`, which returns a friendly message. | ||
|
||
The default policy allows access to the resource, | ||
but clients can cryptographically verify that they are talking to the right server using its public key. | ||
Both the policy and the key are currently hard-coded; | ||
making the former configurable and the latter dynamic is work in progress. | ||
|
||
## Running | ||
|
||
* Run on any board with networking, eg. `laze build -b particle-xenon run`. | ||
* [Set up networking](../README.md). | ||
* Run `aiocoap-client` | ||
to list the resources of the device: | ||
|
||
```sh | ||
$ pipx install 'aiocoap[all]' | ||
$ aiocoap-client coap://10.42.0.61/.well-known/core --credentials client.diag | ||
# application/link-format content was re-formatted | ||
</hello> | ||
``` | ||
|
||
If you prefer not to install the CoAP client, you can | ||
replace any call to `aiocoap-client` with `pipx run --spec 'aiocoap[all]' aiocoap-client` instead. | ||
|
||
The output tells you there is a `/hello` resource, so read that next: | ||
|
||
```sh | ||
$ aiocoap-client coap://10.42.0.61/hello --credentials client.diag | ||
Hello from Ariel OS | ||
``` | ||
|
||
The argument `--credentials client.diag` tells the client to establish a secure connection. | ||
Without the argument, the requests come through just as well, | ||
but the client has no assurance on the server's identity. | ||
|
||
## Further references | ||
|
||
There is a [chapter in the book](https://ariel-os.github.io/ariel-os/dev/docs/book/tooling/coap.html) | ||
that describes more concepts and background. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{1: 2, -1: 1, -4: h'fb13adeb6518cee5f88417660841142e830a81fe334380a953406a1305e8706b'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"coap://10.42.0.61/*": { | ||
"edhoc-oscore": { | ||
"suite": 2, | ||
"method": 3, | ||
"own_cred_style": "by-value", | ||
/ From the server's point of view, this is unauthenticated; we could use any key pair, as long as we send it by value. / | ||
"own_cred": {14: {2: "", 8: {1: {1: 2, 2: h'2b', -1: 1, -2: h'ac75e9ece3e50bfc8ed60399889522405c47bf16df96660a41298cb4307f7eb6', -3: h'6e5de611388a4b8a8211334ac7d37ecb52a387d257e6db3c2a93df21ff3affc8'}}}}, | ||
"private_key_file": "client.cosekey", | ||
"peer_cred": {14: {2: "", 8: {1: {1: 2, 2: h'0a', -1: 1, -2: h'bbc34960526ea4d32e940cad2a234148ddc21791a12afbcbac93622046dd44f0', -3: h'4519e257236b2a0ce2023f0931f1f386ca7afda64fcde0108c224c51eabf6072'}}}}, | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apps: | ||
- name: coap-server | ||
env: | ||
global: | ||
CARGO_ENV: | ||
- CONFIG_ISR_STACKSIZE=16384 | ||
selects: | ||
- ?release | ||
- network | ||
- random | ||
conflicts: | ||
# see https://github.com/ariel-os/ariel-os/issues/418 | ||
- thumbv6m-none-eabi | ||
# no xtensa / riscv gcc on CI | ||
- xtensa | ||
- riscv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#![no_main] | ||
#![no_std] | ||
#![feature(impl_trait_in_assoc_type)] | ||
#![feature(used_with_arg)] | ||
|
||
// Due to mismatches between CoAP components, coapcore currently needs an allocator. This example | ||
// provides the one that can be made most easily. | ||
extern crate alloc; | ||
use static_alloc::Bump; | ||
#[global_allocator] | ||
static A: Bump<[u8; 1 << 16]> = Bump::uninit(); | ||
|
||
#[ariel_os::task(autostart)] | ||
async fn coap_run() { | ||
use coap_handler_implementations::{ | ||
new_dispatcher, HandlerBuilder, ReportingHandlerBuilder, SimpleRendered, | ||
}; | ||
|
||
let handler = new_dispatcher() | ||
// We offer a single resource: /hello, which response just with a text string. | ||
.at(&["hello"], SimpleRendered("Hello from Ariel OS")) | ||
.with_wkc(); | ||
|
||
ariel_os::coap::coap_run(handler).await; | ||
} | ||
|
||
// So far, this is necessary boiler plate; see ../../README.md#networking for details | ||
#[ariel_os::config(network)] | ||
fn network_config() -> embassy_net::Config { | ||
use embassy_net::Ipv4Address; | ||
|
||
embassy_net::Config::ipv4_static(embassy_net::StaticConfigV4 { | ||
address: embassy_net::Ipv4Cidr::new(Ipv4Address::new(10, 42, 0, 61), 24), | ||
dns_servers: heapless::Vec::new(), | ||
gateway: Some(Ipv4Address::new(10, 42, 0, 1)), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters