【问题标题】:What happens with the Gatt Characteristic after it has been read?阅读 Gatt 特征后会发生什么?
【发布时间】:2017-02-12 09:13:09
【问题描述】:

我正在使用具有 Android 5.1(蓝牙 4.0)的 Android 设备和具有蓝牙 4.2 的 MCU 板。

在我的 MCU 方面,我正在循环更新我的 Gatt 特性,以确保我知道我在里面写入的数据是否一致。在我将其写入 gatt 数据库之前,我正在使用 crc 检查。

在我的 android 端,我只有一个线程,它从该 gatt 数据库中读取特征,之后直接我有相同的 crc,但似乎 50% 的值已损坏(这从我的边)。 我知道我在 gatt 数据库中写入的数据是正确的,所以我想问题在于在一个线程中多次读取特征。

我已经尝试通过我的 android 端的通知读取特征,但蓝牙服务永远不会跳入 OnCharacteristicChanged 回调。

我的特征更新是这样的

tmpGatt.readCharacteristic(characteristic);

并且特征被之前的uuid过滤

for(int i = 0; i<Services.size(); i++){
                Characteristics = Services.get(i).getCharacteristics();
                for(int c=0;c < Characteristics.size();c++){
                    UUID myUUID = Characteristics.get(c).getUuid();
                    if(myUUID.toString().equals("354a1b8e-7597-11e6-8b77-86f30ca893d3")){
                        characteristic = Characteristics.get(c);
                        //refExternalData.getRefBluetoothGatt().readCharacteristic(characteristic);
                        descriptor = characteristic.getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
                        Log.i("BLE", "Characteristic " + myUUID.toString() + " found");
                    }
                }
            }

所以我需要做一些特别的事情来重新阅读 gattcharacteristic 吗?

【问题讨论】:

    标签: android bluetooth-lowenergy gatt


    【解决方案1】:

    您是否按照https://developer.android.com/guide/topics/connectivity/bluetooth-le.html#notification 的程序启用通知?

    当您发出readCharacteristic 时,在您获得onCharacteristicRead 之前,您不得发出新的readCharacteristic。或者实际上,在前一个请求完成之前,您不允许发送任何新请求(readCharacteristicwriteCharacteristicreadDescriptorwriteDescriptor)。这是因为一次可能只有一个未完成的 GATT 请求,并且没有内部队列。

    【讨论】:

    • 我现在已经切换回 BLE 示例应用程序,以确保如果我推送特征名称但数据仍然损坏,则会触发 onCharacteristicRead。那么您认为问题出在应用程序端还是单片机端?
    • 如果数据损坏,那肯定是 MCU / 发送方的问题。根据 BLE 标准,有效载荷已通过无线方式进行 CRC 保护。
    • 我会重新检查我的代码,如果我发现问题会在这里发布。谢谢
    • 问题是我已将描述符设置为 descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);而不是descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);。因为我在我的 GATT SERVER 上使用了指示...
    猜你喜欢
    • 1970-01-01
    • 2016-07-26
    • 2013-11-29
    • 1970-01-01
    • 1970-01-01
    • 2019-02-24
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    相关资源
    最近更新 更多