Closed leaskovski closed 3 years ago
Thanks @leaskovski Glad that it works for you. I'll add the Nokia 7 plus into the README.
I had the same question earlier. It looks like the bluetooth hardware can do BLE advertising (what this app does) and connect to other BLE devices at the same time (may really depends on what bluetooth hardware an Android device has). However the same device can not receive the BLE advertising from itself. So the answer is no, it cannot.
Out of curiosity I've tried myself to advertise ANT+ heart rate sensor with this app, and on the same phone Strava app can't see the BLE heart rate sensor created by this app.
Hmm ok, thats a shame. So I have an old Nexus 5, and the ANT+ enabler software that is available on the Play store. It took some effort to get it working again to enable ANT+ on it, but I managed to get it working. I tried the software, and it can pick up my heart strap and show me my heart rate, which is good, but none of my BLE sensor apps are showing it up, so my guess is the BLE side isn't working properly for it. The nexus 5 is running Android 6.0.1.
I never know Nexus 5 has ANT+ support.
For this app to work, the phone has to support BLE advertising. A quick search gives me this: https://stackoverflow.com/questions/26441785/does-bluetoothleadvertiser-work-on-a-nexus-5-with-android-5-0
Looks like Nexus 5 doesn't support BLE advertising unfortunately. However maybe there are some third party work that also enables this feature?
@starryalley hmm, ok, so I thought I would try the app on the Nokia 7 plus properly, and it doesn't show up in the Zwift app or RGT, so it looks like it might not have advertising either. Is there anyway to find out be it via logcat or some other method?
Edit: Actually, it must have BLE Advertising purely because the COVID 19 app for the UK is installed and says its functioning properly, otherwise surely that wouldn't be working?
If you can check logs about this app through logcat, you can see if BLE advertiser is present: https://github.com/starryalley/CSC_BLE_Bridge/blob/35b1006aa3497556c49e19055439c54cde7d0435/app/src/main/java/idv/markkuo/cscblebridge/CSCService.java#L451
If advertiser is there, check if the BLE advertising really started: https://github.com/starryalley/CSC_BLE_Bridge/blob/35b1006aa3497556c49e19055439c54cde7d0435/app/src/main/java/idv/markkuo/cscblebridge/CSCService.java#L537
If there is any errors there, please paste it here if possible. Thanks.
I used the "Logcat Reader" app (https://play.google.com/store/apps/details?id=com.dp.logcatapp&hl=en_GB&gl=US) to filter out for cscservice. It came up with the following on startup...
[01-11 22:40:45.666 1557:4654 W/ActivityManager]
Scheduling restart of crashed service idv.markkuo.cscblebridge/.CSCService in 1000ms
[01-11 22:43:02.018 28689:28689 D/CSCService]
Service started
[01-11 22:43:02.018 28689:28689 D/CSCService]
requesting ANT+ access
[01-11 22:43:02.301 28689:28689 D/CSCService]
Bluetooth enabled...starting services
[01-11 22:43:02.325 28689:28689 D/CSCService]
CSCP enabled!
[01-11 22:43:02.330 28689:28709 I/CSCService]
onServiceAdded(): status:0, service:android.bluetooth.BluetoothGattService@abd7590
[01-11 22:43:02.333 28689:28689 D/CSCService]
HR enabled!
[01-11 22:43:02.333 28689:28689 D/CSCService]
Enumerating (1) BT services
[01-11 22:43:02.333 28689:28689 D/CSCService]
Services registered: 00001816-0000-1000-8000-00805f9b34fb
[01-11 22:43:02.334 28689:28689 D/CSCService]
Service onStartCommand
[01-11 22:43:02.334 28689:28709 I/CSCService]
onServiceAdded(): status:0, service:android.bluetooth.BluetoothGattService@9dd1e89
[01-11 22:43:02.377 28689:28689 W/CSCService]
LE Advertise Failed: 1
[01-11 22:43:02.377 28689:28689 V/CSCService]
No subscribers registered
[01-11 22:43:02.377 28689:28689 V/CSCService]
Updating UI: speed:0.0, cadence:0, hr 0, speed_ts:0, cadence_ts:0, 0
I've updated the title to reflect that this is actually to do with device support.
BTW, I also confirmed that the Nexus 5 doesn't register the advertiser properly, it produces the same error you mentioned.
LE Advertise Failed: 1
1 means ADVERTISE_FAILED_DATA_TOO_LARGE.
Not sure why this happens on this specific device. Maybe the hardware support is a bit different. If you can, can you try remove this line: and compile/run again? https://github.com/starryalley/CSC_BLE_Bridge/blob/35b1006aa3497556c49e19055439c54cde7d0435/app/src/main/java/idv/markkuo/cscblebridge/CSCService.java#L464
If it still doesn't work, maybe try removing line 463 as well.
Just to be clear, do you mean that on Nokia 7 Plus you can't use this app successfully, even once? Thanks.
Sorry, probably set line 463/464 to false
instead of true
to reduce the AdvertiseData
length. I'm not sure what is the default value (include or exclude) so removing those 2 lines may not actually exclude those data.
Will give it a try in the morning. Thanks
Yeah, I thought that as the HR was being read from my strap that it would broadcast fine. I guess I was wrong... To eager for it to think it was working. Classic Dev! Sorry!
Not managed to try this yet, though whilst I was on calls today, I did manage to get the Nexus 5 working!!! So by installing CyanogenMod 13 on the Nexus 5 (after reading this thread on getting BLE advertising working, https://forum.xda-developers.com/t/how-to-get-kevo-on-nexus-5-5-0-1-or-5-1-or-cm12-5-0-2-or-5-1-1.3041092/post-65950497), I was able to use that ROM and Ant+ Enabler (https://play.google.com/store/apps/details?id=com.z2software.antplus), and have sucessfully used the app to do a session on RGT Cycling this evening... so result! I now have a ANT+ to BLE bridge device that I can use.
Will hopefully check the Nokia 7 Plus tomorrow.
So I made the code change and rebuilt. Tried it, and it doesn't look like it is having an issue now, but it isn't showing the HR sensor up in zwift or the ghostracer app, both of which support BLE sensors.
Filtered logcat attached.... https://pastebin.com/J6bSMrMB
So it looks like some BLE hardware can have trouble keeping the advertise data within 31 bytes so I will probably exclude the power level by default as it will add some extra bytes there.
If you have time, probably try to include device name:
.setIncludeDeviceName(true)
and exclude power level
.setIncludeTxPowerLevel(false)
Not sure what went wrong as I can't see anything wrong in the log.
@starryalley so it does work. I set every back in the code, and this time I thought about what you said and looked at the device name of my phone. It was large, so I changed it to "N7", and it all worked fine, so you probably need to mention something in the readme about device names. What should be the limit on them? Looks like there might be a bug in the Android SDK that doesn't truncate the name or something?
So in short, the Readme can have... Nokia 7 Plus (Android 10) Nexus 5 (CM13 with Ant+ Enabler)
Thanks for this info @leaskovski
As for the name being too long, see the second answer: https://stackoverflow.com/questions/36845422/is-there-any-way-to-change-the-device-name-in-advertisedata-in-android-ble
Looks like there is another way to avoid this. Feel free to submit a PR if you have time to test/try.
Hi team,
So I was just having a play with this using my Nokia 7 Plus (which has ANT+ built in, even though its not listed on the this is Ant website directory), and this works. It picks up my old garmin strap, and my elite zumo. Top job!
Now, the question I have is that can the BLE devices it creates, be used within an app running on the same device as the bridge is running on? Or do you have to run the bridge on a separate device to where you want to consume the the simulated devices?
My use case is running the RGT app on my phone, whilst using the bridge app to generate the signal from my heart strap to the RGT app. The RGT app already see's my trainer as it has BLE and ANT, just need to get my old school strap linked in. I have also tried the Ghostracer app to see if it can see the BLE sensor either, but no dice.
Good work!!!