Tuesday 6 December 2016

Finding, enabling and starting Bluetooth in Linux from terminal

First thing that is needed to be done is to check if your machine has a Bluetooth adaptor or not. Most modern PC should have one builtin but if that is not the case one can always buy a cheap Bluetooth USB dongle and plug it in. Once the hardware side of things are done with, enter the following command to start the essential software routines to handle Bluetooth:

$ sudo service bluetooth start

To know what and how many adaptors you have at your disposal you need to use the following command:

$ hciconfig

The above command will return nothing if no Bluetooth adaptor is available, else you will see something like this as output:

hci0: Type: BR/EDR  Bus: UART
BD Address: B8:27:EB:E4:87:C3  ACL MTU: 1021:8  SCO MTU: 64:1
UP RUNNING
RX bytes:773 acl:0 sco:0 events:50 errors:0
TX bytes:2540 acl:0 sco:0 commands:50 errors:0

What you see above is the primary information about the adaptor hci0. The zero here is like a serial number, if the system had two adaptors then there would have been two such outputs following hci0 and hci1. For the rest of the commands in this post I am going to use hci0 as a default.
If you wish to know more about the adaptor then use:

$ hciconfig -a hci0

In the output of the above commands you see in the second line something written as "UP RUNNING". This represents the current state of the adaptor. Currently hci0 is running. To shut the radio down use:

$ hciconfig hci0 down

To bring it back again:

$ hciconfig hci0 up

That is it. Bluetooth is now functional. As a validation you can scan using other devices to see if your device gets listed there. It should.

Once you're able to get this and are willing to continue using Bluetooth from the terminal, you need to install the following things for a better experience:

$ sudo apt-get install bluez
$ sudo apt-get install bluez-tools


No comments:

Post a Comment