Skip to main content

Crate pamoja_coap

Crate pamoja_coap 

Source
Expand description

CoAP transport for the pamoja SDK.

CoapTransport implements the core [Transport] trait on top of the pure-Rust [coap_lite] message codec and a UDP socket, so an application can talk to constrained RESTful devices through the same protocol-agnostic surface it uses for every other transport.

CoAP is connectionless: connect binds a local UDP socket and points it at the server, then spawns a background task that decodes inbound datagrams. A send is a CoAP PUT to a resource path, and a subscribe registers an RFC 7641 observe on a resource so the server’s notifications are forwarded to an internal queue that recv drains.

Delivery follows the configured Reliability: Reliability::Confirmable messages are acknowledged with retransmission (at-least-once), while Reliability::NonConfirmable messages are fire-and-forget (at-most-once), which suits the cheapest, most power-constrained devices.

§Examples

use pamoja_core::Transport;
use pamoja_coap::{CoapConfig, CoapTransport};

let mut transport = CoapTransport::new(CoapConfig::new("localhost", 5683));
transport.connect().await?;
transport.subscribe("sensors/temperature").await?;
transport.send("actuators/valve", b"open").await?;

if let Some(message) = transport.recv().await? {
    println!("{}: {} bytes", message.topic, message.payload.len());
}

Structs§

CoapConfig
Connection settings for a CoapTransport.
CoapTransport
A CoAP client that implements the core [Transport] trait.
Message
A message received from an observed resource.

Enums§

Reliability
The delivery guarantee applied to published and subscribed messages.