IanPeake / FatMaxxer

Android Project to find FatMax in real time with a Polar H10
Other
61 stars 11 forks source link

Emulate BLE sensor (How to get DFA-a1 on your sports device) #3

Open MedTechCD opened 3 years ago

MedTechCD commented 3 years ago

I don't know much about coding and the possibilities but had an alternative idea to get a1 live on the screen of your sports device: If Fatmaxxer app could be coded to behave as/emulate a BLE sensor, a Connect IQ field could pick up the signal and display it on the bike computer/watch. The data stream could then also be saved in the Fit file. I know that there are apps that rebroadcast a picked-up ANT+ signal over BLE. Technically this seems possible.

IanPeake commented 3 years ago

Great idea, no idea if an Android phone can emulate the device side of a BLE connection

IanPeake commented 3 years ago

It appears that this may be possible, though no proof of concept code yet:

https://www.quora.com/Can-a-smartphone-act-as-a-Bluetooth-low-energy-receiver-and-sender

IanPeake commented 3 years ago

Looks like we are after peripheral mode plus however the sensor behaves:

https://stackoverflow.com/questions/29235787/how-can-i-create-an-android-ble-peripheral

MedTechCD commented 3 years ago

This is a Github project that rebroadcasts ANT+ as BLE. Maybe you can get something usefull from that code: https://github.com/starryalley/CSC_BLE_Bridge

IanPeake commented 3 years ago

That looks good. There is then the question of what protocol to use. Does FatMaxxer rebroadcast alpha1 x 100 as though it were a heart rate?

IanPeake commented 3 years ago

Code here https://github.com/starryalley/CSC_BLE_Bridge/blob/d91a0cfa254ec9f7f44655b2928b46727d112f99/app/src/main/java/idv/markkuo/cscblebridge/CSCService.java#L59

MedTechCD commented 3 years ago

Not sure what way to go here. Emulate an already existing sensor will interfere with actual sensors. In CIQ I read about a generic ANT+ channel that could be used for a supplementary sensor. But I don't know if the generic channel also exists for BLE. A generic channel would be read out by a CIQ Datafield. It may be a good idea to start with emulating a HR sensor (dfa x 100) just to make sure that this path could get us where we want.

MedTechCD commented 3 years ago

Found this https://apps.garmin.com/en-US/apps/9bcc8b66-8385-4afb-b93e-f69e01422284 while searching the CIQ development forum https://forums.garmin.com/developer/connect-iq/f/discussion/244531/connect-iq-sdk-connecting-to-ble-v4-sensor-that-sends-gatt-messages Looks like there is a good chance that it can work.

MedTechCD commented 3 years ago

Specs for Edge 830 image

IanPeake commented 3 years ago

Take a look at https://github.com/IanPeake/FatMaxxer/blob/main/app-debug-ble-emu-test.apk which is based on the github project above. The BLE emulator service appears to be starting and advertising. But so far I haven't been able to see any new sensor from my Garmin.

cagnulein commented 1 year ago

Hi @IanPeake are you still working on this? I'm doing the same here https://github.com/cagnulein/qdomyos-zwift/issues/1316 maybe we can exchange our knowledge on this. I'm able to use a MacOS or raspberry or ESP32 to a Garmin device, but android or iOs it's not working. It seems that Garmin knows that it's a phone. It's not the MAC address because i changed it into the ESP32 matching the android one and it's still working. It's not the adv time, because i put even 1s to the ESP32 and it's still working.

I have to investigate it with a BLE sniffer. Follow that thread in case.

IanPeake commented 1 year ago

Hi Roberto,

Thanks for the information. I gather that the incompatibility between Garmin devices and phones having incompatible requirements regarding public vs private bluetooth addresses explains the issue.

The rpi workaround sounds interesting.

Best regards,

Ian

On Sun, Mar 19, 2023 at 7:38 PM Roberto Viola @.***> wrote:

Hi @IanPeake https://github.com/IanPeake are you still working on this? I'm doing the same here cagnulein/qdomyos-zwift#1316 https://github.com/cagnulein/qdomyos-zwift/issues/1316 maybe we can exchange our knowledge on this. I'm able to use a MacOS or raspberry or ESP32 to a Garmin device, but android or iOs it's not working. It seems that Garmin knows that it's a phone. It's not the MAC address because i changed it into the ESP32 matching the android one and it's still working. It's not the adv time, because i put even 1s to the ESP32 and it's still working.

I have to investigate it with a BLE sniffer. Follow that thread in case.

— Reply to this email directly, view it on GitHub https://github.com/IanPeake/FatMaxxer/issues/3#issuecomment-1475152873, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFSEU6J447FHXLSXVIFOUB3W43AY5ANCNFSM47DHAGRA . You are receiving this because you were mentioned.Message ID: @.***>