从Android手机的nRF 51822蓝牙温度传感器读取温度

时间:2019-06-05 22:28:47

标签: android bluetooth bluetooth-gatt

我有这个蓝牙温度传感器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 我在做什么错了?

1 个答案:

答案 0 :(得分:0)

属性是一个位掩码,该特征支持该操作。如https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic.html所示,16表示通知而不读取,因此该特性无法读取。也许您应该尝试注册通知呢?