OpenTracksApp / OpenTracks

OpenTracks is a sport tracking application that completely respects your privacy.
https://OpenTracksApp.com
Apache License 2.0
1.01k stars 187 forks source link

Cadence sensor #1787

Closed janzen42 closed 8 months ago

janzen42 commented 8 months ago

Describe the bug I have a Coospo BK467. This sensor can be used as a speed sensor or cadence sensor. I have set it to cadence mode and I have added it as a Cadence sensor in the app settings however when I record an activity, the Cadence data field shows a dash for the device hardware address and a dash for the rpm. I have tested the sensor and it works as expected using the CoospoRide app.

To Reproduce

  1. Go to Settings, Bluetooth Sensors, Cadence, select BK467
  2. Add Cadence data field to layout and record activity.
  3. Rotate the cadence sensor on bike.
  4. Observe no readings in the cadence data field.

Screenshots Screenshot_20231214-141402_OpenTracks Screenshot_20231214-141426_OpenTracks

Technical information

dennisguse commented 8 months ago

The UI feedback is that OpenTracks did not connect to the sensor or that the sensor.is not configured (hence no address shown below the value). You may verify that the sensor is working with speed?

janzen42 commented 8 months ago

Yes, I just set it up as a speed sensor and it worked for speed. (I am testing using a stationary bike so I assume the speed isn't due to changes in gps location.)

dennisguse commented 8 months ago

How did you set the sensor into cadence mode beside attaching it to the crank? The BLE standard for these kind sensors allows to send two values (one for crank and one for wheel) that are reported. I guess back then the assumption was that one sensor may be able to measure both. So, if the sensor is reporting it's measurement as wheel rotation; OpenTracks will only handle it as wheel rotation.

Code for cycling cadence is in BluetoothHandlerCyclingCadence.

janzen42 commented 8 months ago

I do wonder what the sensor reports. I'm not sure how to dig into that. The sensor has two distinct modes that can be set by removing and replacing the battery. The sensor flashes a red light to indicate it is in speed mode and a blue light to indicate cadence mode. I believe the two modes are critical to it functioning correctly since when in speed mode it is mounted to the hub of the wheel and in cadence mode it is mounted to the crankshaft arm.

dennisguse commented 8 months ago

I see. Can you compile+start Open tracks via AndroidStudio? If so, you can log the sensor output and check what it is doing.

dennisguse commented 8 months ago

And you may check if the sensor in cadence mode is working as a speed sensor for OpenTracks.

korn806 commented 8 months ago

I have exactly the same error and can confirm the existance of this bug since the v4.9.6 update. My cadence sensor worked before that and is still recognized and works in other Apps without a problem.

dennisguse commented 8 months ago

@korn806 thanks. Then I broke something....

dennisguse commented 8 months ago

Can you check if #1789 fixes the problem?

janzen42 commented 8 months ago

I am trying but I'm quite unfamiliar with this process. I'm not sure where to start. Is there a tutorial you can recommend?

janzen42 commented 8 months ago

I managed to download the project and loaded it into Studio but now I'm getting a Gradle error so I'm working on figuring out why that is happening.

Gradle DSL method not found: 'setVersionCodeOverride()'

Possible causes:

Your project may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).

janzen42 commented 8 months ago

I managed to download the project and loaded it into Studio but now I'm getting a Gradle error and I can't figure it out. There must be something setup wrong in Visual Studio but I don't know what it could be.

`Build file '/home/janzen42/Downloads/OpenTracks-cadence-1787/build.gradle' line: 119

A problem occurred configuring root project 'OpenTracks-cadence-1787'.

org.codehaus.groovy.runtime.metaclass.MissingMethodExecutionFailed: No signature of method: com.android.build.gradle.internal.api.ApkVariantOutputImpl.setVersionCodeOverride() is applicable for argument types: (null) values: [null] Possible solutions: setVersionCodeOverride(int), getVersionCodeOverride(), setVersionNameOverride(java.lang.String), getVersionNameOverride()

dennisguse commented 8 months ago

@janzen42 quite good :D Code works for me... - can you try to remove line 114:124? It is just for building the nightly builds. So, removing this part and check what happens:

    applicationVariants.configureEach { variant ->
        variant.resValue "string", "applicationId", variant.applicationId

        if (variant.buildType.name == 'nightly') {
            variant.outputs.configureEach {
                setVersionCodeOverride(getVersionCode())
                setVersionNameOverride(getVersionName())
                outputFileName = "${applicationId}_${variant.versionCode}.apk"
            }
        }
    }
janzen42 commented 8 months ago

I got a successful build. What should I do next?

Starting Gradle Daemon... Gradle Daemon started in 503 ms

Configure project : fatal: not a git repository (or any parent up to mount point /) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

Task :prepareKotlinBuildScriptModel UP-TO-DATE

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD SUCCESSFUL in 7s

janzen42 commented 8 months ago

I tried to Run and I got this error.

`Executing tasks: [:assembleDebug] in project /home/janzen42/Downloads/OpenTracks-cadence-1787

Configure project : fatal: not a git repository (or any parent up to mount point /) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

Task :createDebugVariantModel Task :preBuild UP-TO-DATE Task :preDebugBuild UP-TO-DATE Task :mergeDebugNativeDebugMetadata NO-SOURCE Task :generateDebugResValues Task :dataBindingMergeDependencyArtifactsDebug Task :extractDebugSupportedLocales Task :generateDebugResources Task :generateDebugLocaleConfig Task :generateDebugBuildConfig Task :mergeDebugResources Task :packageDebugResources Task :javaPreCompileDebug Task :mapDebugSourceSetPaths Task :checkDebugAarMetadata Task :createDebugCompatibleScreenManifests Task :extractDeepLinksDebug Task :parseDebugLocalResources Task :processDebugMainManifest Task :dataBindingGenBaseClassesDebug Task :processDebugManifest Task :mergeDebugShaders Task :compileDebugShaders NO-SOURCE Task :generateDebugAssets UP-TO-DATE Task :mergeDebugAssets Task :compressDebugAssets Task :desugarDebugFileDependencies Task :processDebugJavaRes NO-SOURCE Task :mergeDebugJniLibFolders Task :checkDebugDuplicateClasses Task :mergeDebugNativeLibs NO-SOURCE Task :mergeDebugJavaResource Task :stripDebugDebugSymbols NO-SOURCE Task :mergeLibDexDebug Task :validateSigningDebug Task :writeDebugAppMetadata Task :writeDebugSigningConfigVersions Task :processDebugManifestForPackage Task :l8DexDesugarLibDebug Task :processDebugResources FAILED Task :mergeExtDexDebug

FAILURE: Build failed with an exception.

BUILD FAILED in 6s 32 actionable tasks: 32 executed`

janzen42 commented 8 months ago

I can confirm this fixes the bug! I had downloaded the zip so I figured that was the reason for all the errors. I cloned the project using command gh repo clone OpenTracksApp/OpenTracks -- --branch cadence#1787 and I made sure your change to line 72 of BluetoothRemoteSensorManager.java was actually there since I wasn't sure if I had the right branch. That looked good so I compiled and I ran it by pairing over wifi to my Moto G7. As you can see in the screenshot attached we have success! Screenshot_20231217-114428_OpenTracks (Debug)

janzen42 commented 8 months ago

This is probably a separate issue but I noticed that the stats display shows the the rpm number continuously when cadence is over 60 rpm but when the cadence is lower it shows the number for about a second and then shows the dash. The lower the cadence, the more the dash is displayed rather than the last measured value.

dennisguse commented 8 months ago

@janzen42 thanks for taking the time to test this. I will craft a new release now :dagger:

Regarding the <60 rpm: can you open a new issue for this?