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

BLE Challenges, #78

Open
arsab opened this issue Sep 19, 2019 · 4 comments
Open

BLE Challenges, #78

arsab opened this issue Sep 19, 2019 · 4 comments

Comments

@arsab
Copy link
Contributor

arsab commented Sep 19, 2019

BLE Challenges,

When searching for new sensor the system find them during scan
but fail or takes many tries to recognize them as having supported service.

Could not find the reason….

We may have too many sensor around?
==> Would it make sense to scan only for supported services? to improve probability of support?

in BleScannerSDK21 add:

private final ScanSettings settings = new ScanSettings.Builder()
        .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
        .build();

private final ScanFilter HrFilter = new ScanFilter.Builder()
.setServiceUuid(ParcelUuid.fromString("0000180d-0000-1000-8000-00805f9b34fb"))
.build();

private final ScanFilter CscFilter = new ScanFilter.Builder()
.setServiceUuid(ParcelUuid.fromString("00001816-0000-1000-8000-00805f9b34fb"))
.build();

private final ArrayList<ScanFilter> Uuidfilters = new ArrayList<ScanFilter>(Arrays.asList(HrFilter, CscFilter));

and replace startScan parameters:

            scanner.startScan(Uuidfilters, settings, callback);        

// scanner.startScan(callback);

Issues are open on this subject:
#70

Workaround (last resort) not very elegent:

  • Edit the configuration database with name & mac address ;-(
  • Or configure the address of sensors?

——————

After we have Sensors recognized as supported and enabled.
Getting them connected is complex exercise, We have « Connecting… » for a while.
Some time, rescan or disable & enable works?

In order to keep connection and being able to work in parallel the system use
connectGatt( context, « autoConnect » …)

found that BLE on Android is not as straight forward as we would expect
It looks that one of key element to connect with « autoConnect » is to have the sensor in the cash beforehand.
But we have difficulty to get there…..

Workaround to have servers in the cache, if they have disappeared, e.g. reboot, Bluetooth off and back on…:

  • before launching AAT connect and disconnect the sensors to get them in « cache » with e.g. with nRF Connect

Good articles with references which may help:
https://medium.com/@martijn.van.welie/making-android-ble-work-part-1-a736dcd53b02
https://medium.com/@martijn.van.welie/making-android-ble-work-part-2-47a3cdaade07

and code examples:

https://github.com/NordicSemiconductor/Android-BLE-Library/blob/master/ble/src/main/java/no/nordicsemi/android/ble/BleManager.java#L140
https://github.com/NordicSemiconductor/Android-BLE-Library/blob/master/ble/src/main/java/no/nordicsemi/android/ble/BleManager.java#L563

https://github.com/weliem/blessed-android/blob/master/blessed/src/main/java/com/welie/blessed/BluetoothCentral.java#L543
https://github.com/weliem/blessed-android/blob/master/blessed/src/main/java/com/welie/blessed/BluetoothCentral.java#L563
https://github.com/weliem/blessed-android/blob/master/blessed/src/main/java/com/welie/blessed/BluetoothCentral.java#L609

@arsab arsab mentioned this issue Oct 3, 2019
bailuk added a commit that referenced this issue Oct 19, 2019
…), display message to user when reconnecting
bailuk added a commit that referenced this issue Oct 19, 2019
…is with SensorStateButton in MainActivity
bailuk added a commit that referenced this issue Oct 19, 2019
@dr-m
Copy link

dr-m commented Mar 2, 2020

Hi, a new user here. I just got the newest version (c443993, v1.18) via F-Droid. I did not manage to set up a minimal build environment on my Debian system yet. Some README.developer.md would be nice for developers who prefer minimal command-line tools and are not that familiar with Android development.

I tested with a heart rate sensor and a speed/cadence sensor, mostly on v1.17, for some hours. Even though the source code has some references to wheel circumference, I did not find it in the user interface, and it appears so that only the cadence is being displayed. I have a few wishes:

  • It would be really nice to get the data stored in the GPX file (including the wheel rotation pulses, or speed and distance information even when ‘redundant’ compared to the GPS data).
  • Audio notifications for sensor lost/connected. Each type of sensor could have its own sound sample that would be played in 2 tones: low-high for connection, high-low for loss. For example, a heartbeat sound.
  • Audio and visual notification for sensor out-of-bounds, with user-settable bounds. Again, with sensor-specific sound samples. This would say 'your heart rate is too high/low' or 'your cadence is too low/high'.
  • Audio and visual notification for progress, with user-settable intervals (time or distance).

Last, I noticed some typos. Because I do not have a working build environment, I would rather not open pull requests for something that I did not test myself. Here are some suggestions:

git grep -i satus
git grep -i conect

The first one is visible in the user interface. The "SENSOR_DISCONECTED" in the second one might also affect some external interface, so I am not sure if that can be changed.

@bailuk
Copy link
Owner

bailuk commented Mar 3, 2020

Hi,

Wheel circumference gets calculated from GPS samples. Information from the speed sensor is then used to display current speed inside the cockpit view.

WheelCircumference.java, CscService.java, CurrentSpeedDescription.java

Android Studio is the official development environment for Android.
For building with minimal Android SDK installed:

#!/bin/bash

export ANDROID_HOME=/home/user/Android/Sdk/

git clone  https://github.com/bailuk/AAT.git
cd AAT/
./gradlew assemble --stacktrace

ls -l app/build/outputs/apk/release/

bailuk added a commit that referenced this issue Mar 3, 2020
@dr-m
Copy link

dr-m commented Mar 3, 2020

Thank you, @bailuk! I will be busy with work for the next few weeks, but I am looking forward to return to this in the near future.
AAT is the first application of its kind that could satisfy my needs. MyTracks was somewhat promising back in the day (now living on as OpenTracks, but currently retaining only heart rate monitor support). OsmAnd never supported external sensors, and its complexity and potentially large RAM usage could increase the risk that a recording is aborted.

@dr-m
Copy link

dr-m commented Jun 4, 2020

Sorry, I have been too busy with work to contribute to this great application.

Meanwhile, I figured out that my combined speed/cadence sensor was not making contact with the spoke magnet. After I fixed that, the display started showing "Speed S" instead of "Speed GPS". A more obvious indication of "lost" speed sensor could be useful, especially when configuring the sensor for the first time. For cadence or heart rate, this is less of a problem, because you would directly see the measurement values.

I have an annoying problem with my BLE heart rate sensor. It keeps disappearing while I am recording. It will reappear and resume recording if I go back to the main screen and click on the Sensors button. I do not think that it is related to power savings, because on one ride, the HRM sensor disappeared while I was watching the screen. It should also not be a problem on the sensor side, because I never have to touch the sensor to resume the connection. (I could understand that the sensor enters power-saving mode if the connection to my body is too weak, but that does not seem to be the case.)

The non-BLE speed/cadence sensor has worked perfectly for the past 3 months.

Here is a sample from a recent ride where it seems that the heart rate measurements were lost for some time:

	<trkpt lat="60.235964" lon="24.981834"><ele>22.0</ele><time>2020-05-24T12:57:14.000Z</time><extensions>
		<heartrate>147</heartrate>
		<cadence>76</cadence>
	</extensions></trkpt>
	<trkpt lat="60.236014" lon="24.981964"><ele>22.0</ele><time>2020-05-24T12:57:15.000Z</time></trkpt>
	<trkpt lat="60.236063" lon="24.982085"><ele>23.0</ele><time>2020-05-24T12:57:16.000Z</time></trkpt>
	<trkpt lat="60.236110" lon="24.982195"><ele>23.0</ele><time>2020-05-24T12:57:17.000Z</time></trkpt>
	<trkpt lat="60.236156" lon="24.982302"><ele>22.0</ele><time>2020-05-24T12:57:18.000Z</time><extensions>
		<heartrate>153</heartrate>
		<cadence>71</cadence>
	</extensions></trkpt>
	<trkpt lat="60.236210" lon="24.982413"><ele>22.0</ele><time>2020-05-24T12:57:19.000Z</time></trkpt>
	<trkpt lat="60.236265" lon="24.982522"><ele>22.0</ele><time>2020-05-24T12:57:20.000Z</time></trkpt>
	<trkpt lat="60.236320" lon="24.982623"><ele>22.0</ele><time>2020-05-24T12:57:21.000Z</time></trkpt>
	<trkpt lat="60.236377" lon="24.982730"><ele>22.0</ele><time>2020-05-24T12:57:22.000Z</time><extensions>
		<heartrate>155</heartrate>
		<cadence>0</cadence>
	</extensions></trkpt>
	<trkpt lat="60.236429" lon="24.982833"><ele>22.0</ele><time>2020-05-24T12:57:23.000Z</time></trkpt>
	<trkpt lat="60.236477" lon="24.982933"><ele>23.0</ele><time>2020-05-24T12:57:24.000Z</time></trkpt>
	<trkpt lat="60.236523" lon="24.983028"><ele>23.0</ele><time>2020-05-24T12:57:25.000Z</time></trkpt>
	<trkpt lat="60.236569" lon="24.983126"><ele>23.0</ele><time>2020-05-24T12:57:26.000Z</time><extensions>
		<cadence>0</cadence>
	</extensions></trkpt>
	<trkpt lat="60.236614" lon="24.983206"><ele>22.0</ele><time>2020-05-24T12:57:27.000Z</time></trkpt>
	<trkpt lat="60.236657" lon="24.983289"><ele>22.0</ele><time>2020-05-24T12:57:28.000Z</time></trkpt>
	<trkpt lat="60.236702" lon="24.983372"><ele>22.0</ele><time>2020-05-24T12:57:29.000Z</time></trkpt>
	<trkpt lat="60.236746" lon="24.983460"><ele>22.0</ele><time>2020-05-24T12:57:30.000Z</time><extensions>
		<cadence>72</cadence>
	</extensions></trkpt>
	<trkpt lat="60.236785" lon="24.983547"><ele>21.0</ele><time>2020-05-24T12:57:31.000Z</time></trkpt>
	<trkpt lat="60.236812" lon="24.983653"><ele>21.0</ele><time>2020-05-24T12:57:32.000Z</time></trkpt>
	<trkpt lat="60.236841" lon="24.983754"><ele>21.0</ele><time>2020-05-24T12:57:33.000Z</time></trkpt>
	<trkpt lat="60.236869" lon="24.983858"><ele>21.0</ele><time>2020-05-24T12:57:34.000Z</time><extensions>
		<heartrate>88</heartrate>
		<cadence>17</cadence>
	</extensions></trkpt>
	<trkpt lat="60.236908" lon="24.983962"><ele>21.0</ele><time>2020-05-24T12:57:35.000Z</time></trkpt>

It is likely that I manually re-enabled the heart rate sensor during this recording snippet, but I am not entirely sure. If it helps, I can try to look up a better sample where I clearly remember that the display was active when AAT stopped reporting the heart rate.

(Side note: I find it somewhat strange that the cadence is being logged only once per 3 or 4 seconds. Does the sensor really deliver data so seldomly? The pulse rate should be 1 Hz already at 60 rpm, and I have the impression that the AAT display would refresh the cadence data about once per second.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants