Bluetoothctl: Difference between revisions

From DikapediaV2
Jump to: navigation, search
No edit summary
No edit summary
Line 18: Line 18:
====Enable Bluetooth Adapter====
====Enable Bluetooth Adapter====
----
----
Use <b>rfkill</b> command.  
Use [[Rfkill|<b>rfkill</b>]] command.  


  $ rfkill list all
  $ rfkill list all

Revision as of 17:36, 30 July 2025

Bluetoothctl is a command-line tool used to interact with the Bluetooth subsystem on Linux systems. It provides a text-based interface for managing Bluetooth devices, including discovering, pairing, connecting, and configuring Bluetooth devices.

Key Features of Bluetoothctl:

  • Device Discovery: Scan for nearby Bluetooth devices.
  • Pairing: Pair with Bluetooth devices.
  • Connecting: Establish a connection with paired devices.
  • Trusting: Mark devices as trusted to allow automatic connections in the future.
  • Agent Management: Manage Bluetooth agents, which handle pairing requests and PIN/passkey entry.
  • Power Control: Turn Bluetooth on or off.
  • Device Information: Retrieve information about connected and discovered devices.


Check bluetooth service


$ sudo systemctl status bluetooth


Enable Bluetooth Adapter


Use rfkill command.

$ rfkill list all
$ sudo rfkill unblock bluetooth


Scan Bluetooth Devices


$ sudo bluetoothctl scan on
Discovery started
.
.
.


See Bluetooth Devices


$ bluetoothctl devices

$ bluetoothctl devices | grep -i mx
Device D6:A3:C1:F9:2C:21 MX Master 3S
Device C7:A2:BB:7F:F3:49 MX Anywhere 2S


Pair and Connect a Bluetooth Device


$ dzdo bluetoothctl pair <device MAC>

$ dzdo bluetoothctl pair D6:A3:C1:F9:2C:21
Attempting to pair with D6:A3:C1:F9:2C:21
[CHG] Device D6:A3:C1:F9:2C:21 Paired: yes
Pairing successful

Once the pairing is complete, you need to connect the Bluetooth device:

$ sudo bluetoothctl connect D6:A3:C1:F9:2C:21
 Attempting to connect to D6:A3:C1:F9:2C:21
 Connection successful


Trusting a Bluetooth Device


If the pairing failed due to error "AuthenticationRejected", you may have to trust it first:

$ dzdo bluetoothctl pair D6:A3:C1:F9:2C:21
Attempting to pair with D6:A3:C1:F9:2C:21
Failed to pair: org.bluez.Error.AuthenticationRejected

$ dzdo bluetoothctl trust D6:A3:C1:F9:2C:21
[CHG] Device D6:A3:C1:F9:2C:21 Trusted: yes
Changing D6:A3:C1:F9:2C:21 trust succeeded

$ dzdo bluetoothctl pair D6:A3:C1:F9:2C:21
Attempting to pair with D6:A3:C1:F9:2C:21
[CHG] Device D6:A3:C1:F9:2C:21 Paired: yes
Pairing successful