cagnulein / qdomyos-zwift

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

[REQ] Watch OS 10 CSC Bluetooth Data for Bike #1924

Closed keatontaylor closed 8 months ago

keatontaylor commented 8 months ago

Is your feature request related to a problem? Please describe. In WatchOS 10, apple added the ability for the Apple Watch to connect to various fitness devices for cadence, speed and power. I currently use the iFit subscription for my workouts but prefer to have my workouts recorded in apple health kit. I could sync the iFit workouts to HealthKit but I found them to be semi-inaccurate.

Describe the solution you'd like I'd like qdomyos-zwift to be able to transmit as an Apple Watch compatible health device via the CSC protocol.

A great example is here: https://github.com/dbsqp/bluetooth-reebok-57e

Describe alternatives you've considered The Apple Watch does detect the QZ companion app when running as a virtual bluetooth device currently, but no data appears to show up in the apple indoor cycling/running workout even with the watch connected to QZ.

Additional context For additional context, I am not attempting to connect my watches heart rate monitor to qdomyos-zwift. I am attempting to connect my watch so I can use Apple Watch workouts but have those workouts include the live data from qdomyos-zwift in real time.

If this is currently possible via settings please let me know, I was unable to get it working, even if the watch was able to detect QZ and pair with it, the metrics never showed in the Apple Watch workout. Please see https://github.com/dbsqp/bluetooth-reebok-57e again if you're curious how I ideally see this working.

cagnulein commented 8 months ago

you can do already but not via the iphone directly paired with the watch. you have to use an ipad, or a mac or an android device or a windows machine

Let me know

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno gio 28 dic 2023 alle 20:13 Keaton Taylor @.***> ha scritto:

Assigned #1924 https://github.com/cagnulein/qdomyos-zwift/issues/1924 to @cagnulein https://github.com/cagnulein.

— Reply to this email directly, view it on GitHub https://github.com/cagnulein/qdomyos-zwift/issues/1924#event-11352787957, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAALYWFQR34CQKAB2JEXS3TYLXAG5AVCNFSM6AAAAABBF2EXN2VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJRGM2TENZYG44TKNY . You are receiving this because you were assigned.Message ID: @.***>

keatontaylor commented 8 months ago

Yep, had discovered that during the troubleshooting phase, swapped to using qdomyos-zwift on an iPad which makes the health device discoverable as "QZ" on the watch. However, I am still not seeing the data from the bike on the watch.

My setup is: NordicTrack S22i with the QZCompanionNordictrackTreadmill app installed iPad Pro (3rd Gen - iOS 17.1.1) running qdomyos-zwift and accurately showing speed, inclination, watts, odometer. Watch Series 9 (watchOS 10.1) connected to the "QZ" health device. (does not appear to stay connected). Below are settings.

Under Experimental Features:

Under Treadmill Options:

All other settings default

cagnulein commented 8 months ago

if you see qz on the watch you are right. you need to several times this process because sometimes the watch is not getting it. in the bluetooth settings of the watch pair it and connect it. then open the apple fitness app and you will get it. it also works all the time with an android device

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno gio 28 dic 2023 alle 20:45 Keaton Taylor @.***> ha scritto:

Yep, had discovered that during the troubleshooting phase, swapped to using qdomyos-zwift on an iPad which makes the health device discoverable as "QZ" on the watch. However, I am still not seeing the data from the bike on the watch.

My setup is: NordicTrack S22i with the QZCompanionNordictrackTreadmill app installed iPad Pro (3rd Gen - iOS 17.1.1) running qdomyos-zwift and accurately showing speed, inclination, watts, odometer. Watch Series 9 (watchOS 10.1) connected to the "QZ" health device. (does not appear to stay connected). Below are settings.

Under Experimental Features:

  • Enable Virtual Device - ON
  • Virtual Device Bluetooth - ON
  • Bike Power Sensor - ON

Under Treadmill Options:

  • Proform/NodicTrack Options -> NodicTrack 295 IP - IP Address of bike

All other settings default

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

keatontaylor commented 8 months ago

I've definitely attempted multiple times, just curious there are any settings that I missing that ensure the bluetooth data transmitted is CSC that the Apple Watch accepts.

I can dig an android device out and see if that helps, but since I often have any iPad with me anyway was really hoping that would work.

Does the setting in "Treadmill as Bike" need to be enabled? Under Treadmill options? Or perhaps some other setting that I am missing?

cagnulein commented 8 months ago

nope that setting is not useful. you can also disable the bike power sensor setting and try without it. Let me know

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno gio 28 dic 2023 alle 20:56 Keaton Taylor @.***> ha scritto:

I've definitely attempted multiple times, just curious there are any settings that I missing that ensure the bluetooth data transmitted is CSC that the Apple Watch accepts.

I can dig an android device out and see if that helps, but since I often have any iPad with me anyway was really hoping that would work.

Does the setting in "Treadmill as Bike" need to be enabled? Under Treadmill options? Or perhaps some other setting that I am missing?

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

keatontaylor commented 8 months ago

I did try with and without it the power sensor, still no success getting it to show up on watchOS 10. Side note that might be related, cadence in the qdomyos-zwift is always zero, is this a misconfiguration as well or expected?

cagnulein commented 8 months ago

for sure that's the issue. if watchos get cadence 0 it's not connecting to it. so share a debug log with this issue, that's definitely the issue

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno gio 28 dic 2023 alle 21:10 Keaton Taylor @.***> ha scritto:

I did try with and without it the power sensor, still no success getting it to show up on watchOS 10. Side note that might be related, cadence in the qdomyos-zwift is always zero, is this a misconfiguration as well or expected?

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

keatontaylor commented 8 months ago

Attached is the debug log. debug-Thu_Dec_28_14_21_25_2023.log

cagnulein commented 8 months ago

found the issue. remove the ip from the nordictrack setting in the treadmill and press ok and set it instead on the nordictrack bike settings , tdf companion ip and press ok

keatontaylor commented 8 months ago

Cadence and resistance are correctly showing up in qdomyos-zwift iOS app now, connecting the Apple Watch to the QZ Bluetooth health device still shows no stats from the bike on the watch indoor bike workout.

Booting up an android device to try also reinstalling the qdomyos-zwift app on the iPad just incase I inadvertently messed up some settings.

cagnulein commented 8 months ago

i will record a video for you, maybe you are doing something different from me

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno gio 28 dic 2023 alle 21:49 Keaton Taylor @.***> ha scritto:

Cadence and resistance are correctly showing up in qdomyos-zwift iOS app now, connecting the Apple Watch to the QZ Bluetooth health device still shows no stats from the bike on the watch indoor bike workout.

Booting up an android device to try also reinstalling the qdomyos-zwift app on the iPad just incase I inadvertently messed up some settings.

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

cagnulein commented 8 months ago

done https://github.com/cagnulein/qdomyos-zwift/assets/48216/448505fd-2cd5-4385-9c6c-ed16498d9c8f

keatontaylor commented 8 months ago

Following your exact steps, still nothing coming in on the Apple Watch. Attempted an android tablet and the watch sees no bluetooth connection at all. Default settings with the exception of the IP for the bike under the bike settings within the android trial apk under releases. (also tried the nightly build)

cagnulein commented 8 months ago

ok android you need the bike power sensor . can you show me a video of what you are doing on ipad to watch?

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno gio 28 dic 2023 alle 22:30 Keaton Taylor @.***> ha scritto:

Following your exact steps, still nothing coming in on the Apple Watch. Attempted an android tablet and the watch sees no bluetooth connection at all. Default settings with the exception of the IP for the bike under the bike settings within the android trial apk under releases. (also tried the nightly build)

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

keatontaylor commented 8 months ago

Was able to get it to work for the power (watts) by turning off Airdrop (contacts only) on the iPad. I suspect that was messing with the bluetooth signal.

Should I also see cadence, distance, speed on the Apple Watch? I am not seeing those in your video and still not seeing them in the apple watch when doing the workout.

cagnulein commented 8 months ago

qz sends all of them but apple watch just use power and cadence as far as i know

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno gio 28 dic 2023 alle ore 22:52 Keaton Taylor < @.***> ha scritto:

Was able to get it to work for the power (watts) by turning off Airdrop (contacts only) on the iPad. I suspect that was messing with the bluetooth signal.

Should I also see cadence, distance, speed on the Apple Watch? I am not seeing those in your video and still not seeing them in the apple watch when doing the workout.

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

keatontaylor commented 8 months ago

hmm, cadence, speed, distance and power. are all supported via https://github.com/dbsqp/bluetooth-reebok-57e as of iOS 10. Also not seeing cadence come in on the Apple Watch.

cagnulein commented 8 months ago

yes but in order to send power (the most important one) qz must emulates a power pedal. power pedal can send only power and cadence. speed is based on cadence, and also distance of course. qz is also sending the other metrics by ftms but apple watch doesn't support it in order to send cadence on a separate way, qz will need to emulate a cadence sensor but apple watch is not smart enough to get 2 different sensors from 1 device only as far as I know. I will check the code of that project to see if I can do something different to better like to the apple watch. 11pm right now here, so I will go to sleep ;)

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno gio 28 dic 2023 alle ore 22:56 Keaton Taylor < @.***> ha scritto:

hmm, cadence, speed, distance and power. are all supported via https://github.com/dbsqp/bluetooth-reebok-57e as of iOS 10. Also not seeing cadence come in on the Apple Watch.

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

keatontaylor commented 8 months ago

thank you very much for all your help, truly appreciate it.

cagnulein commented 8 months ago

the reason why you can't see speed or distance is because cadence (note for me). i guess i understood why, apple watch wants them in a different way. i will check it tomorrow

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno gio 28 dic 2023 alle ore 23:03 Keaton Taylor < @.***> ha scritto:

thank you very much for all your help, truly appreciate it.

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

cagnulein commented 8 months ago

note: AW wants wheel count, that's why, i will add it :)

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno gio 28 dic 2023 alle ore 23:20 cagnulein @.***> ha scritto:

the reason why you can't see speed or distance is because cadence (note for me). i guess i understood why, apple watch wants them in a different way. i will check it tomorrow

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno gio 28 dic 2023 alle ore 23:03 Keaton Taylor < @.***> ha scritto:

thank you very much for all your help, truly appreciate it.

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

cagnulein commented 8 months ago

done @keatontaylor i did this for both android and ios. i tested and i can see correctly cadence now. The only thing that I can't understand it's how show speed and distance on the apple watch workout app for indoor bike. It doesn't give me the way. Are you able to see it somehow? I would like to ask to @dbsqp how can I show the metrics there. Anyway qz now is sending the metrics in the same way as https://github.com/dbsqp/bluetooth-reebok-57e/tree/AppleWatch-branch does

You can test it using the android build here https://github.com/cagnulein/qdomyos-zwift/commit/93779d04c50fbb211becdea4906533241c9a4e0f or send me an email to roberto.viola83 at gmail.com indicating this ticket to get the ios one.

Let me know!

dbsqp commented 8 months ago

Hope this helps

When implementing the bluetooth cycling power service (CPP) power, wheel revolutions and crank revolutions are reported. Power is instantaneous i.e. at time of notify event, whereas wheel and crank revolution counts also have an associated last trigger event time. Times are sent as an unsigned 16 bit integer that rolls over.

Cadence and speed (CSCS) service is the same without the power value but importantly the granularity of the last revolution tigger events is different between the two services i.e. 1s/2048 for power (CPP) and 1s/1024 for CSCS.

Note that for my use case of an exercise bike the cadence to wheel revolution is fixed and thus wheel count always has same ratio to that of crank.

With respect to the apple watch, when in CSC mode the wheel size is a variable set on the client as an option to the bluetooth device, default is 700c x 2.5mm. In contrast when in power meter mode this variable is not exposed. I don't know why wheel dimension is not exposed as a variable for CPP. I just assumed the default value and ensured I got the same cadence/speed on my watch for both CSCS and CPP mode as reported on my bike.

The main issues I had when developing my code was the different granularity and ensuring the correct rollover of the timestamp integers.

All speed and distance related metrics are calculated on the client device (watch) based only on the counts and difference in time between subsequent events. That is you send running count of revolutions (crank and wheel) and their respective last timestamps and the speed/distance is calculated on client based on their differences.

Note that in my code I only calculate speed and distance for the sake of debugging via serial output. To get matching values the dimensions of 700c wheel needed to be used thus I assume CPP is using this value.

cagnulein commented 8 months ago

Thanks @dbsqp for the detailed description! I did everything and cadence and power works great from iOS or Android to Apple Watch. The only thing that I can't understand is how enable the speed/distance metrics in the watch. When I go into the customization menu in the Apple Watch I can see only HR/CADENCE/POWER metrics but not speed or distance one. Am I missing something?

I'm saying this because in the screenshots of your github page i saw speed and distance

dbsqp commented 8 months ago

It might be that the instance of the CPP service implemented here is not reporting cumulative wheel revolutions and its associated time stamp i.e. only reporting power and cadence. I will have a look at the code but maybe one of the devs would know.

cagnulein commented 8 months ago

ehehe i'm the dev :) i'm reporting the timestamp, i guess it's something else, because even when i wasn't sending cadence, i was able to add the cadence metric (even if it was showing "--")

cagnulein commented 8 months ago

maybe it's the feature characteristic

// CP 32 bit/0-31 - 4/5:crankRev 3/4:wheelRev
  byte feature[1] = { 0b00000000000000000000000000001100 };

i will check this later.

dbsqp commented 8 months ago

OK. My code creates one service CSC (cadance/speed) or CPP (power/cadance/speed). For CPP I set the features using the raw binary flags that you just quoted and add the data to the packet send by notify. I found using a layer of abstraction confused and difficult to align with the BLU CPP specs. I think you are not declaring the feature, if you don't declare it data send will just be ignored by client.

I also think you can create combined services with BLU i.e. one device with CPC and HR etc. I did not do this hence using CPP as a superset of CSC.

cagnulein commented 8 months ago

I just tried and it makes no difference. I'm still thinking that it's something else. @dbsqp could you please add here a screenshot from your watch where you can customize the screen for the indoor ride adding the distance and speed metrics? maybe i'm ignoring something simple :)

dbsqp commented 8 months ago

2023-12-29 17-01 at incoming-6B94637E-ECA9-471B-B521-C223114B6D53 2023-12-29 17-01 at incoming-03619798-A226-4AC2-A6F3-1E102BB5D332 2023-12-29 17-02 at incoming-8F9C1E3B-4589-442B-952D-17756D0D37AD 2023-12-29 17-02 at incoming-75C77190-B404-4526-9677-566498F8670B

This just displays metric, if its not reported wont see a value. Can also see trend of metrics in iOS Fitness App under workout details > show more.

cagnulein commented 8 months ago

thanks! so yes for sure i need to do something else! thanks for your time! maybe it's a cache issue on the watch.

dbsqp commented 8 months ago

No problem. There was a reason I started with FMTS, then implemented CSC and when that was working setup CPP. I also think it is strange wheel dimension is not a variable. Is not cached by watch as since I developed my code I have clean installed my phone and watch and connected as only CPP and all works as expected (surprisingly). Although my code works there was much trial and error to get things working. Good luck!

cagnulein commented 8 months ago

@keatontaylor did you try the new beta?

keatontaylor commented 8 months ago

Hey @cagnulein the app appears to be working on occasion, having lots of bluetooth disconnection issues. Actually ended up working on @dbsqp code to modify it to fetch the UDP packets coming from QZCompanionNordictrackTreadmill and then just re-broadcast them via an ESP32.

This is working great for power, but I am having a really hard time calculating the cadence from just the RPM.

Any insights on how you're taking the RPM and converting it into crank/wheel count and time last crank revolution and last wheel revolutions?

cagnulein commented 8 months ago

hi @keatontaylor sorry to hear this, did you also try the android version?

for the cadence, check the module of @dbsqp is very easy to understand

keatontaylor commented 8 months ago

For the android version I am still unable to get it to show up as a bluetooth health device at all, but it could be some issue with the bluetooth on the tablet that I am using. I am unsure.

I had looked into the code written by dbsqp, and I do fully understand all the necessary values, crankCount, time of last crank, etc, but what I do not understand is how you're taking RPM from QZCompanionNordictrackTreadmill and converting it into crank count and time of last crank. (Same for wheel count, etc)

My understanding that might be wrong is that you're always increasing crank count by 1:

CrankRevs++;
LastCrankEventTime += (uint16_t)(1024.0 / (((double)(Cadence.value())) / 60.0));

So if I understand this correctly the following example would be true:

CrankRevs = 0 LastCrankEventTime = 0

New UDP packet from Bike reporting an RPM of 55

CrankRevs = 1 LastCrankEventTime = 1229 -> (1024 / (50 / 60) rounded up

Is this accurate?

keatontaylor commented 8 months ago

Alright got cadence and power correctly working on the watch via an ESP32 repackaging data from QZCompanionNordictrackTreadmill and publishing it over BLE via @dbsqp code.

Thank you both for your efforts, very happy to have this data liberated from NordicTrack's very closed ecosystem.

One additional side note: I am still unable to get the watch to show the speed/distance in real-time, but they do show up in the fitness app under the summary of the workout, need to fiddle with the wheelRotations vs. crankRotations to get them accurate but otherwise things are working exceptionally well.

Going to close this ticket as completed since I was able to get it working on the iPad as well, just not consistently.

cagnulein commented 8 months ago

Alright got cadence and power correctly working on the watch via an ESP32 repackaging data from QZCompanionNordictrackTreadmill and publishing it over BLE via @dbsqp code.

great!

Thank you both for your efforts, very happy to have this data liberated from NordicTrack's very closed ecosystem.

glad to hear this!

One additional side note: I am still unable to get the watch to show the speed/distance in real-time, but they do show up in the fitness app under the summary of the workout, need to fiddle with the wheelRotations vs. crankRotations to get them accurate but otherwise things are working exceptionally well.

yes it's what i'm seeing to! @dbsqp are you using any watchos beta? i can't explain this in any other way

Going to close this ticket as completed since I was able to get it working on the iPad as well, just not consistently.

ok but please keep me updated about this, i'm very curious about distance and speed, thanks

dbsqp commented 8 months ago

My Apple Watch Ultra 1 is running 10.2 (21S364). My code was developed on only release versions from 10.0 which implemented support for the cadence/speed/power sensors.

What I could do is log out the raw integers sent from my code, you can then at-least see if there is a problem. At the same time I can set my code to be in CSC mode and take some screenshots of the wheel dimension option.

dbsqp commented 8 months ago

One other thing to consider is to use the indoor not outdoor cycling workout. For the latter I think the speed/distance values are taken from GPS data not wheel revolution.

cagnulein commented 8 months ago

My Apple Watch Ultra 1 is running 10.2 (21S364). My code was developed on only release versions from 10.0 which implemented support for the cadence/speed/power sensors

are you able to update the watchos to the latest version to check that it's still working?

What I could do is log out the raw integers sent from my code, you can then at-least see if there is a problem. At the same time I can set my code to be in CSC mode and take some screenshots of the wheel dimension option.

sure it could be useful, maybe a constant wattage and cadence. let's say 100w and 100rpm. i'm using the CP mode

thanks

cagnulein commented 8 months ago

One other thing to consider is to use the indoor not outdoor cycling workout. For the latter I think the speed/distance values are taken from GPS data not wheel revolution.

yep right, always used indoor one

dbsqp commented 8 months ago

WatchOS 10.2 is current release. Have also uploaded serial logs to my project under /documentation/debug-*. There is the serial output of my code in power mode, the extract of the xml export from health under iOS and two images showing screens from iOS. Note that the rollover of my integers for crank/wheel times are synchronised as lastWheelK = 2 x lastCrankK. Also took screen grab of sensor in CSC mode with the option to set wheel dimension. 2023-12-30 17-00 at incoming-17B2350A-FBE9-4D3F-B5B3-25CE91FA5074

cagnulein commented 8 months ago

i see only the screenshot, where did you put the log? Thanks!

dbsqp commented 8 months ago

https://github.com/dbsqp/bluetooth-reebok-57e/tree/AppleWatch-branch/documentation

files starting debug-*

cagnulein commented 8 months ago

thanks! very helpful! I will compare them with mine!

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno sab 30 dic 2023 alle ore 18:35 dbsqp @.***> ha scritto:

https://github.com/dbsqp/bluetooth-reebok-57e/tree/AppleWatch-branch/documentation

files starting debug-*

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

keatontaylor commented 8 months ago

Alright, I got it working, the issue is that if the sensor has only ever reported supporting the Cycling Power Service the Apple Watch will not offer the ability to select putting speed/distance on the workout views.

I setup @dbsqp code, turned off USEPOWER so it would instead use the Cycling Speed and Cadence Service. Flashed to the ESP32 and then forgot the bluetooth health device and reconnected it. Then I could add the speed and distance to the workout view watch faces.

Next I reflashed my code that handles the UDP broadcast packet reading from the bike and sets up the Cycling Power Service. The watch preserves the settings and still allows you to see the speed/distance, since it is being reported by the BLE connection.

A few things worth noting:

Both of these are due to the fact that the reported speed on the bike is dependent on resistance. Instead after some trial and error I arrived at the following function.

// Calculate the wheel offset.
double wheelOffset = kphValue * 2.66;
lastWheelK = lastWheelK + (int)(2048.0 / (wheelOffset / 60.0));
wheelCount = wheelCount + 3;

This seems to get the best results regardless of the resistance selected in the bike, but I have no idea if they're actually accurate as I might be missing something.

cagnulein commented 8 months ago

so it seems a apple bug the fact that i don't see distance! good to know! thanks for the detailed feedback!

Roberto Viola Software engineer and open source enthusiast http://robertoviola.cloud

Il giorno sab 30 dic 2023 alle 21:49 Keaton Taylor @.***> ha scritto:

Alright, I got it working, the issue is that if the sensor has only ever reported supporting the Cycling Power Service the Apple Watch will not offer the ability to select putting speed/distance on the workout views.

I setup @dbsqp https://github.com/dbsqp code, turned off USEPOWER so it would instead use the Cycling Speed and Cadence Service. Flashed to the ESP32 and then forgot the bluetooth health device and reconnected it. Then I could add the speed and distance to the workout view watch faces.

Next I reflashed my code that handles the UDP broadcast packet reading from the bike and sets up the Cycling Power Service. The watch preserves the settings and still allows you to see the speed/distance, since it is being reported by the BLE connection.

A few things worth noting:

  • Setting the wheel rotations == crank rotations will result in inaccurate distance measurements.
  • Setting the last wheel trigger as a multiple of the last crank trigger (*2 for example) will result in inaccurate speed measurements.

Both of these are due to the fact that the reported speed on the bike is dependent on resistance. Instead after some trial and error I arrived at the following function.

// Calculate the wheel offset. double wheelOffset = kphValue * 2.66; lastWheelK = lastWheelK + (int)(2048.0 / (wheelOffset / 60.0)); wheelCount = wheelCount + 3;

This seems to get the best results regardless of the resistance selected in the bike, but I have no idea if they're actually accurate as I might be missing something.

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

dbsqp commented 8 months ago

So do we think that the wheel size is somehow cached on the client from previous device config where it was set? I also re-read the bluetooth spec for a power meter and searched a bit and only found crank-length being a user set variable. Anyway glad my code was of help.

keatontaylor commented 8 months ago

Yeah my guess is that if the wheel size is entirely on the apple side, if it isn't set, then apple just assumes the default.

I might play around with adjusting the wheel size in Cadence and Speed mode and see if that setting is preserved when moving back to Cycling Power mode.

Side note: does apple really not support the running speed and cadence service? I cannot find a single reference to them supporting this spec, but haven't modified the BLE code to just try it. Would be cool to get my treadmill integrated as well.