zacharyedwardbull / pycycling

A Python package for interacting with Bluetooth Low Energy (BLE) compatible bike trainers, power meters, radars and heart rate monitors
https://pypi.org/project/pycycling/
MIT License
131 stars 25 forks source link

Add FTMS support #4

Closed zacharyedwardbull closed 1 year ago

zacharyedwardbull commented 3 years ago

I don't have time myself to implement this (nor do I have an FTMS compatible trainer to test with), but if anyone would like to give it a go, pull requests would be welcome!

The specification can be found here: https://www.bluetooth.com/specifications/specs/

tensorturtle commented 1 year ago

@zacharyedwardbull I just got a FTMS-compatible trainer (Elite Suito T) so implementing this is certainly on my to-dos!

zacharyedwardbull commented 1 year ago

That would be fantastic, thanks @tensorturtle! Are the other protocols (CPS and CSCS) working properly with the trainer?

tensorturtle commented 1 year ago

@zacharyedwardbull I'm almost finished with FTMS support. I can confirm that CPS and CSCS works perfectly with my trainer. A few thoughts / concerns:

  1. Compared to CPS and CSCS, FTMS provides much better measurements for speed and cadence because it has a much lower threshold and there is no need to postprocess the data.
  2. FTMS is designed to support not just indoor bike trainers but also treadmills and rowing machines, etc. Therefore many of the fields that I have implemented can't be tested and won't be useful in the pycycling context.
  3. There is a nebulous bluez bug that I can't find any information about, which looks something like: bleak.exc.BleakDBusError: [org.bluez.Error.Failed] Operation failed with ATT error: 0x80 (Unknown code). It happens once a while when bleak is writing a GATT characteristic. It's definitely possible to catch the exception and continue. I think I will create a separate issue for this because I don't know if it's a problem with my hardware.
zacharyedwardbull commented 1 year ago
  1. Compared to CPS and CSCS, FTMS provides much better measurements for speed and cadence because it has a much lower threshold and there is no need to postprocess the data.

Excellent! Both sound like good things :)

  1. FTMS is designed to support not just indoor bike trainers but also treadmills and rowing machines, etc. Therefore many of the fields that I have implemented can't be tested and won't be useful in the pycycling context.

That's fine, I guess maybe I should have picked a more general name for the library when I first released it!

There is a nebulous bluez bug that I can't find any information about, which looks something like: bleak.exc.BleakDBusError: [org.bluez.Error.Failed] Operation failed with ATT error: 0x80 (Unknown code). It happens once a while when bleak is writing a GATT characteristic. It's definitely possible to catch the exception and continue. I think I will create a separate issue for this because I don't know if it's a problem with my hardware.

Sorry I'm not able to help with this. https://github.com/hbldh/bleak/issues/174 might be relevant. I find this interesting:

I am working with a BLE device that will return an application specific ATT error response (between 0x80 - 0x9F, as required by the Bluetooth specification) when a characteristic is written with invalid data.

It sounds like the error might be thrown after writing invalid data, not sure if this is due to a bug in your code, or an issue somewhere else in the stack.