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.
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.
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".
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With