Bluetooth
You can use bluetoothctl and bluetooth to control bluetooth devices
To check the status of bluetooth
rfkill
ID TYPE DEVICE SOFT HARD
0 wlan phy0 unblocked unblocked
1 bluetooth hci0 blocked unblocked
To turn bluetooth on (replace on with off to turn bluetooth off)
bluetooth on
bluetooth = on
kapper@xps:~/dot$ rfkill
ID TYPE DEVICE SOFT HARD
0 wlan phy0 unblocked unblocked
1 bluetooth hci0 unblocked unblocked
rfkill
ID TYPE DEVICE SOFT HARD
0 wlan phy0 unblocked unblocked
1 bluetooth hci0 unblocked unblocked
To scan and connect to devices, run bluetoothctl to enter a bluetooth shell
bluetoothctl
Agent registered
[bluetooth]#
Now, we can start a scan with scan on
[bluetooth]# scan on
Discovery started
[CHG] Controller AC:74:B1:85:27:98 Discovering: yes
[NEW] Device 6A:0C:07:6A:09:EC Inspire HR
[NEW] Device 48:FE:3D:EB:C8:C3 48-FE-3D-EB-C8-C3
[NEW] Device EB:28:A2:3E:99:3F One
After scanning for some time, type devices to see the devices discovered in a list. While doing this, we can stop the scan so our output isn't messed with.
[bluetooth]# scan off
Discovery stopped
[CHG] Controller AC:74:B1:85:27:98 Discovering: no
[CHG] Device 6B:98:C9:C1:86:6C RSSI is nil
[CHG] Device 59:A5:50:BA:7E:4E RSSI is nil
[CHG] Device 66:05:2D:A4:AF:D2 RSSI is nil
[CHG] Device 50:32:37:84:CB:D4 TxPower is nil
[CHG] Device 50:32:37:84:CB:D4 RSSI is nil
[CHG] Device 03:0D:0F:0F:E9:51 RSSI is nil
[CHG] Device 6A:81:34:01:76:C0 RSSI is nil
[CHG] Device EB:28:A2:3E:99:3F TxPower is nil
[CHG] Device EB:28:A2:3E:99:3F RSSI is nil
[CHG] Device 48:FE:3D:EB:C8:C3 RSSI is nil
[CHG] Device 6A:0C:07:6A:09:EC RSSI is nil
[bluetooth]# devices
Device 50:32:37:84:CB:D4 50-32-37-84-CB-D4
Device 90:DD:5D:98:3A:E7 90-DD-5D-98-3A-E7
Device F9:EB:78:07:17:4B Dell Keybd KB7221W
Device 28:11:A5:34:08:2C Dumbo
Device 34:82:C5:F8:04:F3 Sam
Device E6:4E:7A:3F:FD:E7 Dell Mouse MS5320W
Device F9:EB:78:08:17:4B Dell Keybd KB7221W
Device E6:4E:7A:57:FD:E7 Dell Mouse MS5320W
Device F9:EB:78:04:17:4B Dell Keybd
Device 6A:0C:07:6A:09:EC Inspire HR
Device 48:FE:3D:EB:C8:C3 48-FE-3D-EB-C8-C3
Device EB:28:A2:3E:99:3F One
Device 6A:81:34:01:76:C0 Family Room TV
Now, if we want to pair, simply type pair followed by the ID for the device
[bluetooth]# pair F9:07:78:DA:17:4B
Attempting to pair with F9:07:78:DA:17:4B
[CHG] Device F9:07:78:DA:17:4B Connected: yes
[agent] Passkey: 221692
[NEW] Primary Service (Handle 0x4461)
/org/bluez/hci0/dev_F9_07_78_DA_17_4B/service000a
00001801-0000-1000-8000-00805f9b34fb
Generic Attribute Profile
[NEW] Primary Service (Handle 0x4461)
/org/bluez/hci0/dev_F9_07_78_DA_17_4B/service000b
0000180a-0000-1000-8000-00805f9b34fb
Device Information
[NEW] Characteristic (Handle 0x4461)
/org/bluez/hci0/dev_F9_07_78_DA_17_4B/service000b/char000c
00002a29-0000-1000-8000-00805f9b34fb
Manufacturer Name String
[NEW] Characteristic (Handle 0x4461)
/org/bluez/hci0/dev_F9_07_78_DA_17_4B/service000b/char000e
00002a50-0000-1000-8000-00805f9b34fb
PnP ID
[CHG] Device F9:07:78:DA:17:4B UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device F9:07:78:DA:17:4B UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device F9:07:78:DA:17:4B UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
[CHG] Device F9:07:78:DA:17:4B UUIDs: 0000180f-0000-1000-8000-00805f9b34fb
[CHG] Device F9:07:78:DA:17:4B UUIDs: 00001812-0000-1000-8000-00805f9b34fb
[CHG] Device F9:07:78:DA:17:4B ServicesResolved: yes
[CHG] Device F9:07:78:DA:17:4B Paired: yes
Pairing successful
[CHG] Device F9:07:78:DA:17:4B Name: Dell Keybd KB7221W
[CHG] Device F9:07:78:DA:17:4B Alias: Dell Keybd KB7221W
[CHG] Device F9:07:78:DA:17:4B Modalias: usb:v413Cp2511d0001
[Dell Keybd ]#
This device just happens to be a keyboard, so I'm asked to type the pascode 221692 on the keyboard, then press enter. Once I do this, the pair is completed and the devices are paired.
Next time you enable bluetooth with bluetooth on, and then you turn on this keyboard, the devices will automatically attempt to connect.