commit 1bc75b612368c9a5775f3d6c0fd303dfe01d5a00 from: Thomas Böhler date: Wed Nov 23 16:31:29 2022 UTC Various minor and unimportant changes commit - 67f022afe299e120ddc8c913c6d7d393d2f55534 commit + 1bc75b612368c9a5775f3d6c0fd303dfe01d5a00 blob - 517246328d0094049b939cf24fe1793eb882594b blob + 770261bf170a707ab5e159e26e1162e7b6ca73dd --- src/main.rs +++ src/main.rs @@ -7,10 +7,10 @@ use btleplug::platform::Manager; use uuid::Uuid; const ESP_MAC_ADDR: [u8; 6] = [0x60, 0x55, 0xf9, 0xc1, 0x1e, 0x2e]; -const SERVICE_UUID: uuid::Uuid = Uuid::from_u128(0x061f8f7050293e727e62a46aa61cda68); -const BUFFER_READY_UUID: uuid::Uuid = Uuid::from_u128(0x78844add576bb4cd3c40f1f3d536a38a); -const DATA_BUFFER_UUID: uuid::Uuid = Uuid::from_u128(0xb57fc8740ebd1d2695ae2d31db630a54); -const BUFFER_LEN_UUID: uuid::Uuid = Uuid::from_u128(0x3e0fb4716b176bbc63b82b70b6cf54dd); +const SERVICE_UUID: Uuid = Uuid::from_u128(0x061f8f7050293e727e62a46aa61cda68); +const BUFFER_READY_UUID: Uuid = Uuid::from_u128(0x78844add576bb4cd3c40f1f3d536a38a); +const DATA_BUFFER_UUID: Uuid = Uuid::from_u128(0xb57fc8740ebd1d2695ae2d31db630a54); +const BUFFER_LEN_UUID: Uuid = Uuid::from_u128(0x3e0fb4716b176bbc63b82b70b6cf54dd); const SERVICE_CHARACTERISTICS: [Uuid; 3] = [BUFFER_READY_UUID, DATA_BUFFER_UUID, BUFFER_LEN_UUID]; async fn find_device( @@ -68,7 +68,6 @@ async fn main() -> anyhow::Result<()> { let manager: Manager = Manager::new().await?; let adapter_list = manager.adapters().await?; - info!("adapters: {:?}", adapter_list); // TODO: only allow adapters that support BLE 5.0 or higher if adapter_list.is_empty() { @@ -93,6 +92,7 @@ async fn main() -> anyhow::Result<()> { Some(s) => s, None => anyhow::bail!("ESP doesn't provide service with UUID {:?}", SERVICE_UUID), }; + // TODO: assert DLE with length 251 // check if service has all the characteristics that are needed // not checking if they have the correct properties... @@ -125,19 +125,20 @@ async fn main() -> anyhow::Result<()> { .find(|c| c.uuid == DATA_BUFFER_UUID) .unwrap(); - // send around (512 byte * 8) * 512 iteration / (10^3) = 2097.152 kbit - for _ in 0..512 { + info!("Sending (512 byte * 8) * 1024 iterations / (10^3) = 4194.304 kbit"); + for _ in 0..1024 { let buffer: Vec = std::iter::repeat_with(rand::random) .take(buffer_len) .collect(); esp.write(data_buffer_char, &buffer, WriteType::WithoutResponse) .await?; - log::info!("Sending another {} bytes", buffer.len()); } info!("Done"); + tokio::time::sleep(std::time::Duration::from_secs(60)).await; esp.disconnect().await?; + info!("Disconnected"); Ok(()) }