Code Monkey home page Code Monkey logo

bluetoothdevicepairing's Introduction

BluetoothDevicePairing

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

Note on connecting to Bluetooth devices

If you pair a device that is not already paired, the utility will also connect to it (this is the default behavior of Windows Bluetooth API)
However, the pairing will fail if a device is paired but not connected.
Unfortunately, it is impossible to simulate what the "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 below.

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 to your machine
BluetoothDevicePairing.exe list-adapters

Examples of scripts

The BluetoothDevicePairing utility can be used in bat and PowerShell scripts.

Script to pair a Bluetooth device

The following bat script allows to automate the connection of Bluetooth devices. Before using this script, you need to find out the Bluetooth type and name of your device:

  1. Put the device into the pairing mode
  2. Run the BluetoothDevicePairing.exe discover command that will print the required information.
  3. Adapt the script below to use your device's name and Bluetooth type.

How to use the script:

  1. Put the device into a pairing mode
  2. Run the script
C:\my\apps\BluetoothDevicePairing.exe unpair-by-name --name "MX Ergo" --type BluetoothLE --discovery-time 1
C:\my\apps\BluetoothDevicePairing.exe pair-by-name --name "MX Ergo" --type BluetoothLE --discovery-time 10
if %ErrorLevel% NEQ 0 (
    pause
    exit /b %errorlevel%
)

How it works

The program uses

Device pairing by name

To pair a device by name, the utility starts by 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

If the command fails, it returns the value -1. If it succeeds, it returns 0.

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

bluetoothdevicepairing's People

Contributors

polargoose avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.