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

  • With nrfConnect, you can see/do things you can't do in CIQ.  If BleScan can't connect, I doubt you can with CIQ in general right now.

  • I wanted to solve the same issue with a datafield I'm currently working on. I solved it by adding all the discovered devices to an array and letting the user select at runtime.

    Since a Datafield has no input delegate, I present the list 1 device at a time and cycle to the next device every 5 seconds, with a countdown timer displayed. Starting the app pairs the currently shown device


  • @cnemcse Usually you could identify the right device by the service uuid in the device advertisements. Only if more than one device is using the same service uuid it needs some user choice by MAC address.

    in your case it seems that device pairing works. For my weight scale device pairing times out. 

  • You can't see the MAC address of the other end with CIQ.

    In the Nordic sample .bleDeligate, "contains" shows you how to look for a specific UUID.

    Once you do find the specific device you want, you can save the scan result used to pair in Storage, and the next time your app runs, pull the scan result out of storage and use that to pair.  You can skip scanning all together, and save time in the process.

  • Cool strategy. Thanks for sharing this approach!

  • It's really useful if you are at a place where there might be multiple sensors of the same type, say a Ble HRM., After the first pairing, you can always use the same one if you use the saved scanResult.  And first time pairing, you just do it in a place where only device you want to use is within range.

    Another option is looking at the RSSI in the scan result, and only try to pair with the closest

  • Did some AI research on this. Please comment if totally wrong.

    It seems CIQ does not support unsecured communication, but exactly this I need when connecting to my scale.

    In the words of Ble the pattern @jim_m_58 proposes differentiates between two connection establishment ways:

    Connection Establishment

    1. General Connection Establishment (Ble Scan):

      • The collector (e.g., Garmin watch) searches for devices in the general discoverable mode and establishes a connection if right device was found.
      • This method is allowed for both unbonded and bonded collectors.
    2. Direct Connection Establishment (Stored Address):

      • The collector establishes a direct connection to a specific device that it already knows (MAC, storedScanResult).
      • This method is also allowed for both unbonded and bonded collectors.
    3. Auto Connection Establishment 

      • not allowed for unbound collectors, 
    4. Selective Connection Establishment 

      • not allowed for unbound collectors

    Furthermore after the basic connection is established there are multiple types of communication

    Types of Communication

    Bonded Collectors:

    These are devices that have undergone the bonding process. During bonding, cryptographic keys are exchanged and stored on both devices. This allows for secure reconnections in the future without needing to repeat the pairing process. The keys are stored, enabling quick and secure reconnections.

    Unbonded Collectors:

    Connections to unbonded collectors can be either secured or unsecured:

    1. Unsecured by Keys:

      • Unpaired and Unbonded: In this scenario, the devices have not exchanged cryptographic keys. The connection is not encrypted and is therefore not secure.
      • Security: The connection is not secure, and data transmitted over this connection can be intercepted.

    2. Secured by Keys (Paired):

      • Paired but Not Bonded: In this scenario, the devices have exchanged cryptographic keys during the pairing process, but these keys are not stored for future use. The connection is secure for the current session, but the pairing process must be repeated for future connections.
      • Security: The connection is encrypted and secure for the duration of the session

    Security Modes:

    • Mode 1, Level 1: No security (no encryption, no authentication, plaintext communication)..
    • Mode 1, Level 2: Unauthenticated pairing with encryption.
    • Mode 1, Level 3: Authenticated pairing with encryption.
    • Mode 1, Level 4: Authenticated LE Secure Connections with encryption.
  • BLE in CIQ knows about MACs -> Toybox.BluetoothLowEnergy.ScanResult.hasAddress("0C:95:41:7E:53:F3")

  • Would be cool if system 8 would introduce insecure connections as a additional connection strategy.

    // Ble.CONNECTION_STRATEGY_SECURE_PAIR_BOND;
    // Ble.CONNECTION_STRATEGY_INSECURE;
    // Ble.CONNECTION_STRATEGY_DEFAULT;
    Ble.setConnectionStrategy(Ble.CONNECTION_STRATEGY_INSECURE);
    Ble.pairDevice(scanResult);

    Is anybody from Garmin reading this?
    At least they ask developers to post in the forum since the developer support is not for private enquiries.