cagnulein / qdomyos-zwift

Zwift bridge for smart treadmills and bike/cyclette
https://www.qzfitness.com/
GNU General Public License v3.0
435 stars 118 forks source link

[REQ] Support for Computrainer with USB connection #1085

Closed jra650 closed 1 year ago

jra650 commented 1 year ago

Is your feature request related to a problem? Please describe. No it would be a new connection type and a new supported trainer.

Describe the solution you'd like Computrainers are the old original smart trainer and are still in use by lots of riders. They can connect to Android Phones via USB with a FTDI to USB cable, There are many people looking for an Android solution for Computrainers. There is open source code from Golden Cheetah which connects to the Computrainer https://github.com/GoldenCheetah which can provide Computrainer specs and output signal information.

Ant Tester shows the Computrainer on my old Samsung Note 8. QZ (qdomyos-zwift) does not recognize the Computrainer on the Android phone. I am looking for a solution that will broadcast the Computrainer signal via ANT+ or BLE to another device for use with Zwift, Rouvy etc and receive a signal back to make the Computrainer a controllable trainer via this solution.

Describe alternatives you've considered There is a windows solution (https://perfprostudio.com/WebHelp/CTBridge/index.htm?page=Setup.html.) but this requires a laptop just to rebroadcast the Computrainer signal.

Additional context 20221218_104005

cagnulein commented 1 year ago

Perfect, this code is usable without changing anything https://github.com/GoldenCheetah/GoldenCheetah/blob/cabe078453cbe8e136b8adf8d4187a5be878671b/src/Train/Computrainer.cpp

Tomorrow I will implement it

cagnulein commented 1 year ago

@jra650 send me an email to roberto.viola83 at gmail.com indicating this ticket in order to add you to the internal tester. Thanks

cagnulein commented 1 year ago

first code commit done. I'm ready to test @jra650

jra650 commented 1 year ago

Roberto – Thank you. Yes I can test this if I can get a link to a downloadable app. - James

From: Roberto Viola @.*** Sent: Sunday, December 18, 2022 3:51 PM To: cagnulein/qdomyos-zwift Cc: jra650; Mention Subject: Re: [cagnulein/qdomyos-zwift] [REQ] Support for Computrainer with USB connection (Issue #1085)

first code commit done. I'm ready to test @jra650 https://github.com/jra650

— Reply to this email directly, view it on GitHub https://github.com/cagnulein/qdomyos-zwift/issues/1085#issuecomment-1356872765 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AT3CKXPTQA4PSA4GT7XP2Q3WN52K7ANCNFSM6AAAAAATCURKCM . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AT3CKXLG5HHU5TXET4CTU5LWN52K7A5CNFSM6AAAAAATCURKCOWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSQ4A6D2.gif Message ID: @.***>

cagnulein commented 1 year ago

as I said above send me an email with your google play account email

jra650 commented 1 year ago

Oh ok Sorry missed that. I purchased the app on the @.*** account. - James

From: Roberto Viola @.*** Sent: Monday, December 19, 2022 9:53 AM To: cagnulein/qdomyos-zwift Cc: jra650; Mention Subject: Re: [cagnulein/qdomyos-zwift] [REQ] Support for Computrainer with USB connection (Issue #1085)

as I said above send me an email with your google play account email

— Reply to this email directly, view it on GitHub https://github.com/cagnulein/qdomyos-zwift/issues/1085#issuecomment-1357784734 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AT3CKXLZFU66JI54RUZBACDWOBZD7ANCNFSM6AAAAAATCURKCM . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AT3CKXLV2YTSNWQPLAFXDMDWOBZD7A5CNFSM6AAAAAATCURKCOWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSQ5YTJ4.gif Message ID: @.***>

cagnulein commented 1 year ago

@jra650 you have to send me an email, github hides the email :)

cagnulein commented 1 year ago

@jra650 I thought I wrote the steps, my fault. In the bike section, computrainer setting serial device, put the serial device path that you see in the ant tester app. Be sure that it's exactly the same, with all the backslashes Press ok and restart qz If you still don't see anything in the metrics, send me a debug log from qz Let me know

jra650 commented 1 year ago

Ok... How do you see or get to the debug log... Not seeing that either and dont see any corresponding files on the phone under Android/data/... qdomyoszwift

Also to confirm what I'm typing in the serial address area is /dev/bus/usb/001 Correct? No device id or anything?

On Mon, Dec 19, 2022, 2:25 PM Roberto Viola @.***> wrote:

@jra650 https://github.com/jra650 I thought I wrote the steps, my fault. In the bike section, computrainer setting serial device, put the serial device path that you see in the ant tester app. Be sure that it's exactly the same, with all the backslashes Press ok and restart qz If you still don't see anything in the metrics, send me a debug log from qz Let me know

— Reply to this email directly, view it on GitHub https://github.com/cagnulein/qdomyos-zwift/issues/1085#issuecomment-1358148199, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT3CKXLPGB5RMWLOZQKLD2LWOCZCRANCNFSM6AAAAAATCURKCM . You are receiving this because you were mentioned.Message ID: @.***>

cagnulein commented 1 year ago

Ok... How do you see or get to the debug log... Not seeing that either and dont see any corresponding files on the phone under Android/data/... qdomyoszwift

Check here https://github.com/cagnulein/qdomyos-zwift/wiki/How-do-i-get-the-debug-log-in-case-something-doesn't-work%3F

Also to confirm what I'm typing in the serial address area is /dev/bus/usb/001 Correct? No device id or anything?

It would be my first guess too, put probably on android we might look for it. Let me check the debug log first

Do you see the tile at least?

cagnulein commented 1 year ago

@jra650 In the log I don't see any communication at all. I believe the serial port address is wrong.

In Linux a serial port has this prefix /dev/ttyS*

Maybe can you check on your device and a terminal app, if you see something similar? You can also attach here a bug report from android with the usb connected

Let me know

jra650 commented 1 year ago

Path for serial connection looked correct, a Terminal app apparently is not going to show USB path without root permissions. Not sure that this Android debugging report is going to show anything... Ant Tester show Computrainer attached at time of report bugreport-2022-12-19-16-50-07.zip

cagnulein commented 1 year ago

got it @jra650 <6>[ 1116.950157] [2: kworker/2:0:24001] usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0

so replace the current path of the serial port with

/dev/ttyUSB0

press ok and restart QZ

share a fresh log then

Let me know

cagnulein commented 1 year ago

@jra650 also update qz, i added some new debug log in order to understand if at least the port is open now with the new path

jra650 commented 1 year ago

Thanks for your continued work on this! Heres the log. No message at the top of the qz that it sees the Computrainer, and no lights on the Computrainer serial to USB cable (after an initial light when the cable is plugged into the phone) debug-Tue_Dec_20_10_08_17_2022.log Screenshot_20221220-100929

cagnulein commented 1 year ago

that's the reason

Tue Dec 20 10:08:20 2022 1671548900646 Debug: ../src/Computrainer.cpp virtual void Computrainer::run() openPort 13

error 13, let me check the meaning

cagnulein commented 1 year ago

error code 13(Permission denied). I guess we need to explore how can we access to serial port on android. A simple open and the new line on the manifest isn't enough. @jra650 Do you have an app on the play store (i'm not on android) that can open a serial port?

cagnulein commented 1 year ago

@jra650 this could help! https://github.com/xmaihh/Android-Serialport/blob/master/README_EN.md there is also an apk that you can try https://github.com/xmaihh/Android-Serialport/releases/download/v2.1/SerialportDemo.apk

Let me know if at least you can open the com port. If so I can add it to QZ

jra650 commented 1 year ago

I installed the SerialPortDemo, but its mostly in Chinese so a bit hard to understand. However I found USB Serial Terminal ... see images attached. I'm not certain of which commands I should send through the terminal. The USB Serial Terminal app could see and open the port, but it did not seem to communicate with the port. I attached an updated qz debug log anyway and can send an Android debug log if necessary.

Screenshot_20221220-112722_USB Serial Terminal Screenshot_20221220-112750_USB Serial Terminal Screenshot_20221220-113300_USB Serial Terminal debug-Tue_Dec_20_11_33_37_2022.log

cagnulein commented 1 year ago

using the chinese apk it's better only to check if you can open the port if it's possible for you. anyway tomorrow i will start also this implementation

jra650 commented 1 year ago

There is also this open source code from SRAM which bought the Computrainer assets: https://github.com/SRAM/RacerMateOne . This code is more related to the Computrainer than Android port issues ... but there may be something in there.

Also as mentioned... this project https://gitlab.com/bingham34/ble-computrainer-ftms/-/commits/main indicates he was communicating with the Computrainer.

cagnulein commented 1 year ago

@jra650 i already implemented the low layer code for the communications now we need an android project for the serial port. that's why we need to be sure about the chinese apk so i can use that one as a reference

jra650 commented 1 year ago

Any idea how I should set the parameters? When I opened the app, there was nothing in the /dev/... part of the lower left screen

this is their Sample image image

This is my screen shot. I tried changing the parameters but nothing showed in that /dev/ area Screenshot_20221220-120910_Serial Port API sample

cagnulein commented 1 year ago

mmm ok let's do in this way. i will fork this project and i will translate in english adding some debug log. i'm focused on this because if it's work it's very easy to implement.

cagnulein commented 1 year ago

i will do and i will create a new demo apk for you

jra650 commented 1 year ago

Great! I think its more what parameters to set. Not sure what the 123456 is at the bottom of the screen. Could that be the port#?? I tried 0 there as well.

cagnulein commented 1 year ago

ok good news @jra650 I found that I have a serial port that I can connect to my phone to test it myself! Also I saw the same problem of the simple apk that you saw too! So now i found this https://github.com/mik3y/usb-serial-for-android that works pretty well! I'm implementing it!

cagnulein commented 1 year ago

Implemented @jra650 It was very easy at the end! I'm sending a new one! I already tested with my FTDI, so at least the connection with the serial port and the writing is working for sure!

jra650 commented 1 year ago

OK Progress! The cable FTDI lights now light up and the Computrainer control box screen looks correct (indicating that its being controlled by a connected device). But the qz screen just indicates 'connecting' and I dont see speed or power etc.

debug-Wed_Dec_21_09_43_46_2022.log

cagnulein commented 1 year ago

great @jra650 found the issue buffer overflow!

let me check this

cagnulein commented 1 year ago

got the mistake, i'm fixing it

cagnulein commented 1 year ago

@jra650 new version online, i hope it fixed now (the issue is on the receive part, so i can't test directly)

jra650 commented 1 year ago

More progress. I'm seeing data on the qz screen even though the message at the top still says 'connecting' Not all data on the screen looks correct... speed was low, power was very high. A second phone shows the Samsung Note 8 (where the Comutrainer is connected) as a Heart Rate sensor, and its not clear that all the data from the Computrainer (which does not include heart rate) is being broadcast (or received).

debug-Wed_Dec_21_11_07_39_2022.log

cagnulein commented 1 year ago

A second phone shows the Samsung Note 8 (where the Comutrainer is connected) as a Heart Rate sensor, and its not clear that all the data from the Computrainer (which does not include heart rate) is being broadcast (or received).

with nrfconnect you can see that QZ is sending all the metrics that you're seeing in QZ itself. So you are also be ready to use zwift for example (of course we have to fix the wrong metrics first)

More progress. I'm seeing data on the qz screen even though the message at the top still says 'connecting' Not all data on the screen looks correct.

Great! What an improvement in only 1 day, isn't it? Don't care about the connecting... thing, it's just because that label is updated for bluetooth devices only, so it stays in that state because we are using the serial port

Let me check the metrics, we are in the Golden Cheetah territory (the metrics are parsed by the GC module), also i'm seeing some buffer overflow. So I'm gonna check the log and I will come back to you again

cagnulein commented 1 year ago

i got the issue GC didn't manage the case where the byte weren't in sync (for example GC code is expecting 7 byte but from android i'm getting first 4 bytes and then 3 bytes but the GC code is trashing all of them)

cagnulein commented 1 year ago

new version online @jra650

jra650 commented 1 year ago

I am not seeing data on this new version. The Computrainer appears to be conencted (lights on) but no speed, power or other data on the screen. The updated app would immediately crash, so I had to uninstall and reinstall. But believe I have setting done correctly since the Computrainer connected.

debug-Wed_Dec_21_12_33_55_2022.log

cagnulein commented 1 year ago

the crash happens (and it's something that i need to fix) when the serial port setting is different from blank and the serial port is not connected or already in use.

Anyway I guess I did something wrong in the last build, let me fix this

cagnulein commented 1 year ago

new version online @jra650

jra650 commented 1 year ago

Still no data on screen.

On Wed, Dec 21, 2022, 10:50 AM Roberto Viola @.***> wrote:

@jra650 https://github.com/jra650 new version online, i hope it fixed now (the issue is on the receive part, so i can't test directly)

— Reply to this email directly, view it on GitHub https://github.com/cagnulein/qdomyos-zwift/issues/1085#issuecomment-1361540218, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT3CKXI7HZ5H4ZKN4FQHZFDWOMRNFANCNFSM6AAAAAATCURKCM . You are receiving this because you were mentioned.Message ID: @.***>

cagnulein commented 1 year ago

share the log please @jra650

jra650 commented 1 year ago

Huh... sorry tried responding to the email vs uploading and log was attached but I guess didnt come through

debug-Wed_Dec_21_13_16_34_2022.log

cagnulein commented 1 year ago

got the issue, I have to complicate more the buffer on RX. Let me try Sorry for this try and error but we don't have any other way to do this, anyway we will got it for sure! The hard part is done :)

cagnulein commented 1 year ago

new version online @jra650

jra650 commented 1 year ago

OK Closer.... getting data, although the data is still erratic (see fit file). And Wahoo, Rouvy etc does not recognize data stream. (FIT file is in ZIP below)

This image is from NRFConnect, and seems to only show HR (unless I should be on another screen... not familiar with that app)

Screenshot_20221221_145636_nRF Connect

debug-Wed_Dec_21_14_43_44_2022.log 0QZ-backup-Wed Dec 21 14_43_46 2022.zip

cagnulein commented 1 year ago

all the ble services are good @jra650 which issue do you have in Wahoo RGT for example? are you using a second device for Wahoo?

I'm checking the log now

cagnulein commented 1 year ago

new version online @jra650 i found a little error in the rx buffer that could explain the wrong data sometimes. I'm going to bed now. Write your comments here so I will work on this tomorrow morning. Thanks

jra650 commented 1 year ago

OK Better - thanks for your continued work! Zwift sees the output as a controllable Wahoo Kicker. Not sure its getting more than just power (but thats fine). Issue continues to be that this data is not accurate.... in fact as soon as qz starts, power and speed values are shown (intermittently) without me pedaling. When I do pedal the data on qz does not seem accurate. (I can see speed and cadence from another sensor on a Garmin Edge display). If necessary I can record a simultaneous fit file with the Garmin which will show Speed, HR, cadence, and power (from another source but which should be within 20-30 watts of the calibrated Computrainer) to compare to what qz is seeing. Or I could calibrate the Computrainer and record 2 minutes at a steady speed with Golden Cheetah and then 2 minutes at that same speed with qz.

The fit logs from qz and Zwift are in the Zip file (AND I had to put the debug log in the Zip because it was over 30mb?? Fit.zip

cagnulein commented 1 year ago

Zwift sees the output as a controllable Wahoo Kicker

yes it's the wifi bridge, you have also the bluetooth bridge as well (you need probably to rename your phone as "bike" only 4 letters and reboot it, some samsung has some issue with long bluetooth names).

Not sure its getting more than just power (but thats fine)

yes you have to see everything: power, cadence, hr, and controllable

Or I could calibrate the Computrainer and record 2 minutes at a steady speed with Golden Cheetah and then 2 minutes at that same speed with qz.

checking the log I'm quite sure to have understood the issue. In order to be sure, it will be a great thing if you will be able to collect serial port communication from Golden Cheetah to Computrainer. In this way I can compare the traffic from QZ to Computrainer.

My idea is that on PC the frame are very clean because the serial driver works better. Here on android we have a lot of spare bytes that I have to filter. I have an idea to how do so, but I need a reference working in order to be 100% sure.

Let me know

cagnulein commented 1 year ago

with GC, you can collect serial port log with this for example https://freeserialanalyzer.com/