Packages

Elixir library providing Bluetooth Low Energy (BLE) client functionality through a Rustler NIF. Uses the btleplug crate to scan for, connect to, and interact with BLE peripherals. POC basic functionality and only client (central) mode is supported resp. usable currently.

Current section

Files

Jump to
rustler_btleplug native btleplug_client src gatt_battery_characteristic.rs
Raw

native/btleplug_client/src/gatt_battery_characteristic.rs

use std::io;
use std::thread;
use std::time::Duration;
fn main() -> battery::Result<()> {
let manager = battery::Manager::new()?;
let mut battery = match manager.batteries()?.next() {
Some(Ok(battery)) => battery,
Some(Err(e)) => {
eprintln!("Unable to access battery information");
return Err(e);
}
None => {
eprintln!("Unable to find any batteries");
return Err(io::Error::from(io::ErrorKind::NotFound).into());
}
};
loop {
println!("{:?}", battery);
thread::sleep(Duration::from_secs(1));
manager.refresh(&mut battery)?;
}
}