Azarudeen Asraff
Azarudeen Asraff

Reputation: 21

Service for heart rate or step count is not found in watch

I am building an app for my company where there is a feature it should get a heart rate from a Bluetooth watch.

I am using this library where I can get the basic data like device name and battery level and all but I can't get the data that I want (Step count and Heart rate).

Is there any other way to make it work? I have been working on this for weeks.

These are services I got from nRF:

Services from nRF

The code that I have written:

package com.example.myapplicationrx;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.ParcelUuid;
import android.widget.Button;

import com.polidea.rxandroidble2.RxBleClient;
import com.polidea.rxandroidble2.RxBleConnection;
import com.polidea.rxandroidble2.RxBleDevice;

import java.util.UUID;

import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;

public class MainActivity extends AppCompatActivity {

    Disposable connectionDisposable;
    RxBleDevice device;
    RxBleClient rxBleClient;

    @SuppressLint("MissingPermission")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button start = findViewById(R.id.start);
        Button read = findViewById(R.id.read);
        Context context = getApplicationContext();
        rxBleClient = RxBleClient.create(context);

        String macAddress = "EE:00:52:C1:66:95";

        device = rxBleClient.getBleDevice(macAddress);

        start.setOnClickListener(v -> {
            connectionDisposable = device.establishConnection(false)
                    .flatMapSingle(rxBleConnection -> rxBleConnection.readCharacteristic(convertFromInteger(0x2A37)))
                    .subscribe(
                            characteristicValue -> {
                                System.out.println(new String(characteristicValue));
                            },
                            throwable -> {
                                // Handle an error here.
                                System.out.println(throwable);
                            }
                    );
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    connectionDisposable.dispose();
                }
            }, 10000);
        });
    }
        public UUID convertFromInteger ( int i){
            final long MSB = 0x0000000000001000L;
            final long LSB = 0x800000805f9b34fbL;
            long value = i & 0xFFFFFFFF;
            return new UUID(MSB | (value << 32), LSB);
        }
        private Observable<RxBleConnection> prepareConnectionObservable () {
            return device
                    .establishConnection(false);
        }
        private String byteArrayToHex ( byte[] a){
            StringBuilder sb = new StringBuilder(a.length * 2);
            for (byte b : a)
                sb.append(String.format("%02x", b & 0xff));
            return sb.toString();
        }
    }

errors when I read heart rate

I/System.out: com.polidea.rxandroidble2.exceptions.BleCharacteristicNotFoundException: Characteristic not found with UUID 00002a37-0000-1000-8000-00805f9b34fb

Upvotes: 0

Views: 281

Answers (1)

Youssif Saeed
Youssif Saeed

Reputation: 13305

From the attached image, it looks like the watch doesn't have the standard Heart Rate Service (UUID 0x180D) or the standard Step Count Service (UUID 0x27BA). You can read the device name and the battery service because the Device Information Service (0x180A) and Battery Service (0x180F) exist.

If you want to be able to read the heart rate and step count, you should first understand how this data is exposed via the watch. It looks like there are two additional primary services that the watch supports, but these are not standard services, so unless there's documentation from the watch company, it would be difficult to try and read the data off these services. Your best bet would be a trial and error method where you read the data in those services and try to make sense off it knowing that they should contain heart rate and step count data.

Upvotes: 2

Related Questions