Broadcast Heart Rate by BLE

Former Member
Former Member

Hi community,

Last days i beging do sport with virtual systems as Zwift. My equipment is all Garmin and I just view that Garmin use only ANT`+ communications for all their devices. For this reason I can't connect my Heart Rate band (TRI) or my Garmin Fenix 5S with virtual devices (as Zwift) that use only bluetooth communications.

I view that some Garmin Watches has a mode to broadcasting hear rate to other devices. But this broadcasting is only for ANT+ communications. My idea is perform this equal function but using ble communication.

Then the uses cases are:

1 - Use case (Connection with Virtual Trainning APP)

Actors:

  • Smart Watch
  • Zwift APP

Description:

  • Smartwatch will pairing with bluetooth device (Laptop, table or Smartphone) with trainning APP Zwift

Preconditions:

  • Smartwatch has BLE communications.
  • Laptop/Tablet/Smartphone has BLE communications.
  • Laptop/Tablet/Smartphone has got Zwift APP.

Normal course:

  • The user opens broadcasting hear rate widget  into smart watch.
  • The user search in Zwift APP available hear rate devices to connect by bluetooth communication and it select Garmin device.
  • The Garmin watch and Laptop/Tablet/Smartphone is paired and start the communication.

I just begin develop this simple feature but I never performed any bluetooth communication develop. Perhaps I need some support :)

I will share with you the GitHub report for we can colaborate together.

PD: Congratulations for SDK Garmin docs, it appear all clear!!

I will bring you news later.

Best regards,

Javi

  • If your watch supports the Virtual Run Profile, with that you can broadcast HR over BLE even if your HRM is ANT.  CIQ isn't involved.

  • Former Member
    Former Member over 4 years ago in reply to jim_m_58

    Thanks for you quickly response

    I view this new Virtual Run profile, But its only compatibility with FR235/FR945 and Fenix Serie 6.

    I current have got a Fenix 5S and FR645M. Both devices has bluetooth but they haven't got that new Virtual run profile feature. Is possible that Fenix 5S and FR645M are not compatibles for perform this feat? For hardware I thought that yes they were compatible.

  • Former Member
    Former Member over 4 years ago

    I’m create new class inherit from BleDelegate. When I try initialization this class I get a error that I don’t understand.

    This is the class inherit from BleDelegate:

    BleHandler.mc

    using Toybox.System;
    using Toybox.BluetoothLowEnergy as Ble;
    
    
    class BleHandler extends Ble.BleDelegate {
    
    	var scanning = false;
    	var device = null;
    	
    	hidden function debug(str) {
    		System.println("[ble] " + str);
    	}
    	
    	function initialize(callback) {
    	    BleDelegate.initialize();
    	    debug("initialize");
    	
     	}
     	
     	
     	private function connect(result) {
    		debug("connect");
    		Ble.setScanState(Ble.SCAN_STATE_OFF);
    		Ble.pairDevice(result);
    	}
    
    	private function dumpUuids(iter) {
    		for (var x = iter.next(); x != null; x = iter.next()) {
    			debug("uuid: " + x);
    		}
    		return false;
    	}
    	
    	function onScanResults(scanResults) {
    		debug("scan results");
    		
    	}
    	
    	function registerProfiles() {
    		var profile = "testing";
    		Ble.registerProfile(profile);
    	}
    	
    	function onScanStateChange(scanState, status) {
    		debug("scanstate: " + scanState + " " + status);
    		if (scanState == Ble.SCAN_STATE_SCANNING) {
    			scanning = true;
    		} else {
    			scanning = false;
    		}
    	}
    
    	function onConnectedStateChanged(device, state) {
    		debug("connected: " + device.getName() + " " + state);
    		if (state == Ble.CONNECTION_STATE_CONNECTED) {
    			self.device = device;
    		} else {
    			self.device = null;
    		}
    	}
    	
    	function open() {
    		registerProfiles();
    		Ble.setScanState(Ble.SCAN_STATE_SCANNING);
    	}
    
    	function close() {
    		debug("close");
    		if (scanning) {
    			Ble.setScanState(Ble.SCAN_STATE_OFF);
    		}
    		if (device) {
    			Ble.unpairDevice(device);
    		}
    	}	
    
    }

    HeartRateBroadcastBleApp.mc

    using Toybox.Application;
    using Toybox.BluetoothLowEnergy as Ble;
    using Toybox.Lang;
    using Toybox.System;
    
    class HeartRateBroadcastBleApp extends Application.AppBase {
    	var bleHandler = null;
    
        function initialize() {
        	System.println("Start APP...");
            AppBase.initialize();
        }
    
        // onStart() is called on application start up
        function onStart(state) {
        	System.println("On Start...");
        	try {
    	    	bleHandler = new BleHandler();
    			Ble.setDelegate(bleHandler);
    			//bleDevice.open();
    		
    		} catch (e instanceof Lang.Exception) {
    			System.println("Exception error message:");
    			System.println(e.getErrorMessage());
    			System.println("Exception stack trace:");
    			e.printStackTrace();
    		}		
        }
    
        // onStop() is called when your application is exiting
        function onStop(state) {
        	System.println("On Stop...");
        	bleHandler.close();
        }
    
        // Return the initial view of your application here
        function getInitialView() {
        	System.println("Init Main View");
            return [ new HeartRateBroadcastBleView(bleHandler) ];
        }
    
    }

    Error:

    Error: Symbol Not Found Error
    Details: Failed invoking <symbol>
    Stack: 
      - onStart() at /Users/jperez/eclipse-workspace/HeartRateBroadcastBle/source/HeartRateBroadcastBleApp.mc:19 0x1000006a 

    I tried add try/catch when the class is initializated for get more information about this error but the error output is the same.

    Could you help me with this error? I don't understand the root from this error.

  • In CIQ, what you can do is the "other end" of what you want.  You can connect to a BLE HRM and get data from it, but you can't advertise you are a HRM and let others connect to you.

    As far as the error, CIQ BLE requires CIQ 3.1, and not all 3.1 devices support it.  The f5s doesn't, the 645m does.  If you are trying to run in the sim, even with a target that supports CIQ BLE, you need to have additional HW on your pc/mac fo speak BLE.  See: https://forums.garmin.com/developer/connect-iq/w/wiki/19/getting-started-with-connect-iq-ble-development

    The virtual run profile is only available on newer devices, so you wont see that coming to the f5s, and more than likely not to the 645m

  • Former Member
    Former Member over 4 years ago in reply to jim_m_58

    Thanks so much for your support Jim.

    I tried launch app with another smartwatch compatible with CIQ 3.1 and it fix error. I don't checked CIQ 3.1 compatibility devices.. I will search some compatibility table.

    So i could not advertise another devices that my garmin is a HRM to broadcast HR data? :(  I will have to wait if in the future there is any change in CIQ that let me do it.

    Let me thank you again for your time Jim.

  • The BLE in CIQ is meant to connect to external sensors, but not act as one.  I doubt that will change.

  • https://forums.garmin.com/developer/connect-iq/w/wiki/19/getting-started-with-connect-iq-ble-development

    I was just thinking of dabbling in BLE sensors and connecting to it. Seems like additional investment is needed and t's an expensive investment (USD40+ for my region).

    Alternatve would just be to keep on loading and unloading to and from the watch and use the watch as the "sim".

  • The dongle is only $10US.  You can get by without it and just test on a device with sideloads, but for $10, it's worth it.

    https://forums.garmin.com/developer/connect-iq/w/wiki/19/getting-started-with-connect-iq-ble-development

    The nRF52840 Dongle

    I just published a Ble Scanner which allows you to see what a devices can seen using CIQ BLE if you're considering an app

    https://apps.garmin.com/en-US/apps/9bcc8b66-8385-4afb-b93e-f69e01422284

  • haha... the link you provided lead to the Nordic Development Kit and of course, I didn't know any better.

    https://www.nordicsemi.com/About-us/BuyOnline?search_token=nRF52840DONGLE&series_token=nRF52840

    Now that it's ~USD12, its down to an affordable level for me.

    Question - Since never done any BLE programming before, how does the data comes back to the device? In ANT+ it's a message payload that one uses the ANT+ specs for that particular profile and then uses that to decode the payload.

    Is there a similar site like thisisant.com for BLE approved devices that I can get the payload interpretation?

  • It's a bit different than ANT.  Some ble profiles you can easily find online, like a HRM for example.

    When you do a scan and find something (based on the service UUID), you connect/pair it, and then you can access various characteristics.  Those allow read, write, or notify.

    So if you connected to a BLE HRM, you can read the HR characteristic, but you can also turn on notify for it, and the sensor will inform your app when it's changed.  In this case, writing a value makes no sense.

    In stuff I do with a raspberry pi, I control both ends so can define my own profile.  Here's a blog post which a bunch of info:

    https://forums.garmin.com/developer/connect-iq/b/news-announcements/posts/would-you-like-some-raspberry-pi-with-your-connect-iq