DEV Community

Shane Duffy
Shane Duffy

Posted on • Edited on • Originally published at shaneduffy.io

1

Handling Bluetooth Programmatically on Windows

I use a command to connect to my Pixel Buds now, and switch between Bluetooth devices. It's pretty convenient, especially if you're still on Windows 10, with its buggy Bluetooth auto-connection.

Install Bluetooth Command Line Tools

This is the CLI tool provided by bluetoothinstaller.com, which has provided a humble suite of Bluetooth quality of life tools since 2009.

Connecting to a Bluetooth Device

You can connect by associating a COM service with a Bluetooth device. This is done via the btcom command.

btcom {-c|-r} {-b BluetoothAddress | -n FriendlyName} [-s {sp|dun|GUID|UUID}]

  -c  Create association between COM port and a remote service (Enable non-COM service).
  -r  Remove association between COM port and a remote service (Disable non-COM service).
  -s  Remote service to use (Default is Serial Port Service)
  -b  Bluetooth address of remote device in (XX:XX:XX:XX:XX:XX) format. 
  -n  Friendly name of remote device.
  -h  Prints this help screen.
Enter fullscreen mode Exit fullscreen mode

You'll need to figure out the specific COM services that you want to hook into. Windows connects headsets via two COM services: A2DP (110b) and HFP (111e), so you may need to connect to both for it to work properly.

If you're having issues connecting (-c), try disconnecting (-r) the device first. This has worked effectively for me, although it will generally take a few seconds longer to connect.

Connect

btcom -n "Shane's Pixel Buds" -c -s110e
btcom -n "Shane's Pixel Buds" -c -s110b
Enter fullscreen mode Exit fullscreen mode

Disconnect

btcom -n "Shane's Pixel Buds" -r -s110e
btcom -n "Shane's Pixel Buds" -r -s110b
Enter fullscreen mode Exit fullscreen mode

What Bluetooth Devices Are Available?

The Friendly Name for my Pixel Buds is "Shane's Pixel Buds". You can list available Bluetooth devices and COM services using btdiscovery command. This will list the ID as well as the Friendly Name.

btdiscovery [-i Seconds] [-b BluetoothAddress | -n FriendlyName] [-d Format] [-s [Format]]

  -i  Set the length of inquiry to the specified number of seconds.
  -b  Bluetooth address of remote device in (XX:XX:XX:XX:XX:XX) format.
  -n  Friendly name of temote device.
  -d  Set output format for the list of discovered devices.
  -s  Make service discovery. Optionally set output format for the list of services.
  -h  Prints help screen.
Enter fullscreen mode Exit fullscreen mode

Billboard image

The fastest way to detect downtimes

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitoring.

Get started now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay