Getting data from a wearable device in a custom application
Asked Answered
M

2

6

I'm planning to create a fitness android application. Among other things, I want some integration with wearable devices. The device I have at hand now is an Honor Band 4 (Huawei). I haven't found any clear explanations of how to approach this problem and if it's even possible.

My first idea was periodically getting data from the HuaweiHealth application and importing it inside mine. But it seems that the HuaweiHealth app doesn't play nice with others, as I haven't seen a way of accessing this data.

Another thing I came across is the Android Sensors API: https://developers.google.com/fit/android/ble-sensors Could I use this to get data from my Honor Band? I assume that this would only get me raw data and I would have to handle all the logic to get the accurate pedometer, heart rate meter, etc.

Any input would be appreciated.

Migrate answered 23/5, 2019 at 15:39 Comment(0)
D
9

I don't know much about Google Fit, so maybe it is easier to interact with the watch using that application. However, I will explain how I dealt with the Bluetooth communication in the past in a similar scenario

The device uses the protocol Bluetooth Low Energy for data transmission. First of all, you should read a general description of how the protocol works. A good start would be the Bluetooth SIG website.

The most important thing you need to know is what's the software model presented in the protocol: each device exposes a Generic Attribute Profile (GATT). The way I see it, the GATT is just an API: it says what data the device "offers" and how you can consume it from a client. You should get familiar with the following terminology:

  1. Characteristic: it's a data value transferred between client and server. For example, the device's current battery voltage.
  2. Service: A collection of related characteristics, which operates together to perform a particular function. For instance, the Health Thermometer Service includes characteristics for temperature measurement value and time interval between measurements.
  3. Descriptor: A descriptor provides additional information about a characteristic. For instance, a temperature value characteristic may have an indication of its units (e.g. Celsius), and the maximum and minimum values which the sensor can measure. Descriptors are optional, and each characteristic can have any number of descriptors.

The Bluetooth SIG specifies a complete list of common services and characteristics, and how to interact with them. Again, all that information is in their website.

So, what you need to do before you can start writing code to interact with the watch is to find out which services and characteristics the device exposes. The ideal thing would be that the manual, that came with the watch when you bought it, said something about it... but that's unfortunately probably not the case.

Therefore, you have to figure it out by yourself. First thing you can do is to download an app that let you connect to a BLE Device and explore its GATT profile. I recommend LightBlue Explorer. Using it, you can connect to the watch and find out the characteristics and services that are exposed by the device. Then, you go and read the specification in the Bluetooth SIG website and you have everything you need to start writing code.

However, manufactures of BLE devices are not limited to the services and characteristics defined by the Bluetooth SIG. They can create and implement their own. In the image below I am connected to a digital scale. As you can see, it has many "standard" services (User Index, Body Composition, Battery service, etc.) but surrounded by a red square you can see a service with five characteristics that have no name.

enter image description here

Since that service wasn't defined by the Bluetooth SIG, you need to do some reverse engineering (which can be very difficult and frustrating) to figure out what those characteristics mean and how to consume them.

What I did, was to download the device's official app, I enabled the Bluetooth Snoop HCI and started to interact with the device in as many different ways as possible. After that, I opened the Bluetooth Log with Wireshark and analysed the Bluetooth packets transmissions to try to deduct how to work with those device specific characteristics.

Finally, once you know how the Bluetooth GATT server works in the device, you are ready to write your own application to interact with it. I highly suggest that you use a library for the communication implementation, otherwise you will struggle a lot. The best one I have seen and used is RxAndroidBle (they have other versions of the library for different platforms).

It is a long process, and what I have a written here is only some general information so you have a point to start from.

Danny answered 23/5, 2019 at 16:13 Comment(3)
The problem that I have found is that the only way to connect to the Honor Band 4 is via the Huawei Health app, because it cannot be found on the list of bluetooth devices. That means I cannot examine it using the LightBlue Explorer. Something about this can be found here: uk.community.huawei.com/other-wearables-51/… With this in mind I guess the only way get data is by exporting it from the Huawei app, but I don't know if that can even be done. How is this handled inside other apps?Migrate
@Migrate well, I have done a quick research about the Huawei Health app and it seems it can't export data or integrate with other services (which sucks...), and apparently there isn't another workaround. I can probably be wrong since I don't know that app nor device, but I guess you will have to choose a different Band (check uk.community.huawei.com/software-40/…)Danny
That is the same info I got. Hoping for some input from someone who has used Google Fit and if could use it to get enough info from the phone itself, without needing a dedicated wearable.Migrate
L
0

Actually looking at the same responses... Thanks to @dglozano for explaining so far. My Huawei Band 3 pro give me some pain also... But, after looking a lot, I've found two interesting points :

  1. You can connect your device via LightBlue Explorer after killing Huawei Health app.

  2. I can sniff packages by using Wireshark on my Linux best distro after installing PCAP Remote on my Android and running

    $ssh [email protected] -p 15432 'pcapremote' > huawei.pcap

    after that, I run wireshark, open the file, refresh, and bang my head against the wall because I feel lost.

Good luck !

Lithographer answered 21/8, 2020 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.