Connecting directly to a specific BLE Device

Hi guys,

Stepped myself through Jim's ConnectIQ BLE example which has been very helpful. I'm can read and write to and from my own hardware now, but onto the next thing.

Question
If I have multiple BLE devices in range, that are all advertising the same characteristic, is there a way I can specifically set which device I want to connect to via mac or some other method?

Cheers,
Matt

  • I'm looking for soution for the nearly same problem. I have NRF52 SoC devices and would like to connect to two devices simultaneously with a Garmin Forerunner. Tried both solutions 

    1. Scan while not connected for both and pair after discover
    2. Scan and store to an array both, and after stop scanning and try to connect each

    The behaviour is very strange, first connection successed, second started, connected, and disconnect immadietly -> getting error from CIQ, with "the device is already paierd". The two "scanResult " object is not the same, i'm filtering by name. 

    Used 's BLE application and my own, and getting different RAW datas from the scan result. 

    If I change the second BLE device to a HR (Polar H10 sensor) it works. (However the Garmin can't see the Polar's advertising name what is very very strange. 

  • You only see the name with blescan (or CIQ BLE in general) on some devices.  For the devices I have at hand, I only see the name with a thingy52 or a Garmin HRM-PRO.  When scanning I use the UUID to check for a device I'm looking for.

    When it comes to multiple devices, CIQ BLE can connect to at most 3 devices, and that's not per app, but per Garmin.

    If I want to always connect to only a specific device, as I mentioned before, I save the scan result in Application.Storage and then use the scan result from Storage to pair the next time an app runs.

  • Thanks for the advice! Yeah if you have permanent devices to connect Application.Storage will be a really good point! 

    I have just tested the default garmin pairing with two Polar H10 HRM sensors and its just give back a number what is not corresponds the advertisement name. I think some devices uses longer advertisement headers, what Garmin can't support. 

  • Understand that for a CIQ app to use something like a HR sensor, it can't be paired in the FW.

    In my apps I always use the UUID and not the name when looking for a device.

  • I using "pairing" for connection - corresponding to the CIQ naming terminology. (But its just a connection request to be honest). The only problem is with the UUID for me to how to define wich devices is my own (like right/left side) without names. But when using with nRF52 SoC Garmin shows the names. 

  • The problem was 7.0.2 beta SDK. 7.1.1 solved this. 

  • Maybe this is due to this bug, fixed with SDK v7.2.0?

    • "Allow BLE scan results to show up for devices that had not disconnected yet due to the delayed disconnect feature."
  • @jim_m_58 How do you save the scanResult record to application.storage? If i try to do this, i get this error:

    Storage.setValue("MyDevice", scanResult);

    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>'

  • What SDK are you using?  With my apps that do this, they were written before type checking was a thing, so I build without type checking.

    To me, the way it looks is that they are using Application.PropertyValueType where they need to use something different, as I recall you can't store a scanResult with Application.Properties, only Application.Storage

    In the API doc, it lists the valid types for Storage.setValue(), including

    but don't have a list for Properties.setValue() just "Since API level 2.4.0"

  • I don't know, just downloading the newest SDK. I modified the bluetooth sensor codes to switch one sensor into a special mode where it reinitializes itself with a different service UUID so the garmin watch can see they are different sensors.. It was so much overwork to estabilish some connections because as i see Garmin releases watch SW-s without testing them deeply.. 

    As i work much more with CIQ BLE it getting wors and worse. 

    1. lack of documentation

    2. really slow BLE stack - connection takes seconds

    3. isntable simulator what not covers the real working

    4. can't debug on a watch on the fly

    +1 new bug for me: 

    if you call unpairDevice() you wont get the disconnection event