DongLoRa Rust Client
Async Rust client library for talking to a DongLoRa device, either
directly over USB serial or through a mux daemon. Speaks DongLoRa
Protocol v2 via the donglora-protocol crate.
Install
[]
= "1"
= { = "1", = ["rt-multi-thread", "macros"] }
Quick Start
use connect;
use ;
async
All connect functions automatically validate the device by pinging
it, so you get a clear error immediately if the port is not a real
DongLoRa.
What's in Here
src/dongle.rs: high-levelDongleAPI (connect, set_config, transmit, start_rx, next_rx, tx_with_retry).src/session.rs: reader task, tag-allocation, per-command response routing, async event fan-out.src/retry.rs:RetryPolicy+ randomized backoff forCHANNEL_BUSY/EBUSYperPROTOCOL.md §6.10.src/connect.rs: auto-detection pipeline (TCP mux env var, unix socket mux, direct USB serial).src/transport.rs: tokio transports (tokio-serialfor USB,tokio::net::{UnixStream, TcpStream}for mux).src/discovery.rs: USB VID:PID discovery + ping validation.src/errors.rs:ClientError/ClientResult<T>(thiserror-based taxonomy mirroring the Python client'sDongloraError).
Connection Priority
connect(None, timeout) tries these in order:
- TCP mux: via
DONGLORA_MUX_TCPenv var (host:port). - Unix socket mux:
$XDG_RUNTIME_DIR/donglora/mux.sockor/tmp/donglora-mux.sock. - Direct USB serial: auto-detects by VID:PID (CP210x, CH9102, CH340, FT232R bridge chips too).
Once a mux path wins, subsequent reconnects commit to that path and will not fall back to USB, preventing port-steal races during mux restart.
try_connect(timeout) returns an error immediately if no device is
found; connect blocks until one appears.
TX with Retry
use RetryPolicy;
let policy = default; // 3 attempts, 20-100 ms backoff, 500 ms cap
let outcome = dongle.tx_with_retry.await?;
println!;
Keepalive
A background task pings the device every 500 ms when the host has
been idle, tracking the 1 s inactivity window from PROTOCOL.md §3.4
with a 2x safety margin. Disable via ConnectOptions::keepalive(false)
if you want to manage liveness yourself.
License
MIT, see LICENSE.