BLE register and limit connections

Hello,

I have a peripheral and a Garmin watch app that connects to that peripheral. The issue I’m having is how do I establish a 1-to-1 relationship between the peripheral and watch?

So if I have 3 watches and 3 peripherals, all with the same service and characteristic profiles, how do I get Watch A to always reconnect to Peripheral A, B to B, C to C and so on, after their initial connection? Having different ble profiles seems like it wouldn’t be the correct solution. Would using a watch settings file potentially help? Is there anything the watch receives during the BLE connection that would tell it another device is already connected?

Thank you for your help.

  • One thing you can do is when you first scan for sensor A with watch A, you save the scan result in persistent storage, and after that, you no longer scan, just pair using the save scan result,  Do the same with watch B and sensor B, etc.  So you only ever scan once.

    The other option is that you have an app setting for the BLE MAC address of a sensor, and then use hasAddress() on a scan result and see if what you have configured matched the address of that scan result.  Your device must have CIQ 3.2 or greater for this.

  • Hello,

    When i want to  save the scan result in persistent storage ( Storage.setValue("ble_device", scanResult); )

    I have this code error: [{
    "resource": "/c:/Users/bapti/OneDrive/Bureau/APP GARMIN/TEST/Gitlab/garmin-power-extract/App_Ant_Fit_Ble_GPS4.3/source/DeviceManager.mc",
    "owner": "monkeyc",
    "severity": 8,
    "message": "Invalid '$.Toybox.BluetoothLowEnergy.ScanResult' passed as parameter 2 of type 'PolyType<Null or $.Toybox.Application.PropertyKeyType or $.Toybox.Lang.Array<$.Toybox.Application.PropertyValueType> or $.Toybox.Lang.Dictionary<$.Toybox.Application.PropertyKeyType,$.Toybox.Application.PropertyValueType> or $.Toybox.WatchUi.BitmapResource>'.",
    "startLineNumber": 71,
    "startColumn": 1,
    "endLineNumber": 71,
    "endColumn": 1
    }]

    How do you save the scan result in persistent storage ?

  • Application.Storage.setValue(SCANR, view.result);
    Where SCANR is a string with the key name, and view.result is the scan result I used to pair.
    You might just be seeing things detected by type checking.  As a test, turn off type checking for you app and see what changes.
    You can do this on a per-project basis by adding
    project.typecheck=0
    to your monkey.jungle file
  • it only works when i adding project.typecheck=0 in monkey.jungle file