我有这个蓝牙温度传感器https://www.aliexpress.com/item/nRF51822-Bluetooth-4-0-BLE-SOC-Temperature-Atmospheric-Pressure-Acceleration-Sensor-Module-Gyroscope-Light-Sensor-MPU6050/32859423925.html?spm=a2g0s.9042311.0.0.e3534c4dT9GRz3,我正在尝试从中读取温度。 我可以连接到它,通过
获得服务BluetoothGatt.getService(UUID.fromString("6e400001-b5a3-f393-e0a9-e50e24dcca9e")
并通过
获取特征BluetoothGattCharacteristic mReadCharacteristic = mCustomService.getCharacteristic(UUID.fromString("6e400005-b5a3-f393-e0a9-e50e24dcca9e"));
结果:
mReadCharacteristic = {BluetoothGattCharacteristic@5322}
mDescriptors = {ArrayList@5326} size = 1
mInstance = 20
mKeySize = 16
mPermissions = 0
mProperties = 16
mService = {BluetoothGattService@5295}
mUuid = {UUID@5327} "6e400005-b5a3-f393-e0a9-e50e24dcca9e"
mValue = null
mWriteType = 2
然后我将其称为mBluetoothGatt.readCharacteristic(mReadCharacteristic) 并希望通过BluetoothGattCallback获取数据,但readCharacteristic总是返回false
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0) {
return false;
}
属性= 16 PROPERTY_READ = 5 我在做什么错了?
答案 0 :(得分:0)
属性是一个位掩码,该特征支持该操作。如https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic.html所示,16表示通知而不读取,因此该特性无法读取。也许您应该尝试注册通知呢?