我正在开发一个 Android 应用程序,它应该订阅多个 BLE 特性。
但无论我做什么,我都只会收到一个特征的更新值。
这是代码:
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);
无论我做什么,我都只能得到速度数据。如果我更改两个 block 的顺序,我只会获得加速度,但不会获得更多速度数据。
我需要做什么才能同时订阅多个特性?
提前致谢
雷托
最佳答案
要让描述符依次写入,请等待描述符写入的回调,然后再开始下一个描述符。
关于android - 如何使用 Android 订阅多个 BluetoothLE 特性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38230684/