Datasheet
function return true if characteristics is found, and false otherwise. You could also check with .discovered() function. A
service could contain more characteristics but we don't need to discover them all, only those that we want to interact
with.
Advanced: Alternatively, you could discover all the interested characteristics of a service within a function call by
using Bluefruit.Discovery.discoverCharacteristic() (not used in the example). The API can take up to 5 characteristics, if you
need more, the variant with passing array of characteristics is also available. The function will return the number of
characteristic it found.
Note: when a characteristic is discovered by above API, all necessarily meta data such as handles, properties (
read,write, notify etc ...), cccd handle will be updated automatically. You can then
use BLECLientCharacteristic (https://adafru.it/Cng) API such as read(), write(), enableNotify() on it provided that its
properties support such as operation.
5. Once hrmc is discovered, you should enable its notification by calling hrmc.enableNotify() . If this succeeded (return
true), peripheral can now send data to us using notify message. Which will trigger the callback that we setup earlier to
handle incoming data.
// Connect Callback Part 2
void connect_callback(uint16_t conn_handle)
{
Serial.print("Discovering Measurement characteristic ... ");
if ( !hrmc.discover() )
{
// Measurement chr is mandatory, if it is not found (valid), then disconnect
Serial.println("not found !!!");
Serial.println("Measurement characteristic is mandatory but not found");
Bluefruit.Central.disconnect(conn_handle);
return;
}
Serial.println("Found it");
// Measurement is found, continue to look for option Body Sensor Location
// https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.body_sensor_location.xml
// Body Sensor Location is optional, print out the location in text if present
Serial.print("Discovering Body Sensor Location characteristic ... ");
if ( bslc.discover() )
{
Serial.println("Found it");
// Body sensor location value is 8 bit
const char* body_str[] = { "Other", "Chest", "Wrist", "Finger", "Hand", "Ear Lobe", "Foot" };
// Read 8-bit BSLC value from peripheral
uint8_t loc_value = bslc.read8();
Serial.print("Body Location Sensor: ");
Serial.println(body_str[loc_value]);
}else
{
Serial.println("Found NONE");
}
...............
}
© Adafruit Industries https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide Page 85 of 175