Datasheet

2. Since Heart Rate Measurement characteristic (clientMeasurement above) is
notifiable.
You need to set up callback
for it
' hrmc.setNotifyCallback(hrm_notify_callback); ' This sets the callback that will be fired when we receive a Notify
message from peripheral. This is needed to handle notifiable characteristic since callback allow us to response to
the message in timely manner. For this example is just simply printing out value to Serial.
' hrmc.begin(); ' Once all of the properties have been set, you must call .begin() which will add the characteristic
definition to the last BLEClientService that was '.begin()ed'.
3. Next, we can start to scan and connect to peripheral that advertises HRM service. Once connected, we need to go
through peripheral GATT table to find out the Gatt handle for our interest. In this example they are handle for
hrms, hrmc and bslc. This looking up process for interested service/characteristic is called Discovery.
Note: Gatt handle (or just handle) is required to perform any operations at all such as read, write, enable notify. It is
required that a client characteristic must be discovered before we could doing anything with it.
The service should be discovered before we could discover its characteristic. This can be done by
calling hrms.discover(conn_handle) . Where conn_handle is the connection ID i.e peripheral that we want to discover
since it is possible for Bluefruit nRF52 to connect to multiple peripherals concurrently. If the service is found, the
function will return true, otherwise false.
4. Afterwards, we continue to discover all the interested characteristics within the service by calling .discover() . The
You MUST call .begin() on the BLEClientService before adding any BLEClientCharacteristics. Any
BLEClientCharacteristic will automatically be added to the last BLEClientService that was `begin()'ed!
Note for characteristic that does not support notify e.g body sensor location , we can simply use .read() to
retrieve its value.
// Connect Callback Part 1
void connect_callback(uint16_t conn_handle)
{
Serial.println("Connected");
Serial.print("Discovering HRM Service ... ");
// If HRM is not found, disconnect and return
if ( !hrms.discover(conn_handle) )
{
Serial.println("Found NONE");
// disconect since we couldn't find HRM service
Bluefruit.Central.disconnect(conn_handle);
return;
}
// Once HRM service is found, we continue to discover its characteristic
Serial.println("Found it");
.............
}
© Adafruit Industries https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide Page 84 of 175