jonasoreland / runnerup

A open source run tracker
GNU General Public License v3.0
738 stars 275 forks source link

Nordic Semiconductor Heartsensor? #1066

Closed sdebaerd closed 2 years ago

sdebaerd commented 2 years ago

Hi

Would it be possible to support Nordic Semiconductor Heartrate sensor? It's a BLE sensor (NRF), with a public service and method for reading the heartrate.

Service: UUID: 0x180D

Method: UUID: 0x2A37 Properties NOTIFY

This would provide a huge list of cheaper smartware as additional devices and as end result more users.

Thanks in advance Keep it up!

Kind regards

gerhardol commented 2 years ago

If it is a normal BLE HR bsensor, it should be working already. If there is something special with the implementation or a different protocol, someone with the device need to add support, you need to debug.

sdebaerd commented 2 years ago

It's a BLE sensor of a sportswatch, not a regular BLE HR sensor like a garmin, polar band. Unfortunately the sensor is not being detected when selecting BLE. I think this is due to a minor difference in the protocol.

This is the information I already gathered in the meantime: The SDK library can be found here: https://github.com/NordicSemiconductor/Android-BLE-Library Android Testtool for the sensor(s): https://github.com/NordicSemiconductor/Android-nRF-Toolbox

I have the testtool running on my phone and it seems to contain all necessary objects: -Searching for supported devices -Connecting/Disconnecting -Heart Rate Monitoring reads

gerhardol commented 2 years ago

From what I see from the SDK, these could replace the existing implementation. BLE requires Android 4.3, there are some workarounds to make the app working before 4.3. Using these libraries will make the use more complicated. Ignoring less than 4.3 will affect 1% of the users, which is OK I believe (they will not get any updates when this is bumped, can not install new apps). There was some mentioning of Lollipop, which will affect another 1,5% which is more than I would prefer. The app currently uses the 4.3 API, they were changed in later versions, so this could be a good thing.

But it should be possible to add normal BLE devices in the current codebase. Most of the source code is here: https://github.com/jonasoreland/runnerup/blob/master/hrdevice/src/org/runnerup/hr/AndroidBLEHRProvider.java But adding devices without having access to them is really hard, unless you have full control of the APIs and devices.

sdebaerd commented 2 years ago

Thanks for your reply.

I will try to fork your repository and to implement it, using the/your default framework. What I will try, is to see if I can add the device to the list, as currently it's not visible and continue from there. I see you have a filter on Amazfit and Miband, from what I could find out so far, they're also using the same or a similar sensor, based on source code of the app used to connect to my watch, which is of a different brand. The sensor also allows connecting using GATT, so I somehow feel confident, it can be feasible to implement it in your existing logic, as the UUID for the service is already the same that is also used by Nordic.

sdebaerd commented 2 years ago

Just as what I was thinking, the Huawei pattern was blocking my device to be appearing in the result.

I have it working with this, however there are a lot more of these devices, I have a list of 10 to 15 devices, so it's a bit strange to hardcode this.

static final Pattern huamiPattern = Pattern.compile("(Amazfit +Bip|Mi +.*Band|FC EXPLORE_LE)");

Was there a reason, there was a filter on huawei only?

Thanks in advance

sdebaerd commented 2 years ago

Hereby a list of devices from the same white label manufacturer of the model I own. There are more, more recent editions, but I have to look for them: "PACIFIC 2_LE"; "G-Smart Sprint_LE"; "SW36_LE"; "WatchM1S_LE"; "M1_LE"; "R2_LE"; "R2J_LE"; "R2N_LE"; "WP5_LE"; "R2_JAPAN_LE"; "SMA-R2_LE"; "M4A_LE"; "M4S_LE"; "LOK01_LE"; "FIT W1_LE"; "GT04_LE"; "M4_LE"; "TK05_LE"; "TK04_LE"; "FC EXPLORE_LE"; "GarettMulti4_LE"; "M5S_LE"; "M5_LE"; "SMA-M5_LE"; "M6S_LE"; "M6_LE"; "M7S_LE"; "M7_LE"; "OV-Touch 2.6_LE"; "GT01_LE"; "SMA-M4_LE"; "SW302_LE"; "UP! Smart Connect_LE";

sdebaerd commented 2 years ago

Also found out how I can send alert messages to my watch over BLE, so will be looking to that part as well, as I want to be alerted if go in a higher zone than configured in RunnerUp, besides an audio cue. The alert message triggers a vibration on the watch, but allows to continue tracking, so that would be a better user experience.

gerhardol commented 2 years ago

Just as what I was thinking, the Huawei pattern was blocking my device to be appearing in the result. Was there a reason, there was a filter on huawei only?

I guess that was what was needed to get the device working... I did some kind of test myself I believe, cannot test myself right now as my BLE band stopped working. If you have a fix before Monday I will try to make a release, as Android 11 must be targeted on Monday and that makes it more difficult to set GPS always on. (But there will be releases soon enough anyway when I get to tune the existing PRs).

Also found out how I can send alert messages to my watch over BLE, so will be looking to that part as well, as I want to be alerted if go in a higher zone than configured in RunnerUp, besides an audio cue. The alert message triggers a vibration on the watch, but allows to continue tracking, so that would be a better user experience.

If that is general thing, it could be added to sound notifications, that should be notifications including toasts and notifications and allow multiple notifications in one workout.

sv2ramanan commented 2 years ago

I wrote the small mod to get the huami(amazfit) watches working when paired. I put in only the watches that I had (Bip and Mi band) as I didnt want to put in others without testing. My apologies, I should have monitored the thread and replied before.

sdebaerd commented 2 years ago

No worries, it was fun to debug. It has been a while.

sdebaerd commented 2 years ago

About my comment about the alerts. It is indeed better to have a regular android notification, as this can be configured to be pushed towards the watch, which also triggers the vibration, no need to do crazy BLE developments.

sdebaerd commented 2 years ago

Created a patch and pull request.

gerhardol commented 2 years ago

Changed in #1068