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.
Revision 0:395932faedf1, committed 2014-01-09
- Comitter:
- ktownsend
- Date:
- Thu Jan 09 10:53:09 2014 +0000
- Child:
- 1:54fe327e5d0a
- Commit message:
- First commit
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BLE_API.lib Thu Jan 09 10:53:09 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#755b897a47b1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jan 09 10:53:09 2014 +0000 @@ -0,0 +1,31 @@ +#include "mbed.h" +#include "uuid.h" +#include "hw/nrf51822.h" + +/* Radio HW */ +nRF51822 radio; + +int main(void) +{ + GattService battService ( 0x180F ); + GattCharacteristic battLevel ( 0x2A19, 1, 1, BLE_GATT_CHAR_PROPERTIES_NOTIFY | BLE_GATT_CHAR_PROPERTIES_READ); + + /* Make sure we get a clean start */ + radio.reset(); + + /* Add the characteristic to our service */ + battService.addCharacteristic(battLevel); + + /* Pass the service into the radio */ + radio.addService(battService); + + /* Configure the radio and start advertising with default values */ + /* Make sure you've added all of your services before calling this function! */ + radio.start(); + + /* Now that we're live, update the battery level characteristic */ + uint8_t batt = 72; + radio.writeCharacteristic(battLevel.handle, (uint8_t*)&batt, sizeof(batt)); + + while(1); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Jan 09 10:53:09 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/dc225afb6914 \ No newline at end of file