An example of creating and updating a simple GATT Service using the BLE_API
Dependencies: BLE_API mbed nRF51822
Fork of BLE_BatteryLevel by
Revision 3:288b2baffd14, committed 2014-01-16
- Comitter:
- ktownsend
- Date:
- Thu Jan 16 22:31:47 2014 +0000
- Parent:
- 2:a872df2e051e
- Child:
- 4:5b64235d1b85
- Commit message:
- Updated to latest BLE_API version
Changed in this revision
| BLE_API.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/BLE_API.lib Thu Jan 09 16:43:18 2014 +0000 +++ b/BLE_API.lib Thu Jan 16 22:31:47 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#f6022fb90701 +http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#011e95ce78b8
--- a/main.cpp Thu Jan 09 16:43:18 2014 +0000
+++ b/main.cpp Thu Jan 16 22:31:47 2014 +0000
@@ -1,31 +1,31 @@
#include "mbed.h"
-#include "UUID.h"
-#include "nRF51822.h"
+#include "blecommon.h"
+#include "hw/nRF51822s/nRF51822s.h"
-/* Radio HW */
-nRF51822 radio(p9, p10, p30, p29); // tx, rx, rts, cts
+nRF51822s nrf ( p9, p10, p30, p29 ); /* (tx, rx, rts, cts) */
+GattService battService ( 0x180F );
+GattCharacteristic battLevel ( 0x2A19, 1, 1,
+ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY |
+ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ);
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();
+ /* Make sure we get a clean start */
+ nrf.reset();
/* Add the characteristic to our service */
battService.addCharacteristic(battLevel);
/* Pass the service into the radio */
- radio.addService(battService);
+ nrf.getGattServer().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();
+ nrf.getGap().startAdvertising();
/* Now that we're live, update the battery level characteristic */
uint8_t batt = 72;
- radio.writeCharacteristic(battLevel.handle, (uint8_t*)&batt, sizeof(batt));
+ nrf.getGattServer().updateValue(battLevel.handle, (uint8_t*)&batt, sizeof(batt));
while(1);
}
