Connecting to Bluetooth on Linux is easy when you use the Bluetoothctl utility. This makes connecting to an Android phone with Bluetooth very simple. I am using Ubuntu for this article on my server.
After plugging in my USB Bluetooth adapter, I was able to connect to my Android phone using Bluetooth.
Run the bluetoothctl command to start the bluetoothctl utility.
jason@jason-Lenovo-H50-55:~$ bluetoothctl Agent registered [CHG] Controller 00:13:46:00:A9:12 Pairable: yes [bluetooth]# help Menu main: Available commands: ------------------- advertise Advertise Options Submenu scan Scan Options Submenu gatt Generic Attribute Submenu list List available controllers show [ctrl] Controller information select <ctrl> Select default controller devices List available devices paired-devices List paired devices system-alias <name> Set controller alias reset-alias Reset controller alias power <on/off> Set controller power pairable <on/off> Set controller pairable mode discoverable <on/off> Set controller discoverable mode discoverable-timeout [value] Set discoverable timeout agent <on/off/capability> Enable/disable agent with given capability default-agent Set agent as the default one advertise <on/off/type> Enable/disable advertising with given type set-alias <alias> Set device alias scan <on/off> Scan for devices info [dev] Device information pair [dev] Pair with device trust [dev] Trust device untrust [dev] Untrust device block [dev] Block device unblock [dev] Unblock device remove <dev> Remove device connect <dev> Connect device disconnect [dev] Disconnect device menu <name> Select submenu version Display version quit Quit program exit Quit program help Display help about this program export Print environment variables |
Then run the scan on command to begin scanning for other Bluetooth devices.
[bluetooth]# scan on Discovery started [CHG] Controller 00:13:46:00:A9:12 Discovering: yes |
Then list all devices like this.
[bluetooth]# devices [NEW] Device DC:DC:E2:AA:EE:41 DC-DC-E2-AA-EE-41 [CHG] Device DC:DC:E2:AA:EE:41 LegacyPairing: no [CHG] Device DC:DC:E2:AA:EE:41 RSSI: 127 [CHG] Device DC:DC:E2:AA:EE:41 Name: iPhone 5+ [CHG] Device DC:DC:E2:AA:EE:41 Alias: iPhone 5+ [CHG] Device DC:DC:E2:AA:EE:41 LegacyPairing: yes [CHG] Device DC:DC:E2:AA:EE:41 RSSI is nil |
Actually pairing the device is done like this.
[bluetooth]# pair DC:DC:E2:AA:EE:41 Attempting to pair with DC:DC:E2:AA:EE:41 [CHG] Device DC:DC:E2:AA:EE:41 Connected: yes Request PIN code [agent] Enter PIN code: 6123 |
Getting information about a connected device is pretty easy. Just run this command.
[bluetooth]# info DC:DC:E2:AA:EE:41 Device DC:DC:E2:AA:EE:41 (public) Name: iPhone 5+ Alias: iPhone 5+ Class: 0x005a020c Icon: phone Paired: yes Trusted: no Blocked: no Connected: no LegacyPairing: yes |
Then you are all set. This is pretty easy to do and shows how flexible Linux is.