0
votes

I have been trying for a few weeks to connect to the MI Band 2 watch, and read the heart rate characteristic value, but without luck.

I am a little unsure what the procedure is, when we are talking about GATT. For the API https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/gatt-api.txt I was thinking about using the org.bluez.GattCharacteristic1 interface to read a value out.

I can connect and pair the watch, and get all UUIDs (services, descriptors and characteristics). The heart rate measurement has the following info:

Characteristic
    /org/bluez/hci0/dev_CD_1D_69_25_19_5E/service0027/char0028
    00002a37-0000-1000-8000-00805f9b34fb

I have tried using the bluetoothctl program to read the value, but getting a "not permitted" feedback.

What is the procedure to read out a characteristic value, using the GATT API.

2
Have you tried to do this via Fitness api like this developers.google.com/fit/android/ble-sensors?hl=ru ?Vadim Eksler

2 Answers

2
votes

Your device is using the adopted Heart Rate profile, seeing that 0x2A37 is the adopted characteristic UUID for heart rate measurement. I would recommend that you use the BlueZ command line tools as follows:-

1. Find the handle of the heart rate characteristic using:-

gatttool -b 00:11:22:33:44:55 --characteristics

Replace 00:11:22:33:44:55 with the Bluetooth address of your device. You basically want to find the uuid that contains 2a37 and note down its corresponding 'char value handle'.

2. Find the descriptors at that handle using:-

gatttool -b 00:11:22:33:44:55 char-desc --handle=0xXX

Where XX is the char value handle that you noted down earlier. You should be able to see a couple of characteristic descriptors at that handle. Note down the char handle with uuid 2902.

3- Enable notifications by writing '0100' at that handle using:-

gatttool -b 00:11:22:33:44:55 --sec-level=high --char-write --handle=0xYYYY --value=0100

Where 0xYYYY is the handle of the CCCD descriptor that you noted in step 2. Once this happens, you should start getting indication data, which you can decipher using the temperature data structure found here.

You can find more information about using the BlueZ commands at the following links:-

I hope this helps.

0
votes

Maybe you could try the shell program gatttool or use app like nRF Connect to read.