Closed WouterJD closed 3 years ago
There are multiple sides to this
But it's noted as a feature request and if anyone likes to do a code-suggestion; I will gladly integrate into the code.
I'll +1 this. Adding Bluetooth support opens up the possibility of using more hardware such as phones, tablets/iPads and things like AppleTV that don't support ANT+ but run Zwift and other apps well.
Lots of work though.
https://github.com/jedla22/BleTrainerControl/blob/master/How-to%20FE-C%20over%20BLE%20v1_0_0.pdf
On Linux it should be no problem to create a BLE GATT server via bluez, on windows/mac no idea.
Protocol seems to be the same as used for ANT+
pybluez ?It's multi platform. https://github.com/karulis/pybluez
BLE part which is required to implement GATT is linux only and experimental.
Microsoft has a documentation how to implement a GATT server with c#. But this would require a python wrapper which would cause additional effort.
I'm interested in this feature since i have a tacx fortius (T1932) trainer laying around but no ant+ dongles (and my macbook only has only 2 usb ports.. 🙄)
Let me see if i can put something together.
Well; two USB-ports would do.
And if not, a USB-hub is a quick fix; avoiding the whole software development traject. Two USB-dongles (#61) and a USB-hub costs € 75,= and you are good to go this weekend :-)
Hi Wouter, I took the challenge and tried to get Bluetooth (BLE) working this weekend. I just rode my first couple of meters in Zwift on my Apple TV by running FortiusANT with BLE support on my MacBook. I'm Zwifting from Nijmegen btw.
Ok, so instead of implementing Bluetooth (BLE) support directly in FortiusANT i chose to handle the BLE functionality as a separate process in NodeJS. At startup, FortiusANT should start the NodeJS server so it can then communicate with it. Instead of writing data to an ANT+ dongle it can now send a message to the NodeJS server which will then handle the BLE stuff.
Would you be interested to include the changes in FortiusANT? If so, i would first propose some serious code refactoring tbh. It was quite hard to wrap my head around the code in the current state and fit the BLE part in.
Just let me know, i'd be happy to help :)
Marco; great work, compliments!👍 And yes i would integrate.
Als je wilt kunnen we wel een conference call organiseren om door te spreken op welke wijze te integreren
PS. Welke Tacx heb jij?
Hi @WouterJD congrats for your work. I came over here due to your comment https://www.strava.com/activities/4273307198. :) Learning Python is on my bucket list, maybe understanding your source code can be a good quest to start with :)
@marcoveeneman has done investigations; next steps are to engineer and integrate
Marco; great work, compliments!👍 And yes i would integrate.
Als je wilt kunnen we wel een conference call organiseren om door te spreken op welke wijze te integreren
@WouterJD Great, then i'll proceed with it. I'm using a Tacx Fortius Multiplayer T1932. I've sent you a message to setup the conference call.
guys, consider to implement the FE-C profile, too, with BLE, see issue #122 for rationale
We're working on it and implement stepwise with purpose a full implementation. I'd be curious to know why zwift does not support ANT/FE-C and Rouvy's ANT runs behind on Bluetooth...
Proposal is to transmit simultaneously on BLE and ANT+. I have to note that not all computers have BLE built in, not even laptops.
Best would be for Zwift to just support ANT+ FE-C on android tho... https://forums.zwift.com/t/ant-update/195323 https://forums.zwift.com/t/zwiftgame-android-faq-v-1-0-50775/465924 If there were enough requests for the feature, they would consider implementing it. Maybe the feature will be available soon and it would be a waste of effort implementing the conversion in FortiusANT.
Another option would be the NPE Cable ANT+ to BLE converter (https://youtu.be/HvrYcOyd7wA) which does support FE-C control. (Often mentioned in zwift forums).
As you can see i just opened a pull request where initial support for Bluetooth is added. It is working fine for me, but i would be very interested in results of other users. Please let me know if it works ok for you too or if you encounter any issues. Thanks!
Great work so far Marco. I've just cloned your PR and had issues to connect to 'Virtual Trainer' either through Tacx Training App or RGT Cycling on Android11 - Pixel3a. Pairing the mobile with the trainer directly asked for the pin connects and disconnects right away. FortiusAnt was started on OSX 10.14.6 > python3 FortiusAnt.py -b -t i-Vortex -g -a
Any logs you like to see? BTW, I'm from Germany
Hi @brauereik welcome in the FortiusANT community!
Great work so far Marco. I've just cloned your PR and had issues to connect to 'Virtual Trainer' either through Tacx Training App or RGT Cycling on Android11 - Pixel3a. Pairing the mobile with the trainer directly asked for the pin connects and disconnects right away. FortiusAnt was started on OSX 10.14.6 > python3 FortiusAnt.py -b -t i-Vortex -g -a
Any logs you like to see? BTW, I'm from Germany
Hi @brauereik, thanks for taking the effort in testing my PR! So if i understand correctly FortiusANT did actually start the BLE server and started advertising, nice, good to know that works for someone else as well.
To better understand why the connection was dropped there might be some information in a file called ble.log, which should be located in the pythoncode folder. Note that this file is currently overwritten each time you start FortiusANT. Can you provide the log file so i can have a look at it?
I installed both Tacx Training and RGT on my iPhone and both are connecting with the Virtual Trainer (I am thinking to rename this to FortiusANT for clarity). I guess this is an Android vs iOS issue. I'll have a look if there are some special requirements for Android to connect.
@brauereik I forgot to ask, what do you mean exactly by pin connects
?
It's odd: sometimes the BT device found on Android is called mini as in the OSX BT-settings ans sometimes VirtualTrainer.
Thanks! I had a look at the file but unfortunately i cannot deduce the issue from the log file at the moment. I'll look into how to improve logging there.
Regarding the pairing code: interesting, there are no secure characteristics which would require secure pairing, so i'm a bit surprised Android is asking for a pin here.
With the latest Update for Android 11 I can finally report success! I can finally test how it feels to have the trainers slope being controlled by RGT, which is planned for the weekend.
Hi, what is the motivation for a NodeJS based BLE support instead of Python based BLE support?
@marcoveeneman I know you have studied the subject, please provide the arguments @orrmany Would you think a platform indepent solution is available; please suggest
@brauereik Awesome! So with Android 10 it didn't seem to work, but with Android 11 it does?
@orrmany Motivation is that there doesn't seem to be a complete, cross-platform BLE server implementation available in python, at leas i couldn't find one yet. The bleno project has all of this, except it is in NodeJS instead of python. However, if you know a python library, that would be awesome and i'd be willing to convert this thing to 100% python.
For now, it is functional, which i think is very important in the first place. If the interface to the BLE functionality is abstracted correctly, we could swap the implementation from NodeJS to Python at a later point without much hassle.
@orrmany Motivation is that there doesn't seem to be a complete, cross-platform BLE server implementation available in python, at leas i couldn't find one yet. The bleno project has all of this, except it is in NodeJS instead of python. However, if you know a python library, that would be awesome and i'd be willing to convert this thing to 100% python.
FYI: I am not a Python programmer, so I have no experience. There are a number of libraries according to Google, say https://github.com/nccgroup/BLESuite, but I trust your judgement here. I was just curious, since in my work experience, mixing different programming technologies within the same project always leads to a maintenance hell.
mixing different programming technologies within the same project always leads to a maintenance hell
Agree...but I assume it's done because it's the best solution available
What would you suggest?
On short term, I can't suggest anything. On long term: learning Python is on my bucket list. After cleaning up my current hobby project (an ANT+ & BLE sensordata-logger using an Arduino compatible nRF52840 MCU) it sounds as a good hobby project for me. Don't hold your breath though, it would take at least a year for me, or more, considering my workload at my employer...
Wouter Dubbeldam notifications@github.com ezt írta (időpont: 2020. nov. 22., V, 13:32):
mixing different programming technologies within the same project always leads to a maintenance hell
Agree...but I assume it's done because it's the best solution available
What would you suggest?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/WouterJD/FortiusANT/issues/103#issuecomment-731740836, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD3DSNF3OIR6KO6IF2NBSWDSREAEBANCNFSM4Q5ZG2WA .
I have been looking for a cross-platform BLE library too and haven't found much. For the central role, Bleak looks really good, but unfortunately they decided against implementing the Peripheral role (which is what we really need). https://github.com/hbldh/bleak/issues/81 BLESuite seems to be Linux only (for now)?
So it looks like bleno is probably the quickest way forward. Having it as an optional feature that is only losely coupled through sockets is probably a good thing here. I do worry that people having to install extra depencies themselves may be a support nightmare in addition to the maintenance issue. So having a complete package for people to download on Windows might make sense.
I had a look at the bleno code as well and the way it is built has advantages as well as disadvantages. On Linux and Windows they seem to use libusb and essentially implement their own Bluetooth stack. This is similar to the situation with ANT:
On macOS it looks like they use a reverse-engineered, internal interface to the Bluetooth daemon instead of the official API. That is bad because it might break at any time. Apparently there is now a fork that uses the native API.
It would be nice if we could have the profile implementations in Python, so it would be easier to switch to a native backend in the future, but looking at the bleno architecture, that may not be feasible.
In principle, accessing the native BLE APIs from Python should now be relatively smooth:
But having to write and maintain three backends is not great either. If BLE support is made sufficiently modular, maybe we can have Node.js as a fall-back option and implement native support for one platform at a time.
I have done some tests with Marco's implementation.
(It crashes somewhere but that could be solved perhaps)
To make it work
install
then run
gyp ERR! find VS **********************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **********************
but node.js on windows requires (I do not know yet which of the two steps is really needed)
- visual studio (or)
- npm install --global windows-build-tools
and (on my system) this causes python 2.7.1 being installed, causing version issues
**I think it is a LOT of work, to get the bluetooth interface work.**
But yeah; you can use an old computer and run Zwift on your mobile device...
There are two approaches:
- It's an optional feature; only for the advanced user
- Do not implement since quite some users already have issues with the libusb installation; but that is mandatory for the Tacx USB device. They most likely will not be able to get through the bluetooth installation. It may cause a lot of issues ("helpdesk load")
Just sharing my thoughts at this point. Now I have the dongle, I would want to see it work.
At least on Windows, it is probably a better idea to package all the node.js stuff into a single executable rather than have the user set it up. It seems https://github.com/vercel/pkg should do the job, but someone with more node.js experience might want to weigh in.
The alternative is to go through the native Bluetooth LE API. That would solve a lot of problems: works with all BLE hardware, no zadig driver, can be Python-only. But it adds another big one: separate implementations for Windows, Linux and Mac. So likely would either be Windows-only or a lot of work.
Hi Wouter, I'm new to this all, so first of all thanks for your work and effort. I can start the bluetooth version without any error. I try to start in sim mode ( -a -n -s -b -d127 -g) The gui tells there a Bluetooth interface available, so next step should be pair a tablet / bike computer / smartphone when trying to do so, none of these devices find a FortiusANT Trainer I probably miss a step. FortiusANT.2020-12-23 12-00-09.log FortiusAntGUI.2020-12-23 12-00-10.log
Hi Wouter, I'm new to this all, so first of all thanks for your work and effort. I can start the bluetooth version without any error. I try to start in sim mode ( -a -n -s -b -d127 -g) The gui tells there a Bluetooth interface available, so next step should be pair a tablet / bike computer / smartphone when trying to do so, none of these devices find a FortiusANT Trainer I probably miss a step. FortiusANT.2020-12-23 12-00-09.log FortiusAntGUI.2020-12-23 12-00-10.log
Hi TacxBiker, I guess you started the version from #179 right? Currently Wouter and i are very close to finish integrating bluetooth. However this is done in two separate PRs. #179 implements the necessary logic inside FortiusANT python code, while #130 implements the specific bluetooth logic separately, you need both to get it working. When the two versions are merged, bluetooth support should work (note the setup required for starting Bluetooth in the doc folder of #130, we currently consider bluetooth an advanced feature since it requires extra setup for the user at the moment.)
Ho @TacxBiker Welcome to the FortiusANT community
I'm always curious to know who I communicate with, where FortiusANT is used and what configuration is used. Please tell me what bundle did you buy, and what brake and what head unit do you use? I would therefore appreciate that you introduce yourself; perhaps leave a comment under issue #14.
Hi,
when starting FortiusANT with bluetooth support I get the following error:
13:42:30,448: ... requests.post() error HTTPConnectionPool(host='localhost', port=9999): Max retries exceeded with url: /ant (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0828A4C0>: Failed to establish a new connection: [WinError 10061] Kan geen verbinding maken omdat de doelcomputer de verbinding actief heeft geweigerd'))
It seems the HTTP server for receiving the data from Fortius ANT isn't online
Is there a way to check that?
One step further. To start de server I simply can use this command in de \node folder
Node server.js
But then unfortunately the next error:
C:\Github\FortiusAnt\FortiusANTBLE\FortiusANT-master\node\node_modules\@abandonware\bluetooth-hci-socket\lib\usb.js:90 throw new Error('No compatible USB Bluetooth 4.0 device found!');
But there should be a right bluetooth device. I changed the driver with the zadig tool.
The bluetooth device I use has the following ID: USB\VID_0A5C&PID_21F1 so that should not be the problem.
And there we go:
I added a new device in the \bluetooth-hci-socket\lib\usb.js file
var VENDOR_DEVICE_LIST = [
{vid: 0x0CF3, pid: 0xE300 }, // Qualcomm Atheros QCA61x4
{vid: 0x0a5c, pid: 0x21e8 }, // Broadcom BCM20702A0
{vid: 0x0a5c, pid: 0x21f1 }, // Broadcom BCM20702A0
{vid: 0x19ff, pid: 0x0239 }, // Broadcom BCM20702A0
{vid: 0x413c, pid: 0x8143 }, // Broadcom BCM20702A0
{vid: 0x0a12, pid: 0x0001 }, // CSR
{vid: 0x0b05, pid: 0x17cb }, // ASUS BT400
{vid: 0x8087, pid: 0x07da }, // Intel 6235
{vid: 0x8087, pid: 0x07dc }, // Intel 7260
{vid: 0x8087, pid: 0x0a2a }, // Intel 7265
{vid: 0x8087, pid: 0x0a2b }, // Intel 8265
{vid: 0x0489, pid: 0xe07a }, // Broadcom BCM20702A1
{vid: 0x0a5c, pid: 0x6412 }, // Broadcom BCM2045A0
{vid: 0x050D, pid: 0x065A }, // Belkin BCM20702A0
{vid: 0x1286, pid: 0x204C }, // Marvell AVASTAR
{vid: 0x8087, pid: 0x0025 }, // Dell Precision 5530
];
Connection to an iPad in the Sufferfest app:
and with all the data:
@marcoveeneman you evaluate this?
FortiusANT receives just like it should the power from the CPT. But when the power goes up by 50W it doesn't feel like so. Maybe this has something to do with #173
Hi @TacxBiker, I see you got the BLE interface up and running eventually, great! The change you applied is something that would ideally be integrated in https://github.com/abandonware/node-bluetooth-hci-socket/blob/master/lib/usb.js, since this is part of the library we use. Can you open an issue + PR in that repository?
@marcoveeneman perhaps add a note in the documentation as long as not implemented. Merry Christmas🚴♀️🚴♀️
Hi, trying to get FortiusANT up and running on a raspberry pi 3..... So far FortiusANT starts, callibration works, but bluetooth is not working.
Can anybody point me out how to setup and use node.js of the BTLE support?
@marcoveeneman Done, see what happens. Thanks
Would it be possible to broadcast the data using bluetooth instead of ANT+, no dongle needed in this case.
Thanks a lot for this!
Originally posted by @mruzzon in https://github.com/WouterJD/FortiusANT/issues/61#issuecomment-688177189