First determine the hardware has Bluetooth-enabled devices, and then run the following command, you can drive to our Bluetooth device:
 
The code is as follows:
 
Lsusb
     
Run Hciconfig can see:
     
As you can see from the above picture, our Bluetooth device is HCI0
 
Run Hcitool Dev can see the hardware address of our Bluetooth device
 
Run Hcitoo--help to see more related commands
 
And then we activate it:
 
The code is as follows:
 
sudo hciconfig hci0 up
 
Note that Bluetooth must be turned on before activation, or the following error will occur:
     
And then we started scanning:
 
The code is as follows:
 
Hcitool Scan
     
Can see, found my mobile phone Bluetooth ~ ~
 
And then we're going to start connecting, and the main command used in the connection phase is Rfcomm:
 
Run Rfcomm--help to view usage
 
First you need to bind the destination Bluetooth device:
 
The code is as follows:
 
sudo rfcomm bind/dev/rfcomm0 e0:a6:70:8c:a3:02
 
Note: This address above is the hardware address of the destination Bluetooth device
 
Then we connect it:
 
The code is as follows:
 
sudo cat >/dev/rfcomm0
 
This is the destination Bluetooth host will pop up a dialog box requires input pin, random input, and then the host will pop up a dialog box, as long as the input and just agree to pass the verification. Then we found out that my phone has shown a successful pairing tag.
 
After the pairing is complete we need to remove the bindings (otherwise the device will be prompted to be busy the next time it is used), and the commands are as follows:
 
The code is as follows:
 
sudo rfcomm release/dev/rfcomm0
 
Use rfkill soft switch Bluetooth and wireless function under Linux
 
Many computer systems contain radio transmissions, including Wi-Fi, Bluetooth, and 3G devices. These devices consume power and are a waste of energy when they are not used.
 
Rfkill is a subsystem in the Linux kernel that provides an interface to query, activate, and deactivate radio transmissions in a computer system. When you deactivate a transfer, you can leave it in a state where the software can be reactivated (a soft lock) or where the software cannot be reactivated (hard lock).
 
Rfkill provides an application programming interface (API) for the kernel subsystem. Kernel drivers are designed to support Rfkill use this API to register the kernel and include methods to enable and disable this device. In addition, Rfkill provides user-programmable notifications and methods for user programs to query the transmission status.
 
The Rfkill interface is located in/dev/rfkill, which contains the current state of all radio transmissions in the system. Each device registers the current Rfkill state in Sysfs. In addition, Rfkill emits uevents whenever the status changes in a Rfkill-enabled device.
 
Rfkill is a command-line tool that you can use to query and change Rfkill-enabled devices in your system. To obtain this tool, install the Rfkill package.
 
If you can search the wireless network and enter the correct password but still can't access it, it may be rfkill this program blocks access, it is a soft switch used to control the use of wireless networks and Bluetooth.
 
Use the command Rfkill list to get the device listing, each containing the index number associated with it, starting with 0.
 
The code is as follows:
 
Rfkill List
     
You can use this index number to make Rfkill stop or use a device, for example:
 
The code is as follows:
 
Rfkill Block 0
 
Deactivate the first Rfkill-enabled device in the system.
 
You can also use Rfkill to block a certain type of device, or all Rfkill enabled devices. For example:
 
The code is as follows:
 
Rfkill Block WiFi
 
Deactivate all Wi-Fi devices in the system. To deactivate all Rfkill enabled devices, run:
 
The code is as follows:
 
Rfkill Block All
 
To reuse your device, run Rfkill unblock. To obtain a list of complete device categories that Rfkill can deactivate, run Rfkill help.