Client Characteristic Configuration Descriptor uuid

I am developing on a nrf52 board with a fdc2214 chip. I created 1 custom Service and 3 characteristics shown below, and the format of my UUID is 0000xxxx-1212-efde-1523-785fef13d123, where xxxx is the 16 bit uuid:

image description

Question 1: All the characteristics have the same CCCD UUID, is that normal?

Now, I am trying to subscribe to notification on my android app to read data from the nrf52 board, so following different google resources, I added the following lines of code:

    mBluetoothGatt.setCharacteristicNotification(mReadCharacteristic,true);

BluetoothGattDescriptor descriptor = mReadCharacteristic.getDescriptor(CCCD);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);

in my readCustomCharacteristic(String chx_uuid); shown below:

    public void readCustomCharacteristic(String chx_uuid) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    }
    /*check if the service is available on the device*/
    BluetoothGattService mCustomService = mBluetoothGatt.getService(UUID.fromString("0000abcd-1212-efde-1523-785fef13d123"));
    if(mCustomService == null){
        Log.w("hello", "Custom BLE Service not found");
        return;
    }
    /*get the read characteristic from the service*/
 //   BluetoothGattCharacteristic mReadCharacteristic = mCustomService.getCharacteristic(UUID.fromString("00000002-0000-1000-8000-00805f9b34fb"));
    BluetoothGattCharacteristic mReadCharacteristic = mCustomService.getCharacteristic(UUID.fromString(chx_uuid));
    if(mBluetoothGatt.readCharacteristic(mReadCharacteristic) == false){
        Log.w(TAG, "Failed to read characteristic");
    }

    mBluetoothGatt.setCharacteristicNotification(mReadCharacteristic,true);

    BluetoothGattDescriptor descriptor = mReadCharacteristic.getDescriptor(CCCD);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    mBluetoothGatt.writeDescriptor(descriptor);


}

Question 2: since my UUID format is 0000xxxx-1212-efde-1523-785fef13d123, then why would my app crash when I replace mReadCharacteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")); with mReadCharacteristic.getDescriptor(UUID.fromString("00002902-1212-efde-1523-785fef13d123"));?

Thanks for the help.

  • Answers:

    1. Yes indeed, CCCD has UUID assigned by BT SIG so it is 16-bit (but of course you can expand it with BT SIG UUID base to full 128 bits if you really need;). There is no problem that each of CCCDs has the same UUID because they have different handle IDs (and that's how (G)ATT methods address targets on the stack) and in fact they must be the same because otherwise how you would know that's CCCD???
    2. Not sure it's evident what are you doing in your Android app. CCC descriptor should be accessible through dedicated BLE API call and in fact your app should not care what and how exactly Android (G)ATT stack works with it, you simply ask to enable or disable Notifications (or Indications) and it will happen. You should never talk to that by UUID and it's question what the hell you want to achieve with line mReadCharacteristic.getDescriptor(UUID.fromString("00002902-1212-efde-1523-785fef13d123"))? That UUID doesn't exist on server side, does it?
  • @endnode 00002902-1212-efde-1523-785fef13d123, this UUID does not exist on my server side. So, what does ths line (mReadCharacteristic.getDescriptor(UUID.fromString("00002902-1212-efde-1523-785fef13d123"))) do in my android side? Also, how can I verify that I turned on my notification on my android side? thank you for your help!

  • 0
    12078 pts.
    in reply to endnode

    You are asking ME what YOUR code is doing?:) If you don't know then simply don't put it to your app;) If you are running getDescriptor function with non-existing UUID then I expect it will return some error. Unfortunately I'm not android developer so I neither help you with this function call nor with second question about how to verify Server Notification/Indication status from GATT Client side on top o Android API. I would say Google should be your friend (also this forum has search window and there is good chance that one of 25k Q&S contains Android code which solves your problem).

Related