Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth support #130

Merged
merged 45 commits into from
Dec 24, 2020
Merged

Bluetooth support #130

merged 45 commits into from
Dec 24, 2020

Conversation

marcoveeneman
Copy link
Contributor

@marcoveeneman marcoveeneman commented Nov 8, 2020

Adding Bluetooth support to FortiusANT

This pull-request adds initial and experimental support for BLE (Bluetooth Low Energy) to FortiusANT, as requested in #103. Bluetooth can be enabled by starting FortiusANT on the command line with the -b option.

The current implementation has been tested using the following setup:

  • Tacx Fortius T1932
  • MacBook Pro 2015 running macOS Catalina
  • Zwift running on AppleTV4 with tvOS 14.0.2

FortiusANT currently implements the following BLE services to connect to Zwift:

  • FTMS: FiTness Machine Service
    • Indoor Bike Data Characteristic, for sending power and cadence
    • Fitness Machine Control Point Characteristic, for receiving simulated bike information like wind speed, grade, wind resistance coefficient and rolling resistance coefficient.
  • HRS: Heart Rate Service
    • Heart Rate Measurement Characteristic, for sending heart rate

Testing

Before merging, i would like to ask all interested users to give this version a try and provide some feedback on the experience to increase the quality of this delivery. BLE support has not been tested on Windows yet so i would be very interested in the results of that.

Installation

The BLE support has been implemented in a separate process running on NodeJS. In order to use BLE support, you must install NodeJS and install dependencies required for the BLE implementation. See doc/bluetooth.md.

Fixes #103

@WouterJD
Copy link
Owner

Well Marco this looks like promising.
I have done a quick look and integration of bluetooth is the next step; after TCXexport which has cost too much time since I overlooked the obvious. I think FortiusANT 4.0 is a nice target to give the new interface some grandeur :-)

What I see is that master devices are implemented (heartrate, cadense, power).
Useful would be to add FE-C to be complete.

I see that the implementation is thought of being an alternative to ANT+; this can only be true of FE-C is implemented. Is that difficult?

There is quite some code in FortiusAntBody; perhaps it's good to centralize that in ble.py through a function; now we can.

I need some guidance in using github correctly; how should I download your code and review/test it without overwriting the master. Should I create a branch? How do I link that to your code? confcall needed?

Thanks for assisting anyway. Nice project!

@marcoveeneman
Copy link
Contributor Author

Well Marco this looks like promising.
I have done a quick look and integration of bluetooth is the next step; after TCXexport which has cost too much time since I overlooked the obvious. I think FortiusANT 4.0 is a nice target to give the new interface some grandeur :-)

What I see is that master devices are implemented (heartrate, cadense, power).
Useful would be to add FE-C to be complete.

I see that the implementation is thought of being an alternative to ANT+; this can only be true of FE-C is implemented. Is that difficult?

There is quite some code in FortiusAntBody; perhaps it's good to centralize that in ble.py through a function; now we can.

I need some guidance in using github correctly; how should I download your code and review/test it without overwriting the master. Should I create a branch? How do I link that to your code? confcall needed?

Thanks for assisting anyway. Nice project!

Hi Wouter, thanks! I'm happy you like it so far. I like your idea of introducing it officially in a 4.0 version of FortiusANT :)

Indeed, heart rate power and cadence are integrated, as well as the FTMS characteristic which allows controlling FortiusANT. I had a quick look at FE-C and i think it should not be too hard to add. If i'm not mistaken it is ANT+ FE-C protocol messages over BLE interface right? What would exactly be the added benefit next to the FTMS service?

I agree, FortiusAntBody is getting quite big. It would be good to split it into logical parts, i'd be happy to help with that.

Let's setup another call, i think that would be the easiest, and i can explain a couple of things :)

@WouterJD
Copy link
Owner

FTMS characteristic or FE-C

I do not know the difference; The purpose is that Zwift recognizes the device and can control it - without ANT+. We'll have a chat...

…wind speed/grade/wind resistance and rolling resistance used in FortiusANT
@marcoveeneman marcoveeneman marked this pull request as ready for review December 22, 2020 16:46
@marcoveeneman
Copy link
Contributor Author

I removed all python related code as discussed by @WouterJD and me. The python integration will happen separately. This PR adds the foundation for BLE support in FortiusANT.

This can be reviewed and merged if everything looks ok.

…figuration descriptors, these are provided internally by bleno when required
…cteristic and move the logic to the onReadRequest handler
@WouterJD
Copy link
Owner

Marco, would you mind adding a VersionID (returned by read()) so that FortiusANT knows what version we're talking to?

When people download through git, the set will be consistent.
Windows .exe users may download the new .exe and forget the node-directory. It would be nice to be able to see that back in the logfile for support-reasons.

@WouterJD
Copy link
Owner

In addition to documentation:

Under installation
General
To enable Bluetooth support, three installation steps must be performed

  • Install Nodejs software,
  • Update USB drivers with Zadig
  • Compile the nodejs package

The system is then prepared for FortiusANT to use it, no software is yet active.
FortiusANT will start/stop the Bluetooth bridge (server.js) which exchanges commands between FortiusANT and the Cycling Training Program such as Zwift.

Step 2.
after "which will install the necessary tools" (including python!); this will take quite some time (so don't be impressed)

Step 4.
After Start Zadig add: Select options, list all devices

Note: It may be difficult to know which device is the onboard and which is the BLEdongle (on my system they have the same name). Since I do not use bluetooth, I disable the onboard bluetooth in device manager before inserting the BLEdongle.

Step 5. This may be cryptic for windows users.
Start windows command prompt click Start and type cmd <enter>
Go to [the FortiusAnt folder]\node (cd FortiusAnt\node <enter>)
Type npm install <enter>

Run
"After FortiusANT has detected the Tacx trainer it will start the BLE interface." --> "When [Start] is pressed the BLE interface will be activated untill [Stop]."

PS: FortiusAntBody initiates the Open/Close, FortiusAntBody does not get a signal that the program is stopped. Therefore on Start/Stop.

@marcoveeneman
Copy link
Contributor Author

marcoveeneman commented Dec 23, 2020

Marco, would you mind adding a VersionID (returned by read()) so that FortiusANT knows what version we're talking to?

When people download through git, the set will be consistent.
Windows .exe users may download the new .exe and forget the node-directory. It would be nice to be able to see that back in the logfile for support-reasons.

How about a /version endpoint returning the version information? This can be queried when starting the BLE server for example.

I'll also try to update the documentation as you suggest.

@marcoveeneman
Copy link
Contributor Author

Ready for another review

@WouterJD WouterJD merged commit bfebf09 into WouterJD:master Dec 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Please implement Bluetooth support
2 participants