我等待 onCharacteristicChanged()
回调通过BLE接收数据 . 但是如果蓝牙设备一次发送太多20个字节的数据包,那么我最多可获得10个通知,而不是907字节长消息的预期46个通知 . 较少量的数据被通知就好了 .
在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个字节的消息 . 通常这些消息小于200字节 . 但是,当BluetoothDevice发送长度超过900字节的消息时,应用程序仅通过 onCharacteristicChanged()
获取200个字节的通知 .
在iOS上收到这些更大的消息就好了 .
1 回答
BLE堆栈目前有点破碎,有一个已知的错误,包含太多数据包和读取多个特征 . 根据主题演讲中的幻灯片,BT版本将在L版本中得到极大改进(包括从属和中央模式)