ptx2 / gymnasticon

Make obsolete and/or proprietary exercise bikes work with popular cycling training apps like Zwift, TrainerRoad, Rouvy and more.
https://ptx2.net/posts/unbricking-a-bike-with-a-raspberry-pi
MIT License
299 stars 39 forks source link

Support for resistance change #14

Open roberttod opened 4 years ago

roberttod commented 4 years ago

@ptx2 I was inspired after reading your dev notes a couple of months ago and ended up attaching a raspberry pi to my spin bike, https://www.diamondbackfitness.com/products/510ic-indoor-cycle . The down button for resistance was broken on the bike's built in screen so I replaced all of the logic with a pi and connected it to zwift using gymnasticon. Because of all the hardware involved I had to write the logic in python, which I connected to the "bot" bike using a UDP connection.

I built a custom UI (before I connected to zwift) where I can change the resistance, but changing apps from zwift to my UI to change resistance isn't the easiest thing to do while working out, so thought I'd try to build the BLE resistance change logic.

I've started to build out some BLE characteristics in this PR and the pi now shows up in zwift as supporting resistance change. I'm wondering if you could help point me in the right direction.

A couple of things I'd love some help with

Thanks so much for building this project and inspiring me, it's been nice to get back into electronics!

ptx2 commented 4 years ago

Hi, thanks for opening this, it would be excellent to add FTMS support!

I still need to read up on FTMS and I have only skimmed the PR so far, but just quickly: it looks like characteristic 2AD6 might still need to be implemented? (org.bluetooth.characteristic.supported_resistance_level_range)

I agree on the PDFs. It might be easier to start with the GATT XML spec and refer back to the PDF to fill in the blanks. The XMLs used to be on developer.bluetooth.org but I can't find them there anymore. They're all over the web though, e.g.:

https://github.com/oesmith/gatt-xml https://github.com/oesmith/gatt-xml/blob/master/org.bluetooth.service.fitness_machine.xml https://github.com/oesmith/gatt-xml/blob/master/org.bluetooth.characteristic.supported_resistance_level_range.xml

btmon(1) is very useful for catching things that don't bubble up to the app.

It may also be worth having a look at the websites of Nordic and SiLabs and other BLE chip makers, as they often have developer resources, blog posts, reference implementations, forums, etc.

I'll try to have a better look at this a little later, hope this helps, let me know how it goes!

roberttod commented 4 years ago

Thanks! That's exactly what I was looking for!

I'll leave the PR as a draft until I finish the implementation, it's only half done as it stands so might not be that much value but thought it was worth at least sharing where I'm at so far. Hopefully I'll be able to make some progress over the next couple of weeks.