读取Ble特征

时间:2017-06-12 08:39:55

标签: android bluetooth-lowenergy rxandroidble

我使用RxAndroidBle库与蓝牙设备进行通信, 但最近我遇到了一个奇怪的问题。 当读取其中一个设备特性时,我收到了这样的错误:

BleGattCharacteristicException{macAddress=60:CE:32:BA:9E:70, 
 status=6 (0x06 -> https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-5.1.0_r1/stack/include/gatt_api.h), 
 bleGattOperationType=BleGattOperation{description='CHARACTERISTIC_READ'}}

我看到描述说明特征读取有问题但我能够使用谷歌样本中的一些商业扫描仪或香草蓝牙代码在同一设备上读取它。 我检查了特征属性 - 它有PROPERTY_READ。

使用RxAndroidBle的Polidea样本时,我遇到了同样的错误。

无法在互联网上的任何地方找到类似的案例,也许有人遇到了这样的错误。 其他信息可能是我连接的设备是在iPhone上运行的设备模拟器。 我没有提供任何代码片段,因为我使用了核心示例中的相同代码。

完整详细日志:

06-12 11:00:20.105 22459-22459/? D/RxBle#Radio:   QUEUED RxBleRadioOperationConnect(121589482)
06-12 11:00:20.106 22459-22504/? D/RxBle#Radio:  STARTED RxBleRadioOperationConnect(121589482)
06-12 11:00:20.131 22459-22459/? D/BluetoothGatt: connect() - device: 41:0A:AE:0E:C2:50, auto: false
06-12 11:00:20.131 22459-22459/? D/BluetoothGatt: registerApp()
06-12 11:00:20.131 22459-22459/? D/BluetoothGatt: registerApp() - UUID=b6c1ef8f-408b-4afb-8e27-97a6ff2c20fb
06-12 11:00:20.137 22459-22473/? D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6
06-12 11:00:20.330 22459-22473/? D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=41:0A:AE:0E:C2:50
06-12 11:00:20.333 22459-22473/? D/RxBle#BluetoothGatt: onConnectionStateChange newState=2 status=0
06-12 11:00:20.395 22459-22854/? D/CharacteristicOperationExampleActivity: Hey, connection has been established!
06-12 11:00:20.400 22459-22504/? D/RxBle#Radio: FINISHED RxBleRadioOperationConnect(121589482)
06-12 11:00:25.608 22459-22459/? I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
06-12 11:00:25.663 22459-22459/? I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP
06-12 11:00:25.675 22459-22459/? D/RxBle#Radio:   QUEUED RxBleRadioOperationServicesDiscover(3295555)
06-12 11:00:25.676 22459-22504/? D/RxBle#Radio:  STARTED RxBleRadioOperationServicesDiscover(3295555)
06-12 11:00:25.683 22459-22459/? D/BluetoothGatt: discoverServices() - device: 41:0A:AE:0E:C2:50
06-12 11:00:25.726 22459-22473/? D/BluetoothGatt: onSearchComplete() = Device=41:0A:AE:0E:C2:50 Status=0
06-12 11:00:25.727 22459-22473/? D/RxBle#BluetoothGatt: onServicesDiscovered status=0
06-12 11:00:25.732 22459-22854/? D/RxBle#Radio:   QUEUED RxBleRadioOperationCharacteristicRead(177013014)
06-12 11:00:25.733 22459-22504/? D/RxBle#Radio: FINISHED RxBleRadioOperationServicesDiscover(3295555)
06-12 11:00:25.735 22459-22504/? D/RxBle#Radio:  STARTED RxBleRadioOperationCharacteristicRead(177013014)
06-12 11:00:25.827 22459-22471/? W/BluetoothGatt: onCharacteristicRead() - Device=41:0A:AE:0E:C2:50 handle=102 Status=6
06-12 11:00:25.830 22459-22471/? D/RxBle#BluetoothGatt: onCharacteristicRead characteristic=1f26b1a4-2b50-11e7-99a8-fcaa142b0bea status=6
06-12 11:00:25.844 22459-22471/? D/RxBle#Radio:   QUEUED RxBleRadioOperationDisconnect(84936079)
06-12 11:00:25.849 22459-22471/? D/elo: error: BleGattCharacteristicException{macAddress=41:0A:AE:0E:C2:50, status=6 (0x06 -> https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-5.1.0_r1/stack/include/gatt_api.h), bleGattOperationType=BleGattOperation{description='CHARACTERISTIC_READ'}}
06-12 11:00:25.879 22459-22504/? D/RxBle#Radio: FINISHED RxBleRadioOperationCharacteristicRead(177013014)
06-12 11:00:25.880 22459-22504/? D/RxBle#Radio:  STARTED RxBleRadioOperationDisconnect(84936079)
06-12 11:00:25.915 22459-22459/? D/elo: error: BleGattCharacteristicException{macAddress=41:0A:AE:0E:C2:50, status=6 (0x06 -> https://android.googlesource.com/platform/external/bluetooth/bluedroid/+/android-5.1.0_r1/stack/include/gatt_api.h), bleGattOperationType=BleGattOperation{description='CHARACTERISTIC_READ'}}
06-12 11:00:25.925 22459-22459/? D/BluetoothManager: getConnectionState()
06-12 11:00:25.925 22459-22459/? D/BluetoothManager: getConnectedDevices
06-12 11:00:25.951 22459-22459/? D/BluetoothGatt: cancelOpen() - device: 41:0A:AE:0E:C2:50
06-12 11:00:25.962 22459-22471/? D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=41:0A:AE:0E:C2:50
06-12 11:00:25.966 22459-22471/? D/RxBle#BluetoothGatt: onConnectionStateChange newState=0 status=0
06-12 11:00:25.971 22459-22459/? D/BluetoothGatt: close()
06-12 11:00:25.971 22459-22459/? D/BluetoothGatt: unregisterApp() - mClientIf=6
06-12 11:00:25.974 22459-22504/? D/RxBle#Radio: FINISHED RxBleRadioOperationDisconnect(84936079)

从我可以阅读该属性的Google蓝牙示例应用中详细记录

06-12 14:43:36.540 10869-10869/com.example.android.bluetoothlegatt I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
06-12 14:43:36.598 10869-10869/com.example.android.bluetoothlegatt I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP
06-12 14:43:36.599 10869-10869/com.example.android.bluetoothlegatt D/BluetoothLeService: Trying to use an existing mBluetoothGatt for connection.
06-12 14:43:41.209 10869-10869/com.example.android.bluetoothlegatt D/BluetoothAdapter: stopLeScan()
06-12 14:43:41.215 10869-10869/com.example.android.bluetoothlegatt D/BluetoothAdapter: scan not started yet
06-12 14:43:43.781 10869-10882/com.example.android.bluetoothlegatt D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=5F:56:F7:E9:8A:38
06-12 14:43:43.789 10869-10882/com.example.android.bluetoothlegatt I/BluetoothLeService: Connected to GATT server.
06-12 14:43:43.789 10869-10882/com.example.android.bluetoothlegatt D/BluetoothGatt: discoverServices() - device: 5F:56:F7:E9:8A:38
06-12 14:43:43.792 10869-10882/com.example.android.bluetoothlegatt I/BluetoothLeService: Attempting to start service discovery:true
06-12 14:43:45.513 10869-10882/com.example.android.bluetoothlegatt D/BluetoothGatt: onSearchComplete() = Device=5F:56:F7:E9:8A:38 Status=0
06-12 14:43:54.958 10869-10869/com.example.android.bluetoothlegatt D/BluetoothGatt: setCharacteristicNotification() - uuid: 1f26b1a4-2b50-11e7-99a8-fcaa142b0bea enable: true
06-12 14:43:55.063 10869-10882/com.example.android.bluetoothlegatt W/BluetoothGatt: onCharacteristicRead() - Device=5F:56:F7:E9:8A:38 handle=110 Status=0

确实存在差异,因为此应用在读取值之前设置了通知。应用程序负责的代码如下所示:

// If a given GATT characteristic is selected, check for supported features.  This sample
    // demonstrates 'Read' and 'Notify' features.  See
    // http://d.android.com/reference/android/bluetooth/BluetoothGatt.html for the complete
    // list of supported characteristic features.
    private final ExpandableListView.OnChildClickListener servicesListClickListner =
            new ExpandableListView.OnChildClickListener() {
                @Override
                public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
                                            int childPosition, long id) {
                    if (mGattCharacteristics != null) {
                        final BluetoothGattCharacteristic characteristic =
                                mGattCharacteristics.get(groupPosition).get(childPosition);
                        final int charaProp = characteristic.getProperties();
                        if ((charaProp | BluetoothGattCharacteristic.PROPERTY_READ) > 0) {
                            // If there is an active notification on a characteristic, clear
                            // it first so it doesn't update the data field on the user interface.
                            if (mNotifyCharacteristic != null) {
                                mBluetoothLeService.setCharacteristicNotification(
                                        mNotifyCharacteristic, false);
                                mNotifyCharacteristic = null;
                            }
                            mBluetoothLeService.readCharacteristic(characteristic);
                        }
                        if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
                            mNotifyCharacteristic = characteristic;
                            mBluetoothLeService.setCharacteristicNotification(
                                    characteristic, true);
                        }
                        return true;
                    }
                    return false;
                }
    };

至于RxAndroidBle版本,我在1.2.0,1.2.4和1.3.0上进行了测试。 Android版本7.1,6.0.1和5.1。

在阅读特征之前会尝试实施此通知,因为它是我能看到的唯一区别。

0 个答案:

没有答案