Remove ble-server
This commit is contained in:
parent
82259615e2
commit
a8fd8107b3
|
@ -1,10 +0,0 @@
|
|||
[package]
|
||||
name = "ble-server"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
bluer = { version = "*", features = ["full"] }
|
||||
btleplug = "*"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
uuid = "*"
|
|
@ -1,73 +0,0 @@
|
|||
use btleplug::api::{
|
||||
bleuuid::uuid_from_u16, Central, Manager as _, Peripheral as _, ScanFilter, WriteType,
|
||||
};
|
||||
use btleplug::platform::{Adapter, Manager, Peripheral};
|
||||
use std::error::Error;
|
||||
use std::str::FromStr;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use tokio::time::{self, sleep};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let characteristic = Uuid::from_str("e54b0002-67f5-479e-8711-b3b99198ce6c").unwrap();
|
||||
let manager = Manager::new().await.unwrap();
|
||||
|
||||
// get the first bluetooth adapter
|
||||
let adapters = manager.adapters().await?;
|
||||
let central = adapters.into_iter().nth(0).unwrap();
|
||||
|
||||
// start scanning for devices
|
||||
central.start_scan(ScanFilter::default()).await?;
|
||||
// instead of waiting, you can use central.events() to get a stream which will
|
||||
// notify you of new devices, for an example of that see examples/event_driven_discovery.rs
|
||||
time::sleep(Duration::from_secs(5)).await;
|
||||
|
||||
// find the device we're interested in
|
||||
let handle = find_light(¢ral).await.unwrap();
|
||||
|
||||
println!("{:#?}", handle);
|
||||
|
||||
handle.connect().await?;
|
||||
|
||||
// connect to the device
|
||||
//light.connect().await?;
|
||||
|
||||
// discover services and characteristics
|
||||
handle.discover_services().await?;
|
||||
|
||||
// find the characteristic we want
|
||||
let chars = handle.characteristics();
|
||||
|
||||
println!("Characteristics: {:#?}", chars);
|
||||
|
||||
let light = chars.iter().find(|c| c.uuid == characteristic).unwrap();
|
||||
while true {
|
||||
handle
|
||||
.write(light, &[0x00], WriteType::WithoutResponse)
|
||||
.await
|
||||
.unwrap();
|
||||
sleep(Duration::new(2, 0)).await;
|
||||
}
|
||||
|
||||
handle.disconnect().await.unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn find_light(central: &Adapter) -> Option<Peripheral> {
|
||||
for p in central.peripherals().await.unwrap() {
|
||||
if p.properties()
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.local_name
|
||||
.iter()
|
||||
.any(|name| name.contains("RAK4630"))
|
||||
{
|
||||
return Some(p);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
Loading…
Reference in a new issue