Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Data From Fitness Tracker

I'm developing mobile app on Kotlin and I need to get data (ex. Heart Rate) from Fitness Tracker. But I don't find universal API for this task.

Also I know, that some fitness tracker like Mi Band, Huawei Watch has a official API, but I need a universal method.

like image 358
aptech Avatar asked Dec 22 '25 09:12

aptech


1 Answers

You must use a bluetooth library to connect to the device (fitness tracker).

Bluetooth devices such as fitness trackers communicate data through services. Every bluetooth device has its own set of services. Every service has multiple characteristics.

  1. Once you connect to the device, use the bluetooth library to get the list of services, that the device supports.

Every service has a UUID. You can check which service you need according to the UUID. Bluetooth has an official document for this purpose. You can refer to this: https://btprodspecificationrefs.blob.core.windows.net/assigned-numbers/Assigned%20Number%20Types/Assigned_Numbers.pdf

For example, if you need "heart rate" data, then you need the service with the UUID "0x180d".

  1. Once you find the service you wanted (in this example "0x180d"), get the list of characteristics present in that service. And get the official documentation for that service on this link: https://www.bluetooth.com/specifications/specs/

Go on the link, and search for the desired service (In our example, "heart rate service" i.e. "HRS". Read the documentation carefully on how to extract data. The documentation has the list of characteristics it supports and the format, the data is present in. Check what set of characteristics your device is supporting and work accordingly.

For heart rate, the characteristic you are looking for is "0x2a37". Again you can refer to the above links for this purpose.

  1. Once you have the desired characteristic, read the documentation of the characteristic, if you have to read the data or listen to the data over time.

For example, the heart rate characteristic "0x2a37", only supports listening to the data. The data you will get is a list of integers. You need to parse it into readable format. Refer to this answer for that purpose: https://stackoverflow.com/a/65458794/12555686

And there you have it, you need to follow these steps every time you need data for a certain activity.

One more thing, a lot of fitness trackers (MiBand, Firebolt, etc..) use custom services. For example, the steps data has to be communicated through the "Physical Activity Monitor Service" (PAMS), but MiBand doesn't have this service. It communicates the data regarding steps through its custom service "0xfee0" with the characteristic "0x0007". So that is going to be a tricky job.

You can refer to some GitHub repositories for this purpose. As of now, I know only some GitHub repositories and they are for MiBand. But I assume that other brands must also follow a similar pattern.

Here are the links to some projects:

  1. https://github.com/creotiv/MiBand2/tree/master (python)
  2. https://github.com/dkhmelenko/miband-android/tree/master (kotlin)
  3. https://github.com/simranss/my_fit (flutter) (this is not just for MiBand, but for every fitness tracker)
like image 151
Simran Sharma Avatar answered Dec 23 '25 23:12

Simran Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!