从 Android phone 从 nRF 51822 蓝牙温度传感器读取温度
Read temperature from nRF 51822 bluetooth temperature sensor from Android phone
我有这个蓝牙温度传感器 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 总是 returns false
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0) {
return false;
}
属性 = 16 PROPERTY_READ = 5
我做错了什么?
Properties 是特性支持的操作的位掩码。如https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic.html所示,16表示notify而不是read,所以该特征是不可读的。也许您应该改为注册通知?
我有这个蓝牙温度传感器 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 总是 returns false
if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0) {
return false;
}
属性 = 16 PROPERTY_READ = 5 我做错了什么?
Properties 是特性支持的操作的位掩码。如https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic.html所示,16表示notify而不是read,所以该特征是不可读的。也许您应该改为注册通知?