Bluetooth: Unpaired Bluetooth LE Device Connectivity - Part 2 of 3

Play Bluetooth: Unpaired Bluetooth LE Device Connectivity - Part 2 of 3

The Discussion

  • User profile image

    You should put the link to Team blog and also the slides

  • User profile image

    I checked the blog and could not find the sample code.
    Is it going to be available as pieces of the code in video are not shown

  • User profile image

    For People needing the sample code (like me), i got the BluetoothLEClient from Windows-universal-samples-master and changed some things (as shown in the video), changed StartBleDeviceWatcher() and ConnectButton_Click(), hope it helps, see changes below:

    private void StartBleDeviceWatcher()
    EnumerateButton.Content = "Stop enumerating";
    // Additional properties we would like about the device.
    string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected", "System.Devices.Aep.Bluetooth.Le.IsConnectable" };
    string aqsAllBluetoothLEDevices = "(System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\")";
    //string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected", "System.Devices.Aep.Bluetooth.Le.IsConnectable" };
    //string aqsAllBluetoothLEDevices = "(System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-75eaa7084d49}\")";
    //string[] requestedProperties = { "System.Devices.Aep.DeviceAddress", "System.Devices.Aep.IsConnected" };
    //string aqsAllBluetoothLEDevices = "(System.Devices.Aep.ProtocolId:=\"{bb7bb05e-5972-42b5-94fc-76eaa7084d49}\")";

    // BT_Code: Currently Bluetooth APIs don't provide a selector to get ALL devices that are both paired and non-paired.
    deviceWatcher =

    // Register event handlers before starting the watcher.
    deviceWatcher.Added += DeviceWatcher_Added;
    deviceWatcher.Updated += DeviceWatcher_Updated;
    deviceWatcher.Removed += DeviceWatcher_Removed;
    deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted;
    deviceWatcher.Stopped += DeviceWatcher_Stopped;

    // Start over with an empty collection.

    // Start the watcher.

    private async void ConnectButton_Click() {

    ConnectButton.IsEnabled = false;
    try {
    // BT_Code: BluetoothLEDevice.FromIdAsync must be called from a UI thread because it may prompt for consent.
    bluetoothLeDevice = await BluetoothLEDevice.FromIdAsync(rootPage.SelectedBleDeviceId);
    } catch (Exception ex) when ((uint)ex.HResult == 0x800710df) {
    // ERROR_DEVICE_NOT_AVAILABLE because the Bluetooth radio is not on.
    if (bluetoothLeDevice != null) {
    // BT_Code: GattServices returns a list of all the supported services of the device.
    // If the services supported by the device are expected to change
    // during BT usage, subscribe to the GattServicesChanged event.
    GattDeviceServicesResult result = await bluetoothLeDevice.GetGattServicesAsync(BluetoothCacheMode.Uncached);
    if (result.Status == GattCommunicationStatus.Success) {
    var services = result.Services;
    rootPage.NotifyUser(String.Format("Found {0} Services", services.Count), NotifyType.StatusMessage);
    foreach (var service in services) {
    ServiceCollection.Add(new BluetoothLEAttributeDisplay(service));
    ConnectButton.Visibility = Visibility.Collapsed;
    ServiceList.Visibility = Visibility.Visible;
    } else {
    rootPage.NotifyUser("Failed to connect to device.", NotifyType.ErrorMessage);
    ConnectButton.IsEnabled = true;

  • User profile image

    @RobZ76: Thanks.  I changed the code as you mentioned -- looks like I can do unpaired connect.  But I don't get list of characteristics.   Any additional hints?

    I'm using the TI SensorTag.  

    Sure would be nice to see the source code.

  • User profile image

    Is it available for general desktop App not universal application?


  • User profile image

    @JTKIM yes, it's possible it to use on Desktop, just NuGet DirectWindowsWinmd.Net, change Copy Local: False for references System.Runtime.WindowsRuntime and Windows.

Add Your 2 Cents