diff --git a/examples/apps/src/ble_bas_peripheral.rs b/examples/apps/src/ble_bas_peripheral.rs index 8373b381..7bf1b844 100644 --- a/examples/apps/src/ble_bas_peripheral.rs +++ b/examples/apps/src/ble_bas_peripheral.rs @@ -107,6 +107,7 @@ async fn advertise_task( let conn = advertiser.accept().await?; info!("[adv] connection established"); let mut tick: u8 = 0; + let level = server.battery_service.level; loop { match select(conn.next(), Timer::after(Duration::from_secs(2))).await { Either::First(event) => match event { @@ -114,7 +115,21 @@ async fn advertise_task( info!("[adv] disconnected: {:?}", reason); break; } - _ => {} + ConnectionEvent::Gatt { event, .. } => match event { + GattEvent::Read { value_handle } => { + if value_handle == level.handle { + let value = server.get(&level); + info!("[gatt] Read Event to Level Characteristic: {:?}", value); + } + }, + GattEvent::Write { value_handle } => { + if value_handle == level.handle { + let value = server.get(&level); + info!("[gatt] Write Event to Level Characteristic: {:?}", value); + } + }, + }, + }, Either::Second(_) => { tick = tick.wrapping_add(1); diff --git a/host/src/attribute.rs b/host/src/attribute.rs index 547ed7dc..64c4361b 100644 --- a/host/src/attribute.rs +++ b/host/src/attribute.rs @@ -656,7 +656,8 @@ impl<'r, 'd, M: RawMutex, const MAX: usize> Drop for ServiceBuilder<'r, 'd, M, M #[derive(Clone, Copy, Debug, PartialEq)] pub struct Characteristic { pub(crate) cccd_handle: Option, - pub(crate) handle: u16, + /// Handle value assigned to this characteristic when it is added to the Gatt Attribute Table + pub handle: u16, pub(crate) phantom: PhantomData, }