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:
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.