diff options
author | Dario Nieuwenhuis <dirbaio@dirbaio.net> | 2020-09-14 23:00:09 +0200 |
---|---|---|
committer | Dario Nieuwenhuis <dirbaio@dirbaio.net> | 2020-09-14 23:00:09 +0200 |
commit | ee7a50f0e57815722800f03f558a9f4ce2afe495 (patch) | |
tree | 9ddf9c6bd95affbed2a23fc1088f7a5c9fae5755 /examples/src/bin/ble_bas_central.rs | |
parent | f04052bef3f17cd61392d83072babd2509da4ec5 (diff) | |
download | nrf-softdevice-ee7a50f0e57815722800f03f558a9f4ce2afe495.zip |
Add GATT write.
Diffstat (limited to 'examples/src/bin/ble_bas_central.rs')
-rw-r--r-- | examples/src/bin/ble_bas_central.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/examples/src/bin/ble_bas_central.rs b/examples/src/bin/ble_bas_central.rs index 0de50d6..184dda3 100644 --- a/examples/src/bin/ble_bas_central.rs +++ b/examples/src/bin/ble_bas_central.rs @@ -92,11 +92,25 @@ async fn ble_central_task(sd: &'static Softdevice) { client.battery_level_value_handle, client.battery_level_cccd_handle ); + // Read let buf = &mut [0; 16]; let len = gatt_client::read(&conn, client.battery_level_value_handle, buf) .await .dexpect(intern!("read")); + info!("read battery level: {:[u8]}", &buf[..len]); + + // Write, set it to 42 + buf[0] = 42; + gatt_client::write(&conn, client.battery_level_value_handle, &buf[..1]) + .await + .dexpect(intern!("write")); + info!("Wrote battery level!"); + // Read to check it's changed + let buf = &mut [0; 16]; + let len = gatt_client::read(&conn, client.battery_level_value_handle, buf) + .await + .dexpect(intern!("read")); info!("read battery level: {:[u8]}", &buf[..len]); } |