我在与自定义 BLE 传感器板通信的 Android 手机上使用 BLE 应用程序。板提供了两个特性,加速度和心电图。在电话方面,我想从传感器板接收两个特性的通知。我设置通知的代码:
mGatt.setCharacteristicNotification(ecgChar, true);
BluetoothGattDescriptor descriptor = ecgChar.getDescriptor(
UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mGatt.writeDescriptor(descriptor);
mGatt.setCharacteristicNotification(accelChar, true);
descriptor = ecgChar.getDescriptor(
UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mGatt.writeDescriptor(descriptor);
但是,我只能收到第一个特征的通知。当我只为一个特征注册通知时,效果很好。 ECG 和加速度的采样频率均为 100Hz。那么我怎样才能收到来自这两个特征的通知呢?谢谢。
最佳答案
你一次只能有一个未完成的 gatt 操作。在这种情况下,您会执行两次 writeDescriptor 调用,然后等待第一个完成。您必须等待 https://developer.android.com/reference/android/bluetooth/BluetoothGattCallback.html#onDescriptorWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int)直到你可以发送下一个。
关于android - Bluetooth LE 监听多种特性通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42126016/