Accessing to Heart Service in BLE device returns null

0

I'm trying to read the heart rate from a BLE device (It's a smartwatch and the model is CURREN R5 Pro), but when I get the Heart Rate Service, it returns null.

This is the code:

class Constants {
    final static UUID HEART_RATE_SERVICE_UUID = convertFromInteger(0x180D);
    final static UUID HEART_RATE_MEASUREMENT_UUID = convertFromInteger(0x2A37);
    final static UUID HEART_RATE_CONTROL_POINT_UUID = convertFromInteger(0x2A39);
    final static UUID CLIENT_CHARACTERISTIC_CONFIG_UUID = convertFromInteger(0x2902);

    private static UUID convertFromInteger(int i) {
        final long MSB = 0x0000000000001000L;
        final long LSB = 0x800000805f9b34fbL;
        long value = i & 0xFFFFFFFF;
        return new UUID(MSB | (value << 32), LSB);
    }
}


private final BluetoothGattCallback bluetoothGattCallback = new BluetoothGattCallback() {
    @Override
    public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
        if (newState == BluetoothProfile.STATE_CONNECTED) {
            bluetoothGatt.discoverServices();
            Log.d(TAG, "Connected");
        }
        if (newState == BluetoothProfile.STATE_DISCONNECTED) {
            Log.d(TAG, "Disconnected");
        }
    }

    @Override
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {
        if (status == BluetoothGatt.GATT_SUCCESS) {
            //getCharacteristic(HEART_RATE_MEASUREMENT_UUID) returns null
            BluetoothGattCharacteristic characteristic = gatt.getService(HEART_RATE_SERVICE_UUID)
                    .getCharacteristic(HEART_RATE_MEASUREMENT_UUID);
            gatt.setCharacteristicNotification(characteristic, true);

            BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_UUID);
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            gatt.writeDescriptor(descriptor);
        }
    }

    @Override
    public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
        BluetoothGattCharacteristic characteristic = gatt.getService(HEART_RATE_SERVICE_UUID)
                .getCharacteristic(HEART_RATE_CONTROL_POINT_UUID);
        characteristic.setValue(DATA_STREAMING_COMMAND);
        gatt.writeCharacteristic(characteristic);
    }

    @Override
    public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
        if (HEART_RATE_MEASUREMENT_UUID.equals(characteristic.getUuid())) {
            Log.d(TAG, "HEART_RATE_MEASUREMENT_UUID");
            //PROCESS DATA
        }
        if (HEART_RATE_CONTROL_POINT_UUID.equals(characteristic.getUuid())) {
            Log.d(TAG, "HEART_RATE_CONTROL_POINT_UUID");
            //PROCESS DATA
        }
    }
};

However, the only app that is able to read the heart rate from the device is Wearfit. Other applications are not able to read the heart rate from this device.

The services that I'm able to get are these:

  • 00001800-0000-1000-8000-00805f9b34fb
  • 00001801-0000-1000-8000-00805f9b34fb
  • 6e400001-b5a3-f393-e0a9-e50e24dcca9e
  • 00001530-1212-efde-1523-785feabcd123
  • 0000fee7-0000-1000-8000-00805f9b34fb

Has anyone experienced this situation? Is there anything wrong with my code? Thanks for your help.

android
bluetooth-lowenergy
asked on Stack Overflow Oct 25, 2018 by GianMS • edited Oct 26, 2018 by GianMS

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0