OpenFenix / bluetooth-sniffer

Sniffer of bluetooth traffic between phone and watch
14 stars 3 forks source link

Heart rate #1

Open cagnulein opened 3 years ago

cagnulein commented 3 years ago

Did you find a way to read the heart rate via bluetooth in realtime as Garmin connect does?

nemanjan00 commented 3 years ago

I never got to finish this. Got back from vacation and since then had no time to work on it

cagnulein commented 3 years ago

Totally understandable :) Thanks

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno mer 9 giu 2021 alle ore 15:46 Nemanja Nedeljković < @.***> ha scritto:

I never got to finish this. Got back from vacation and since then had no time to work on it

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/OpenFenix/bluetooth-sniffer/issues/1#issuecomment-857708322, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAALYWF5GOBUSAGYRROXXKDTR5WD5ANCNFSM45WZVLAQ .

idealist1508 commented 2 years ago

I was able to read RealTime HR data on Swim2 with a following .Net Core code on linux For Vivomove HR I found this repo https://github.com/mormegil-cz/Gadgetbridge/tree/garmin-wip


using System.Text;
using HashtagChris.DotNetBlueZ;
using HashtagChris.DotNetBlueZ.Extensions;

var locker = new object();
async Task OnValueIn(GattCharacteristic sender, GattCharacteristicValueEventArgs e)
{
    lock (locker)
    {
        var value = e.Value;
        var hexString = BitConverter.ToString(value);
        Console.WriteLine(hexString);
        Console.WriteLine();
    }
}

if (args.Length < 1)
{
    var progName = System.AppDomain.CurrentDomain.FriendlyName;
    Console.WriteLine($"Usage: {progName} <GarminAddress>");
    Console.WriteLine($"Example: {progName} AA:BB:CC:11:22:33");
    return;
}

var deviceAddress = args[0];
var timeout = TimeSpan.FromSeconds(15);

var adapters = (await BlueZManager.GetAdaptersAsync());
if (adapters.Count == 0)
{
    throw new Exception("No Bluetooth adapters found.");
}
var adapter = adapters.First();

if (!await adapter.GetPoweredAsync())
    await adapter.SetPoweredAsync(true);

var device = await adapter.GetDeviceAsync(deviceAddress);
if (device == null)
{
    Console.WriteLine($"Bluetooth peripheral with address '{deviceAddress}' not found. Use `bluetoothctl` or Bluetooth Manager to scan and possibly pair first.");
    return;
}

Console.WriteLine("Connecting...");
await device.ConnectAsync();
await device.WaitForPropertyValueAsync("Connected", value: true, timeout);
Console.WriteLine($"Connected to {await device.GetNameAsync()}.");

await device.WaitForPropertyValueAsync("ServicesResolved", value: true, timeout);

var servicesUuid = "6a4e2800-667b-11e3-949a-0800200c9a66";
var inCharacteristicUuid = "6a4e2810-667b-11e3-949a-0800200c9a66";
var outCharacteristicUuid = "6a4e2820-667b-11e3-949a-0800200c9a66";

var multiChannelService = await device.GetServiceAsync(servicesUuid);
var inCharacteristic = await multiChannelService.GetCharacteristicAsync(inCharacteristicUuid);
var outCharacteristic = await multiChannelService.GetCharacteristicAsync(outCharacteristicUuid);
inCharacteristic.Value += OnValueIn;

Console.WriteLine("Use Control-C to quit.");
Console.WriteLine();

Console.WriteLine("Sende first Message");
byte[] firstMessage =  
  { 0, 5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
await outCharacteristic.WriteValueAsync(firstMessage, new Dictionary<string, object>());
await Task.Delay(1000);

Console.WriteLine("Register Real_HR service.");
byte[] registerHrServiceMessage = 
  { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0 };
await outCharacteristic.WriteValueAsync(registerHrServiceMessage, new Dictionary<string, object>());
await Task.Delay(1000);

await Task.Delay(-1);

await device.DisconnectAsync();
Console.WriteLine("Disconnected.");