Android(Xamarin) How to get data(pulse) from the bracelet via Bluetooth

Viewed 676

My goal is to get data (pulse) from the fitness bracelet Torntisc T1 using my application and independently process data from the bracelet.

To implement I use Xamarin and found a Bluetooth LE plugin for Xamarin plugin to connect to the device and receive data from it. However, all the characteristics obtained are called "Unknown characteristic" and in values ​​of 0 bytes. Although it has 5 services, each of which has 3 characteristics. The only name of characteristics in 1 service is other: "Device Name", "Appearance", "Peripheral Preferred Connection Parameters". However, the value (value) is everywhere 0 bytes. How to get characteristics? How to get a pulse?

To the bracelet there is an application H Band 2.0, which shows a fairly large number of settings for the bracelet, the question arises where is all this?

Native app H Band 2.0. Attempt of decompile here. I found the classes responsible for the connection in the following directory: sources\no\nordicsemi\android\dfu. I see what has been done via BluetoothGatt. Unfortunately I am not an expert in java and android, unfamiliar with this library. I didn't find any methods or anything related to the "pulse", but a large number of magic parsing characteristics: parse (characteristic)

foreach (var TestService in Services)
            {
                var characteristics = await TestService.GetCharacteristicsAsync();
                foreach (var Characteristic in characteristics)
                {
                    var properties = Characteristic.Properties;
                    var name = Characteristic.Name;
                    var serv = Characteristic.Service;
                    var value = Characteristic.Value;
                    var stringValue = value.ToString();
                    string result = "";
                    if (value.Length != 0)
                        result = System.Text.Encoding.UTF8.GetString(value, 0, value.Length - 1);
                }
            }

enter image description here

1 Answers

To start with you can use the following app to get a better overview of the services and characteristics you are working with, without having to code calls to get the values you need.

Having said that you will need documentation to be able to communicate with the device, what I mean is what data you send, what are acceptable responses how they map to meaningful data etc. The core of BLE is the low energy bit which means exchange as little data as possible ex. mapping integers to enum values which you do not know without the documentation, you can work your way back from decompiled source but it will be orders of magnitude more difficult.

One more thing is that BLE is notoriously unreliable (you will understand if you run into gatt 133 errros on samsungs :), so most implementations also have a sort of added network layer to handle drops and graceful degradation, as well as sending larger peaces of data, this is custom developed per app/device and you also need extensive documentation for this to implement it, which is no trivial matter.

The library you've chosen is quite good and wraps most things you need quite well but it does not handle the instability so you have to take care of that part yourself.

Cheers :)

Related