androidbluetooth-lowenergycharacteristics

How to subscribe to multiple BluetoothLE Characteristics with Android


I am developing an Android app which should subscribe to multiple BLE characteristics.

But whatever I do, I receive only the updated values from one characteristic.

Here is the code:

BluetoothGattCharacteristic characteristicVel = gatt.getService(BleDefinedUUIDs.Service.KOMMMODUL_SERVICE).getCharacteristic(BleDefinedUUIDs.Characteristic.VELOCITY);
                gatt.setCharacteristicNotification(characteristicVel, true);
                BluetoothGattDescriptor descriptorVel = characteristicVel.getDescriptor(
                        BleDefinedUUIDs.Descriptor.CHAR_CLIENT_CONFIG);
                descriptorVel.setValue(BleDefinedUUIDs.Descriptor.ENABLE_NOTIFICATION_VALUE);
                gatt.writeDescriptor(descriptorVel);

            BluetoothGattCharacteristic characteristicAcc = gatt.getService(BleDefinedUUIDs.Service.KOMMMODUL_SERVICE).getCharacteristic(BleDefinedUUIDs.Characteristic.ACCELERATION);
            gatt.setCharacteristicNotification(characteristicAcc, true);
            BluetoothGattDescriptor descriptorAcc = characteristicAcc.getDescriptor(
                    BleDefinedUUIDs.Descriptor.CHAR_CLIENT_CONFIG);
            descriptorAcc.setValue(BleDefinedUUIDs.Descriptor.ENABLE_NOTIFICATION_VALUE);
            gatt.writeDescriptor(descriptorAcc);

Whatever I do I get only the velocity data. If I change the order of the two blocks I get acceleration only but no more velocity data.

What have I to do in order to subscribe to many characteristics at once?

Thanks in advance

Reto


Solution

  • To get descriptors to write one after another, please wait for the callback from a descriptor write before starting the next one.