

Once we know the MAC address of our device, we can begin pairing. The important part is the MAC address, which we use to pair devices. The output shows us any discovered devices with their names and MAC addresses. Now, let’s output the discovered devices using bluetoothctl devices: $ bluetoothctl devices So, we put it in the background using Ctrl-Z. However, this command is a foreground job, which means that we won’t be able to use the terminal until it is finished. To set the controller to discovery mode, we use the bluetoothctl scan on command. Controller 00:1A:7D:DA:71:15 Discovering: yes Connect a Bluetooth Device Using the Terminal Our string can contain as many commands as want as long as we end each with a newline. This causes the bluetoothctl shell to treat the string as user input and allows us to automate the process of using interactive mode. In this example, we use a here-string to redirect our string to stdin. However, there is a way we can use select in a similar way to non-interactive mode: $ bluetoothctl <<< $'select 34:02:86:03:7C:F2\nlist\n' Since the select command only changes the default controller for the current session, it will only work within interactive mode. Non-interactive mode opens up a new session per command, but the interactive shell maintains the same session until exited. In this example, we used the select command in interactive mode. To change the default controller, we use the bluetoothctl select command, passing the MAC address of the controller we want to connect to: # select 34:02:86:03:7C:F2Ĭontroller 34:02:86:03:7C:F2 pc-m Ĭontroller 34:02:86:03:7C:F2 pc-m #2 The default controller is the controller that will be operated on when we run a command. This command outputs information about the connected Bluetooth controllers, including their MAC addresses and what the default controller is. Let’s use the bluetoothctl list command to get a list of connected Bluetooth controllers: $ bluetoothctl listĬontroller 00:1A:7D:DA:71:15 pc-m
