Getting BLE connection to work with companion app

Hi all,

I am fairly new at coding so please bear with me. I want to create an Android companion app that communicates wirelessly with a vivoactive 4s. The ultimate goal is to send sensor data such as heart rate and oxygen saturation to the companion app on the phone to be recorded, monitored, and displayed over time. I have been reading the documentation on the Mobile SDK and BLE protocols and I am still confused on where to start. I have created a device app that is able to get current heart rate and display it on the watch face. My question now is: how should I proceed with making communication and sending sensor data, like current heart rate, to a mobile device via BLE?

I have some follow up questions:

1. Do I have to make a separate file in addition to the app, view, and delegate files on VS code? 

2. Do I have to pair the device first before transmitting data? How do you do this?

3. How do I change how often the messages/data gets transmitted?

Thank you so much for your help!

  • You use the Connect IQ Mobile SDK (Android or iOS) : https://developer.garmin.com/connect-iq/sdk/

    and the Communications module In the SDK used to build apps for watches, etc.  It uses the same connection as is used to do things like sync the device.

    Don't confuse this with BluetoothLowEnergy in CIQ,  It's used to connect to other things - sensors, etc.

    Understand that to do this, your app will need to be running on the watch when you want data on the phone, which means you can't run anything else on the watch.  You could use a background service, but they can only run every 5 minutes and for most, 30 seconds at a time.  

  • Hi Jim, thank you for your response. I have been trying to learn as much as I can and managed to get this far. Is this basically what we need to set up background events? Here I am trying to test a watch face that can print to the console "hi" every five minutes. I have included the app.mc and created a service delegate.mc to model it after sample code that you provided. Am I understanding this correctly? I tried running this in the simulator but it keeps failing to launch. 

    If so, would I just need to put transmit() under onTemporalEvent () to send sensor data like heart rate to a companion app?

    class HRWatchFaceApp extends Application.AppBase {
    
        function initialize() {
            AppBase.initialize();
        }
    
        // onStart() is called on application start up
        function onStart(state as Dictionary?) as Void {
        }
    
        // onStop() is called when your application is exiting
        function onStop(state as Dictionary?) as Void {
        }
    
        // Return the initial view of your application here
        function getInitialView() as Array<Views or InputDelegates>? {
        if(Toybox.System has :ServiceDelegate) {
            var FIVE_MINUTES = new Time.Duration(5 * 60);
            var transmitTime = FIVE_MINUTES;
            Background.registerForTemporalEvent(transmitTime);
            }
        return [ new HRWatchFaceView() ] as Array<Views or InputDelegates>;
        }
    
        function getServiceDelegate() {
            return [new HRWatchFaceServiceDelegate()];
        }
    
    }
    
    function getApp() as HRWatchFaceApp {
        return Application.getApp() as HRWatchFaceApp;
    }

    (:background)
    class HRWatchFaceServiceDelegate extends System.ServiceDelegate {
        function initialize() {
    	    ServiceDelegate.initialize();     
    	 }
        function onTemporalEvent() {
            System.println("hi");
        }
    }

  • @Jim I am using VS code, I am extra confused because I cannot seem to be able to build for device either. I've never ran into this problem before. 

  • Hi , have you build this app? I am working on a similar app, and I also need some help. Could you please help me with this?