Search code examples
c++bluetooth-lowenergymbed

How to add name and ID attributes to custom BLE characteristics C++


I am using this mbed workthrough, to create a custom GATT Service in C++. However, this code only creates characteristics with UUIDs:

uint16_t customServiceUUID  = 0xA000;
uint16_t readCharUUID       = 0xA001;
uint16_t writeCharUUID      = 0xA002

In my C# code on the smartphone connecting to my mbed based device however, I am trying to access the Characteristic.ID and Characteristic.Name attributes, which the standard characteristics in the standard profiles have, but mine do not. How to I add this information to the characteristics?

In my C# code, I have the following:

try {
    foreach(var data in services)
    {
    if (data!=null && data.ID == 0xA001.UuidFromPartial()){ GasSenseService = data; }

    Debug.WriteLineIf (data!=null, "data not null");
                Debug.WriteLine ("Name:", data.Name);
                Debug.WriteLine ("ID:", data.ID);

    }
}
catch {
...

Solution

  • The characteristic name is a descriptor.

    You need to add the correct descriptor used by the API to find Characteristc.Name.

    This page, links to a document with standard descriptors.

    I bet if you create a descriptor with ID 0x2901 (attached to your characteristic) and set its value to "My Chracteristic", then Characteristc.Name will be "My Chracteristic" in your C# code.