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.

Committer:
sam_grove
Date:
Thu Jan 09 16:43:18 2014 +0000
Revision:
2:a872df2e051e
Parent:
1:54fe327e5d0a
Child:
3:288b2baffd14
Update BLE API

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 0:395932faedf1 1 #include "mbed.h"
ktownsend 1:54fe327e5d0a 2 #include "UUID.h"
sam_grove 2:a872df2e051e 3 #include "nRF51822.h"
ktownsend 0:395932faedf1 4
ktownsend 0:395932faedf1 5 /* Radio HW */
sam_grove 2:a872df2e051e 6 nRF51822 radio(p9, p10, p30, p29); // tx, rx, rts, cts
ktownsend 0:395932faedf1 7
ktownsend 0:395932faedf1 8 int main(void)
ktownsend 0:395932faedf1 9 {
ktownsend 0:395932faedf1 10 GattService battService ( 0x180F );
ktownsend 0:395932faedf1 11 GattCharacteristic battLevel ( 0x2A19, 1, 1, BLE_GATT_CHAR_PROPERTIES_NOTIFY | BLE_GATT_CHAR_PROPERTIES_READ);
ktownsend 0:395932faedf1 12
ktownsend 0:395932faedf1 13 /* Make sure we get a clean start */
ktownsend 0:395932faedf1 14 radio.reset();
ktownsend 0:395932faedf1 15
ktownsend 0:395932faedf1 16 /* Add the characteristic to our service */
ktownsend 0:395932faedf1 17 battService.addCharacteristic(battLevel);
ktownsend 0:395932faedf1 18
ktownsend 0:395932faedf1 19 /* Pass the service into the radio */
ktownsend 0:395932faedf1 20 radio.addService(battService);
ktownsend 0:395932faedf1 21
ktownsend 0:395932faedf1 22 /* Configure the radio and start advertising with default values */
ktownsend 0:395932faedf1 23 /* Make sure you've added all of your services before calling this function! */
ktownsend 0:395932faedf1 24 radio.start();
ktownsend 0:395932faedf1 25
ktownsend 0:395932faedf1 26 /* Now that we're live, update the battery level characteristic */
ktownsend 0:395932faedf1 27 uint8_t batt = 72;
ktownsend 0:395932faedf1 28 radio.writeCharacteristic(battLevel.handle, (uint8_t*)&batt, sizeof(batt));
ktownsend 0:395932faedf1 29
ktownsend 0:395932faedf1 30 while(1);
ktownsend 0:395932faedf1 31 }