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

Write tutorials and howtos in here
There are more tutorials here http://community.linuxmint.com/tutorial/welcome
Forum rules
Do not start a support topic here please. Before you post please read this

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

Postby jbb on Sat Feb 09, 2013 10:24 am

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
jbb
Level 1
Level 1
 
Posts: 19
Joined: Wed Apr 15, 2009 10:52 pm

Linux Mint is funded by ads and donations.
 

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

Postby randydevilad on Fri May 10, 2013 6:56 am

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 :(
randydevilad
Level 1
Level 1
 
Posts: 2
Joined: Thu May 09, 2013 1:36 pm


Return to Tutorials / Howtos

Who is online

Users browsing this forum: No registered users and 10 guests