0

I have this bluetooth temperature sensor 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 and I am trying to read temperature out of it. I can connect to it, get services via

BluetoothGatt.getService(UUID.fromString("6e400001-b5a3-f393-e0a9-e50e24dcca9e")

and get characteristics via

BluetoothGattCharacteristic mReadCharacteristic = mCustomService.getCharacteristic(UUID.fromString("6e400005-b5a3-f393-e0a9-e50e24dcca9e"));

result:

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

Then I call mBluetoothGatt.readCharacteristic(mReadCharacteristic) and hope to get data via BluetoothGattCallback, but readCharacteristic always returns false

if ((characteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_READ) == 0) {
    return false;
}

properties = 16 PROPERTY_READ = 5 What am I doing wrong ?

maxxxo
  • 672
  • 3
  • 10
  • 28
  • @Emil is right, this is notify-based. the official document will go through how to get notification https://developer.android.com/guide/topics/connectivity/bluetooth-le#notification – fangzhzh Jun 05 '19 at 22:56

1 Answers1

0

Properties is a bitmask which operations the characteristic supports. As shown at https://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic.html, 16 means notify and not read, so the characteristic can not be read. Maybe you should try to register for notifications instead?

Emil
  • 16,784
  • 2
  • 41
  • 52