Datasheet
Custom: HRM
The BLEService and BLECharacteristic classes can be used to implement any custom or officially adopted BLE service
of characteristic using a set of basic properties and callback handlers.
The example below shows how to use these classes to implement the Heart Rate Monitor (https://adafru.it/vaO)
service, as defined by the Bluetooth SIG.
HRM Service Definition
UUID: 0x180D (https://adafru.it/vaO)
Only the first characteristic is mandatory, but we will also implement the optional Body Sensor Location characteristic.
Heart Rate Control Point won't be used in this example to keep things simple.
Implementing the HRM Service and Characteristics
The core service and the first two characteristics can be implemented with the following code:
First, define the BLEService and BLECharacteristic variables that will be used in your project:
Then you need to 'populate' those variables with appropriate values. For simplicity sake, you can define a custom
function for your service where all of the code is placed, and then just call this function once in the 'setup' function:
Characteristic Name
Heart Rate Measurement
Body Sensor Location
Heart Rate Control Point
UUID
0x2A37
0x2A38
0x2A39
Requirement
Mandatory
Optional
Conditional
Properties
Notify
Read
Write
/* HRM Service Definitions
* Heart Rate Monitor Service: 0x180D
* Heart Rate Measurement Char: 0x2A37
* Body Sensor Location Char: 0x2A38
*/
BLEService hrms = BLEService(UUID16_SVC_HEART_RATE);
BLECharacteristic hrmc = BLECharacteristic(UUID16_CHR_HEART_RATE_MEASUREMENT);
BLECharacteristic bslc = BLECharacteristic(UUID16_CHR_BODY_SENSOR_LOCATION);
void setupHRM(void)
{
// Configure the Heart Rate Monitor service
// See: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.heart_rate.xml
// Supported Characteristics:
// Name UUID Requirement Properties
// ---------------------------- ------ ----------- ----------
// Heart Rate Measurement 0x2A37 Mandatory Notify
// Body Sensor Location 0x2A38 Optional Read
// Heart Rate Control Point 0x2A39 Conditional Write <-- Not used here
hrms.begin();
// Note: You must call .begin() on the BLEService before calling .begin() on
// any characteristic(s) within that service definition.. Calling .begin() on
// a BLECharacteristic will cause it to be added to the last BLEService that
© Adafruit Industries https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide Page 45 of 175