How to control a Bluetooth LE connection on Windows 10? How to control a Bluetooth LE connection on Windows 10? windows windows

How to control a Bluetooth LE connection on Windows 10?


Once the device is paired, whenever it turns on close to the Windows 10 machine, it will try to connect. This is defined behavior in Bluetooth, as the peripheral will always send out a connection request when it is turned on.

There is a DeviceWatcher background task that you can register for to trigger your app when your Bluetooth device connects. You can find some sample code here.

Is there a way to control the connection with a specific bluetooth LE device?

Yes. To initiate a connection: when you create a BluetoothLEDevice via FromBluetoothAddressAsync or FromIdAsync the system will try to initiate a connection to that peripheral, if it does not already hold a connection.

// Connects to a Bluetooth device, given some string deviceIdBluetoothLEDevice bleDevice = await BluetoothLEDevice.FromIdAsync(deviceId);

To dispose of a connection, call the close method on BluetoothLEDevice. If your app is the only entity with a handle to the peripheral, this will cause the system to disconnect. However, if another app or system service has a handle to the peripheral, the connection will not be closed.

// Will disconnect from the BTLE device, if you hold the only handlebleDevice.close()

These are taken from the BluetoothLEDevice documentation here.

Are there other APIs?

There are not any other APIs built in to Windows 10 that offer more control over Bluetooth. The UWP APIs offer the most control that Windows 10 currently provides. You could use an alternate Bluetooth stack, but these would have to be installed separately and likely break other Bluetooth behavior on Windows 10.