[HOW TO] Pair Bluetooth Devices Using Terminal When GUI Wont

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Post Reply
jbb

[HOW TO] Pair Bluetooth Devices Using Terminal When GUI Wont

Post by jbb »

I am writing this because recently I purchased my first Bluetooth device and could not get it to work on a fresh install of Linux Mint Cinnamon 14 (64-bit). After doing a myriad of searches around the web for my particular device, I concluded that this is not just an issue with Mint, but also other Ubuntu based distributions and devices as well. While this will most likely not solve all pairing issues, hopefully the information below may be of some use to people struggling to get some (newer perhaps?) devices working.

Just before I continue, I am by no means a Linux guru; so if anyone sees something that is incorrect, or has a better understanding of what the issue is please let me know!


THE PROBLEM
When trying to use the default GUI Bluetooth connection program, gnome-control-center bluetooth, to connect my keyboard, it would always fail pairing the device even though I was entering the passkey correctly.
Part of me thought that perhaps it was a user privilege problem, so I also tried running it as su and sudo to no avail.

There were plenty of websites suggesting to select the 'do not pair' option, which would require me re-connecting the keyboard every time I restarted the computer; this was simply not an acceptable option for me. As the device I was trying to connect was my input device, it was imperative to have it setup before logging in to the desktop environment.

After a couple of hours of trying different methods with the GUI, I gave up and decided to try with the terminal instead, although I thought it would behave the same as the UI. Part of me was a little stumped as to why it is not the case??


A GLIMMER OF HOPE
After reading around numerous websites, I stumbled across this one http://devasive.blogspot.com.au/2012/11 ... iring.html which apparently would solve my problem, especially seeming this was the very keyboard I was trying to pair. Unfortunately for whatever reason, the steps on this page did not solve my problem either. In fact, in one way it actually made my problem worse, by simply giving me a time out error with no other indication of what was happening with my Bluetooth device.

Digging a little bit deeper, I started to look up the Linux Bluetooth protocol on http://www.bluez.org and learnt about a few other packages/tools that could assist with the main program. Using Synaptic I downloaded two packages that seemed like a good place to start; albeit I only ended up using one of the packages to find a fix. Maybe the other package may provide useful for people who cannot get their devices to work properly.
  • bluez-tools
    Bluez-tools provides command line tools to functions of Bluetooth.
    They are Bluetooth adapter control, Bluetooth agent, sound, input, network
    and other.

    bluez-hcidump
    The hcidump utility allows the monitoring of Bluetooth activity. It
    provides a disassembly of the Bluetooth traffic and can display packets
    from higher level protocols such as RFCOMM, SDP and BNEP.
Following the guide linked above, once you type in "sudo bluez-simple-agent hci0 XX:XX:XX:XX:XX:XX" the computer just seems to sit there for a while thinking, and then throws a timeout error. Using the 'bluez-hcidump' tool, you can see what it is actually doing; waiting for a the passkey to pair the devices. It also has the bonus of showing you the passkey, enabling you to enter it into the K810 before the connection times out.


SOLUTION
So after a little bit of reading to work out how 'bluez-hcidump' tool worked, I came up with the following solution to pair my Bluetooth device to my computer.
  • Turn on PC Bluetooth and set to discoverable
  • Turn on Bluetooth device, and set to discoverable
  • In a new terminal type:

    Code: Select all

    hcitool scan
    and copy mac address XX:XX:XX:XX:XX:XX of the device
  • Now in another terminal type (switches are for ascii output, and date stamped):

    Code: Select all

    sudo hcidump -at
  • You should get output similar to what is posted below (followed by a blinking cursor):
    HCI sniffer - Bluetooth packet analyzer ver 2.4
    device: hci0 snap_len: 1028 filter: 0xffffffffffffffff
  • Assuming the device is on 'hci0', switch back to your original terminal and type:

    Code: Select all

    sudo bluez-simple-agent hci0 XX:XX:XX:XX:XX:XX
  • Now in the hcidump terminal you will see a few things scroll past until you get something that looks like:
    2013-02-07 15:35:40.653393 > HCI Event: User Passkey Notification (0x3b) plen 10
    bdaddr XX:XX:XX:XX:XX:XX passkey xxxxxx
  • Type the 'passkey' in and press ENTER
  • In the original terminal, on success you should get "Release" and "New device (/org/bluez/..."
  • Now set device as trusted:

    Code: Select all

    sudo bluez-test-device trusted XX:XX:XX:XX:XX:XX yes
  • You might have a connection now, but still need to:

    Code: Select all

    sudo bluez-test-input connect XX:XX:XX:XX:XX:XX
That should be it :D
randydevilad

Re: [HOW TO] Pair Bluetooth Devices Using Terminal When GUI

Post by randydevilad »

Hi i want to change over to linux mint but my logitech k810 keyboard wont pair up... im thinking just to stay with windows 7, i just read what you have done and i am totally confused as to hot to make my k810 keyboard work :((((((((( HELPPPPPPPPPPPPPPPPPPPPPP :(
User avatar
desQEDo
Level 1
Level 1
Posts: 40
Joined: Mon Jun 01, 2009 10:32 am

Re: [HOW TO] Pair Bluetooth Devices Using Terminal When GUI

Post by desQEDo »

Update: I found that the connection to the K810 was not consistent. I sometimes get a few intended double keystrokes dropped, even after playing with the settings which I found to be quite non-linear and therefore somewhat difficult to set as the sliders seemed to have a "tipping" point. I also did what is suggested here (http://community.linuxmint.com/tutorial/view/703) that improved things a bit by changing "hiddev*" to "hidraw*" in /lib/udev/rules.d/97-bluetooth-hid2hci.rules, which is a different file with the same function... I'm still not completely sold on the connection issue under MATE. I might try the more radical suggestion from here (http://forums.linuxmint.com/viewtopic.php?t=102417&f=206) to nuke the MATE Bluetooth utility and go with Blueman when I get some time... This is al on the Asus P9X79_PRO MB with 32MB RAM running LM15 64 MATE. :roll:
The MAc K811 works perfectly OOTB with iMac, iPhone & iPad mini! :D

I just bought two of these great keyboards, one for the wife's Mac, iPad & iPhone (K811) and one (K810) for my Asus P9X79 PRO to replace a quite old (over 6 yrs) but really great diNovo Edge. The Mac was simple to pair, the PC on Linux went according to the above instructions for which my heartfelt thanks!
Sometimes though the K810 waits after keystrokes before showing input and sometimes repeats keystrokesssss when nooooot asked to... as demonsssstrated here.
Any ideas for a solution? I already tried the BT keyboard preferences Repeat Keys Delay, Speed & Bounce settings to no avail.
I have also paired the K810 with an Android SGTab 7.7 and a Mac mini and they work fine together as I don't have big demands on the Mac specific keys.
One request to help out randydevilad should he/she not yet have found a solution and to be sure myself: please say which terminal window(s) the final two commands should be executed in – at the end two are still open...
Again, many thanks!
MarkMT

Re: [HOW TO] Pair Bluetooth Devices Using Terminal When GUI

Post by MarkMT »

I'm having the same problem described here and the steps described by jbb sound like a possible solution. However I don't have hcidump on my system - Linux Mint 14. Apparently it's not in the repo. I tried -

sudo apt-get install bluez-hcidump

and get -

Package bluez-hcidump is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

When I try

sudo apt-get install bluez-tools

I get -

E: Unable to locate package bluez-tools

Any suggestions?
MarkMT

Re: [HOW TO] Pair Bluetooth Devices Using Terminal When GUI

Post by MarkMT »

Ok, I managed to solve this myself...

From this page -

https://launchpad.net/ubuntu/trusty/+so ... dump/2.5-1

I downloaded the file - bluez-hcidump_2.5.orig.tar.xz

extracted it and followed the compile instructions in the README. I was then able to follow jbb's instructions and everything proceeded as advertised. I am now typing this on my K810 :).
WhiteListed

Re: [HOW TO] Pair Bluetooth Devices Using Terminal When GUI

Post by WhiteListed »

Hello Guys,

Just an quick update for everyone who is still trying to pair the Logitech K810 (If you are doubting: Don´t, just buy it! You will not regret!):

Follow the instructions provided here, but make sure you press the "connect" button at the rear side of the keyboard, it is not mentioned explicitly in this topic and I thought I would mention it, since there are other ways to connect to the Logitech K810.... If you have pressed the connect button succesful, all three "connection lights" start blinking. At this point, just follow the rest of the tutorial(Thanks for it BTW!).

When trying to connect by just pressing the bluetooth 1 button, there was no key pairing visible in the hcidump -at window.

Goodluck, and if you still have a question you can just PM and I will try to help you.

--WhiteListed
davemaster

Re: [HOW TO] Pair Bluetooth Devices Using Terminal When GUI

Post by davemaster »

Hi guys, just sharing the experience how i got mine logitech k810 working.

I needed to push te connect button on the underside of the keyboard at the beginning of the process, as 'WhiteListed' posted a few months ago. Then, before i entered the line:

Code: Select all

sudo bluez-test-input connect XX:XX:XX:XX:XX:XX
into the terminal, I had to push the Bluetooth button Nr.1 (or 2 or 3 - whichever you need) on the Logitech k810 to enable it to connect and save the settings on the keyrboard. Afterwards it connects to the computer with no problem every time.

Hope it helps
Cheers
camilaran

Re: [HOW TO] Pair Bluetooth Devices Using Terminal When GUI

Post by camilaran »

Thank you very much jbb. I have passed all the day trying to connect my cell phone to my computer without success until I found your post.
namalk

Re: [HOW TO] Pair Bluetooth Devices Using Terminal When GUI

Post by namalk »

Though it was bit old post, it works fine for me - with my Dell Travel mouse. This is a good alternative to GUI which is not reliable all the time.
namalk

Re: [HOW TO] Pair Bluetooth Devices Using Terminal When GUI

Post by namalk »

Please help me if you could...

I have gone through all the steps and successfully connected my Dell Travel mouse. But the problem is when I reboot the laptop, again I have to connect with the same commands. Some times mouse pointer was disappeared.

Can anyone suggest a solution to this???
mormegil

Re: [HOW TO] Pair Bluetooth Devices Using Terminal When GUI Wont

Post by mormegil »

Hello everyone,

Recently I have bought a Logitech MX Anywhere 2S mouse. I have encountered issues with pairing it via bluetooth on my Linux Mint, however I could successfully overcome my difficulties. For the reference: I am using blueman (ver. 2.0.4-1ubuntu2), not the pre-installed bluetooth manager app.
Here is my solution, maybe someone will find it useful:

Code: Select all

bartlomiej@Latitude-7480 ~ $ uname -a
Linux Latitude-7480 4.13.0-37-generic #42~16.04.1-Ubuntu SMP Wed Mar 7 16:03:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
bartlomiej@Latitude-7480 ~ $ rfkill unblock bluetooth 
bartlomiej@Latitude-7480 ~ $ sudo bluetoothctl 
[NEW] Controller 90:61:AE:xx:xx:xx Latitude-7480 [default]
[NEW] Device FC:75:A6:xx:xx:xx MX Anywhere 2S
[bluetooth]# version
Version 5.37
[bluetooth]# default-agent 
No agent is registered
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent 
Default agent request successful
[DEL] Device FC:75:A6:xx:xx:xx MX Anywhere 2S
[bluetooth]# scan on
Discovery started
[CHG] Controller 90:61:AE:xx:xx:xx Discovering: yes
[NEW] Device FC:75:A6:xx:xx:xx MX Anywhere 2S
[bluetooth]# pair FC:75:A6:xx:xx:xx
Attempting to pair with FC:75:A6:xx:xx:xx
[CHG] Device FC:75:A6:xx:xx:xx Connected: yes
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 0000180f-0000-1000-8000-00805f9b34fb
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 00001812-0000-1000-8000-00805f9b34fb
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 00010000-0000-1000-8000-011f2000046d
[CHG] Device FC:75:A6:xx:xx:xx Paired: yes
Pairing successful
[CHG] Device FC:75:A6:xx:xx:xx Modalias: usb:v046DpB01Ad0003
[MX Anywhere 2S]# trust
[CHG] Device FC:75:A6:xx:xx:xx Trusted: yes
Changing  trust succeeded
[MX Anywhere 2S]# connect FC:75:A6:xx:xx:xx
Attempting to connect to FC:75:A6:xx:xx:xx
Connection successful
[MX Anywhere 2S]# unblock
Changing  unblock succeeded
[MX Anywhere 2S]# power off
[CHG] Device FC:75:A6:xx:xx:xx Connected: no
Changing power off succeeded
[CHG] Controller 90:61:AE:xx:xx:xx Powered: no
[CHG] Controller 90:61:AE:xx:xx:xx Discovering: no
[CHG] Controller 90:61:AE:xx:xx:xx Class: 0x000000
[CHG] Device FC:75:A6:xx:xx:xx RSSI is nil
[bluetooth]# power on
[CHG] Controller 90:61:AE:xx:xx:xx Class: 0x1c010c
Changing power on succeeded
[CHG] Controller 90:61:AE:xx:xx:xx Powered: yes
[CHG] Device FC:75:A6:xx:xx:xx Connected: yes
[MX Anywhere 2S]# quit
Agent unregistered
[DEL] Controller 90:61:AE:xx:xx:xx Latitude-7480 [default]
bartlomiej@Latitude-7480 ~ $ 

Last edited by mormegil on Sat Oct 13, 2018 3:46 am, edited 2 times in total.
haanssim

Re: [HOW TO] Pair Bluetooth Devices Using Terminal When GUI Wont

Post by haanssim »

mormegil wrote: Fri Mar 23, 2018 7:03 am Hello everyone,

Recently I have bought a Logitech MX Anywhere 2S mouse. I have encountered issues with pairing it via bluetooth on my Linux Mint, however I could successfully overcome my difficulties. For the reference: I am using blueman (ver. 2.0.4-1ubuntu2), not the pre-installed bluetooth manager app.
Here is my solution, maybe someone will find it useful:

Code: Select all

bartlomiej@Latitude-7480 ~ $ uname -a
Linux Latitude-7480 4.13.0-37-generic #42~16.04.1-Ubuntu SMP Wed Mar 7 16:03:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
bartlomiej@Latitude-7480 ~ $ rfkill unblock bluetooth 
bartlomiej@Latitude-7480 ~ $ sudo bluetoothctl 
[NEW] Controller 90:61:AE:xx:xx:xx Latitude-7480 [default]
[NEW] Device FC:75:A6:15:B8:57 MX Anywhere 2S
[bluetooth]# version
Version 5.37
[bluetooth]# default-agent 
No agent is registered
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent 
Default agent request successful
[DEL] Device FC:75:A6:15:B8:57 MX Anywhere 2S
[bluetooth]# scan on
Discovery started
[CHG] Controller 90:61:AE:xx:xx:xx Discovering: yes
[NEW] Device FC:75:A6:xx:xx:xx MX Anywhere 2S
[bluetooth]# pair FC:75:A6:xx:xx:xx
Attempting to pair with FC:75:A6:xx:xx:xx
[CHG] Device FC:75:A6:xx:xx:xx Connected: yes
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 0000180f-0000-1000-8000-00805f9b34fb
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 00001812-0000-1000-8000-00805f9b34fb
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 00010000-0000-1000-8000-011f2000046d
[CHG] Device FC:75:A6:xx:xx:xx Paired: yes
Pairing successful
[CHG] Device FC:75:A6:xx:xx:xx Modalias: usb:v046DpB01Ad0003
[MX Anywhere 2S]# trust
[CHG] Device FC:75:A6:xx:xx:xx Trusted: yes
Changing  trust succeeded
[MX Anywhere 2S]# connect FC:75:A6:xx:xx:xx
Attempting to connect to FC:75:A6:xx:xx:xx
Connection successful
[MX Anywhere 2S]# unblock
Changing  unblock succeeded
[MX Anywhere 2S]# power off
[CHG] Device FC:75:A6:xx:xx:xx Connected: no
Changing power off succeeded
[CHG] Controller 90:61:AE:xx:xx:xx Powered: no
[CHG] Controller 90:61:AE:xx:xx:xx Discovering: no
[CHG] Controller 90:61:AE:xx:xx:xx Class: 0x000000
[CHG] Device FC:75:A6:xx:xx:xx RSSI is nil
[bluetooth]# power on
[CHG] Controller 90:61:AE:xx:xx:xx Class: 0x1c010c
Changing power on succeeded
[CHG] Controller 90:61:AE:xx:xx:xx Powered: yes
[CHG] Device FC:75:A6:xx:xx:xx Connected: yes
[MX Anywhere 2S]# quit
Agent unregistered
[DEL] Controller 90:61:AE:xx:xx:xx Latitude-7480 [default]
bartlomiej@Latitude-7480 ~ $ 

thank you, now i can connect my mouse using bluetooth connection !
dilettante

Re: [HOW TO] Pair Bluetooth Devices Using Terminal When GUI Wont

Post by dilettante »

mormegil wrote: Fri Mar 23, 2018 7:03 am Hello everyone,

Recently I have bought a Logitech MX Anywhere 2S mouse. I have encountered issues with pairing it via bluetooth on my Linux Mint, however I could successfully overcome my difficulties. For the reference: I am using blueman (ver. 2.0.4-1ubuntu2), not the pre-installed bluetooth manager app.
Here is my solution, maybe someone will find it useful:

Code: Select all

bartlomiej@Latitude-7480 ~ $ uname -a
Linux Latitude-7480 4.13.0-37-generic #42~16.04.1-Ubuntu SMP Wed Mar 7 16:03:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
bartlomiej@Latitude-7480 ~ $ rfkill unblock bluetooth 
bartlomiej@Latitude-7480 ~ $ sudo bluetoothctl 
[NEW] Controller 90:61:AE:xx:xx:xx Latitude-7480 [default]
[NEW] Device FC:75:A6:xx:xx:xx MX Anywhere 2S
[bluetooth]# version
Version 5.37
[bluetooth]# default-agent 
No agent is registered
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent 
Default agent request successful
[DEL] Device FC:75:A6:xx:xx:xx MX Anywhere 2S
[bluetooth]# scan on
Discovery started
[CHG] Controller 90:61:AE:xx:xx:xx Discovering: yes
[NEW] Device FC:75:A6:xx:xx:xx MX Anywhere 2S
[bluetooth]# pair FC:75:A6:xx:xx:xx
Attempting to pair with FC:75:A6:xx:xx:xx
[CHG] Device FC:75:A6:xx:xx:xx Connected: yes
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 0000180f-0000-1000-8000-00805f9b34fb
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 00001812-0000-1000-8000-00805f9b34fb
[CHG] Device FC:75:A6:xx:xx:xx UUIDs: 00010000-0000-1000-8000-011f2000046d
[CHG] Device FC:75:A6:xx:xx:xx Paired: yes
Pairing successful
[CHG] Device FC:75:A6:xx:xx:xx Modalias: usb:v046DpB01Ad0003
[MX Anywhere 2S]# trust
[CHG] Device FC:75:A6:xx:xx:xx Trusted: yes
Changing  trust succeeded
[MX Anywhere 2S]# connect FC:75:A6:xx:xx:xx
Attempting to connect to FC:75:A6:xx:xx:xx
Connection successful
[MX Anywhere 2S]# unblock
Changing  unblock succeeded
[MX Anywhere 2S]# power off
[CHG] Device FC:75:A6:xx:xx:xx Connected: no
Changing power off succeeded
[CHG] Controller 90:61:AE:xx:xx:xx Powered: no
[CHG] Controller 90:61:AE:xx:xx:xx Discovering: no
[CHG] Controller 90:61:AE:xx:xx:xx Class: 0x000000
[CHG] Device FC:75:A6:xx:xx:xx RSSI is nil
[bluetooth]# power on
[CHG] Controller 90:61:AE:xx:xx:xx Class: 0x1c010c
Changing power on succeeded
[CHG] Controller 90:61:AE:xx:xx:xx Powered: yes
[CHG] Device FC:75:A6:xx:xx:xx Connected: yes
[MX Anywhere 2S]# quit
Agent unregistered
[DEL] Controller 90:61:AE:xx:xx:xx Latitude-7480 [default]
bartlomiej@Latitude-7480 ~ $ 

This also worked really well for me pairing a MS Arc Touch Mouse SE with Linux Mint Cinnamon 18.1 Serena, after the built-in Bluetooth manager didn't work.
Thanks, mormegil.
mattz
Level 1
Level 1
Posts: 3
Joined: Tue Dec 31, 2019 3:57 pm
Location: So. Cal., USA

Re: [HOW TO] Pair Bluetooth Devices Using Terminal When GUI Wont

Post by mattz »

Fwiw, this worked for me on LMC21.1 (vera) with a Logitech M557. I've always had trouble pairing the 557 with LMC (not sure why). Many thanks for your post!
Post Reply

Return to “Tutorials”