adamjoniec / BluetoothDevicePairing

Console utility to discover and pair Bluetooth and Bluetooth LE devices.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BluetoothDevicePairing

Console utility to discover and pair Bluetooth and Bluetooth Low Energy devices.

Note on connecting to Bluetooth devices

If you pair a device which is not already paired, the utility will also connect to it (this is default behaviour of Windows Bluetooth API)
However, if device is paired but not connected, the pairing will fail.
Unfortunately, currently it is not possible to simulate what "Connect" button from Windows Bluetooth and Other devices dialog does. More details can be found here: How to connect to a paired audio Bluetooth device. Specifically, here I have described my failed attempts to implement this functionality.

System requirements

Windows 10 1809 (10.0.17763) or higher

How to use

  • Download and unpack the latest release.
  • Run BluetoothDevicePairing.exe --help and BluetoothDevicePairing.exe <command> --help to get usage information and check the Examples section bellow.

Examples

  • Discover devices:
BluetoothDevicePairing.exe discover
  • Pair a device using its mac address:
BluetoothDevicePairing.exe pair-by-mac --mac 12:34:56:78:9A:BC --type Bluetooth
  • Pair a device using its name:
BluetoothDevicePairing.exe pair-by-name --name "MX Ergo" --type BluetoothLE
  • Pair a device using its name and pin code:
BluetoothDevicePairing.exe pair-by-name --name "Device name" --type BluetoothLE --pin 1234
  • Pair a device using its mac and pin code:
BluetoothDevicePairing.exe pair-by-mac --mac 12:34:56:78:9A:BC --type Bluetooth --pin 1234
  • Unpair a device using its mac address:
BluetoothDevicePairing.exe unpair-by-mac --mac 12:34:56:78:9A:BC --type Bluetooth
  • Unpair a device using its name:
BluetoothDevicePairing.exe unpair-by-name --name "MX Ergo" --type BluetoothLE
  • List all Bluetooth adapters available you your machine
BluetoothDevicePairing.exe list-adapters

How it works

The program uses

Device pairing by name

In order to pair a device by name, the utility starts with discovering all available devices and tries to find a device with the required name. After a device is found its mac address is used to request pairing. The command will fail if there are several devices with the same name.

Return values

In case of failure the command returns value -1. In case of success the 0 is returned.

Build

  • Use Visual Studio 2022 to open the solution file and work with the code
  • Run .github/workflows/build.ps1 to build a release (to run this script git.exe should be in your PATH)

References

About

Console utility to discover and pair Bluetooth and Bluetooth LE devices.

License:MIT License


Languages

Language:C# 92.6%Language:PowerShell 7.4%