Files
client-rs/examples/ping.rs
T
swaits a7e93ab56b feat!: v0.2.0 — ping-on-connect validation, try_connect, publish polish
- Add ping-on-connect handshake: all connect functions validate the device
  within 200ms, rejecting non-DongLoRa serial devices immediately
- Add try_connect() — non-blocking connect that errors instead of blocking
  forever when no USB device is present
- Add payload size validation in transmit() (max 256 bytes)
- Add ErrorCode: impl std::error::Error
- Fix drain_rx error handling (no longer swallows original error)
- Fix repository URL to github.com/donglora/client-rs
- Remove wire-level tag constants from top-level re-exports
- Add rust-version (MSRV 1.85), homepage, exclude fields to Cargo.toml
- Add examples/ping.rs
- Allow clippy unwrap/expect in test modules
2026-04-07 15:52:37 -06:00

26 lines
689 B
Rust

//! Connect to a DongLoRa device, ping it, and print the MAC address.
//!
//! Run with: cargo run --example ping
use donglora_client::{RadioConfig, try_connect};
use std::time::Duration;
fn main() -> anyhow::Result<()> {
let mut client = try_connect(Duration::from_secs(2))?;
println!("connected!");
client.ping()?;
println!("ping ok");
let mac = client.get_mac()?;
println!("MAC: {:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
let config = client.get_config()?;
println!("current config: {config:?}");
client.set_config(RadioConfig::default())?;
println!("config set to defaults");
Ok(())
}