An example of creating and updating a simple GATT Service using the BLE_API
Dependencies: BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1
This example creates and updates a standard Battery Level service, and a single GATT characteristic that contains the battery level.
Diff: main.cpp
- Revision:
- 13:60e095fe4b45
- Parent:
- 12:4024aa3f72b0
- Child:
- 14:39b4b11d9cf5
--- a/main.cpp Mon Dec 15 08:10:46 2014 +0000 +++ b/main.cpp Tue Dec 16 09:12:25 2014 +0000 @@ -45,14 +45,14 @@ ble.init(); ble.onDisconnection(disconnectionCallback); + BatteryService batteryService(ble, batteryLevel); + /* setup advertising */ ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.setAdvertisingInterval(Gap::MSEC_TO_ADVERTISEMENT_DURATION_UNITS(1000)); /* 1000ms; in multiples of 0.625ms. */ ble.startAdvertising(); - BatteryService batteryService(ble, batteryLevel); - while (true) { ble.waitForEvent(); // this will return upon any system event (such as an interrupt or a ticker wakeup)