android - 如果传入的数据包太多,则不会调用 onCharacteristicChanged() 回调

标签 android bluetooth-lowenergy btle

我等待 onCharacteristicChanged() 回调通过 BLE 接收数据。但是,如果 BluetoothDevice 一次发送太多 20 字节的数据包,我最多会收到 10 条通知,而不是预期的 46 条 907 字节长的消息。通知少量数据就好了。

在 onServicesDiscovered(BluetoothGatt gatt, int status) 中,我通过以下方式注册通知:

public void onServicesDiscovered(BluetoothGatt gatt, int status) {
  if (status == BluetoothGatt.GATT_SUCCESS) {
    mService = mGatt.getService(SERVICE_UUID);
    mCharacteristic = mService.getCharacteristic(CHARACTERISTIC_UUID);
    mGatt.setCharacteristicNotification(characteristic, enabled);
    BluetoothGattDescriptor descriptor =
            characteristic.getDescriptor(UUID.fromString(CLIENT_CHARACTERISTIC_CONFIG));
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    mGatt.writeDescriptor(descriptor);            
  }
}

我是否必须以某种方式确认我在 onCharacteristicChanged() 中获得了数据?

BluetoothDevice 正在发送大于 20 字节的消息,方法是将它们分成 20 字节的 block 。通常这些消息小于 200 字节。但是,当 BluetoothDevice 发送的消息长度超过 900 个字节时,应用程序仅通过 onCharacteristicChanged() 收到其中 200 个字节的通知。

在 iOS 上可以很好地接收这些较大的消息。

最佳答案

BLE 堆栈目前有点损坏,存在一个关于太多数据包和读取多个特征的已知错误。根据主题演讲中的幻灯片,BT 堆栈将在 L 版本中得到极大改进(包括从模式和中心模式)

关于android - 如果传入的数据包太多,则不会调用 onCharacteristicChanged() 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24326997/

相关文章:

android - Android BluetoothGatt 类中的 clientIf 字段

android - 覆盖默认的点击噪音?

java - 在 A17-Realtag-BLE-Sensor-Wearable 上获取温度或压力

c++ - 在 Arduino UNO 和运行 Linux 的笔记本电脑之间设置蓝牙 (BLE) 通信

bluetooth-lowenergy - BTLE 特征值字节数过多

android - 在android中的 ListView 中创建动态 TextView

java - 在微调器中选择项目后如何获取微调器值

c# - UWP BLE 广告状态已中止

ios - 如何从 CBPeripheral 和 CBCenter 获取 Mac 地址

ios - 相同的信标如何具有唯一的 BTLE 地址?