GithubHelp home page GithubHelp logo

polargoose / bluetoothdevicepairing Goto Github PK

View Code? Open in Web Editor NEW
63.0 4.0 20.0 87 KB

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

License: MIT License

C# 95.33% PowerShell 4.67%
bluetooth bluetooth-connection

bluetoothdevicepairing's Introduction

BluetoothDevicePairing

Console utility to discover and pair Bluetooth and Bluetooth Low Energy devices. The utility also allows to connect and disconnect from audio 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)
  • If you pair to an already paired audio Bluetooth device, the utility will connect to it.
  • Managing Bluetooth devices by mac is much faster than by name, because it doesn't require device discovery.
  • When managing Bluetooth devices by name, you can use the --discovery-time parameter to change the time spend on device discovery.

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
  • Disconnect an audio device using its Mac address:
BluetoothDevicePairing.exe disconnect-bluetooth-audio-device-by-name --name WH-1000XM5
  • Disconnect to an audio device using its name:
BluetoothDevicePairing.exe disconnect-bluetooth-audio-device-by-mac --mac 88:c9:e8:17:5e:0f

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%
)

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 build.ps1 to build a release (to run this script, git.exe should be in your PATH)

References

bluetoothdevicepairing's People

Contributors

polargoose avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bluetoothdevicepairing's Issues

The Answer Post on StackOverflow doesn't work well on my Airpods Pro

I've use the Powershell Script you posted on StackOverflow,but it doesn't work on my Airpods Pro(1st Gen),The script report it works well but my phone does not connected with my computer.Here is the output

The following PnP devices related to the 'Surface Headphones' headphones found:

Status     Class           FriendlyName                                                                     InstanceId     
------     -----           ------------                                                                     ----------
OK         Bluetooth       Surface Headphones                                                               BTHENUM\DEV_...

Disable all these devices
Enable all these devices
The headphones should be connected now.
It may take around 10 seconds until the Windows starts showing audio devices related to these headphones.

The "Surface Headphones" is the name of my Airpods
Before I use this script,I also use a tool to get the infomation of my device,here is the info

(3C:4D:BE:24:CF:D9)     Surface Headphones      Headphones
        7C74    0       AAP Server
        111E    7       Handsfree
        110E    0       AVRCP Target
        110E    0       AVRCP Controller
        110D    0       Audio Sink
        1000    0

Is there any way to solve this problem?

is discovery required when pairing with mac address?

As far as i know discovery isn't required while connecting with mac address directly. I wanted to use this in another project but it requires pairing quickly. The closest I've been able to get is by using
"BluetoothDevicePairing.exe pair --mac 12:34:56:78:9A:BC -discovery-time 1" . thanks btw great tool.

failed to discover devices in windows11

run bluetoothdevicepairing discover in powershell or cmd but the output only replied:

Failed: The parameter is incorrect.

The provided device ID is not a valid BluetoothDevice object.

May I know how can I get the device ID before discovering?

Same MAC, same name - only difference is LE

Hello and thank you for this tool. Great job.

I've been trying to use it to connect to a portable thermal printer. The problem is that it is broadcasting two interfaces and the only difference between them is that one is LE and one is standard energy mode. Your app is connecting to the LE one which isn't the one I need to use.

As you see in this image below only the LE one (MTP-2) is paired and connected:
image

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.