A template for applications where some small amount of data needs to be notified to a phone app over BLE. It is a good starting point for notifications.

Dependencies:   BLE_API mbed nRF51822

Demo for an Input Service

To help you create your own BLE services, we've created a series of service templates. The *input service template* demonstrates the use of a simple input (boolean values) from a read-only characteristic.

The template covers:

1. Setting up advertising and connection states.

2. Assigning UUIDs to the service and its characteristic.

3. Creating an input characteristic: read-only, boolean, with notifications. This characteristic is updated according to the button's state.

4. Constructing a service class and adding it to the BLE stack.

Revision:
6:18d8750f39ee
Parent:
1:7202df456146
--- a/ButtonService.h	Sat Jun 20 00:00:32 2015 +0000
+++ b/ButtonService.h	Sat Jun 20 23:52:29 2015 +0000
@@ -22,20 +22,20 @@
     const static uint16_t BUTTON_SERVICE_UUID              = 0xA000;
     const static uint16_t BUTTON_STATE_CHARACTERISTIC_UUID = 0xA001;
 
-    ButtonService(BLEDevice &_ble, bool buttonPressedInitial) :
+    ButtonService(BLE &_ble, bool buttonPressedInitial) :
         ble(_ble), buttonState(BUTTON_STATE_CHARACTERISTIC_UUID, &buttonPressedInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
     {
         GattCharacteristic *charTable[] = {&buttonState};
         GattService         buttonService(ButtonService::BUTTON_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
-        ble.addService(buttonService);
+        ble.gattServer().addService(buttonService);
     }
 
     void updateButtonState(bool newState) {
-        ble.updateCharacteristicValue(buttonState.getValueHandle(), (uint8_t *)&newState, sizeof(bool));
+        ble.gattServer().write(buttonState.getValueHandle(), (uint8_t *)&newState, sizeof(bool));
     }
 
 private:
-    BLEDevice                        &ble;
+    BLE                              &ble;
     ReadOnlyGattCharacteristic<bool>  buttonState;
 };