Bluetooth Keyboard in XBMC on Raspbmc


29 posts   Page 1 of 2   1, 2
by jonez » Mon Dec 24, 2012 8:54 pm
Got my Pi today and installed Raspbmc using their installer. Using this guide I was able to pair a Bluetooth keyboard with my Pi: http://www.ctheroux.com/2012/08/a-step- ... pberry-pi/

XBMC doesn't seem to respond to any key presses? It seems I'm missing the keyboard.xml file? I tried creating the file /home/pi/.xbmc/userdata/keymaps/keyboard.xml and pasting the contents in from here: https://raw.github.com/xbmc/xbmc/Eden/s ... yboard.xml The directory was empty after a fresh install.
Code: Select all
pi@raspbmc:~/.xbmc/userdata/keymaps$ ls -la
total 520
drwxr-xr-x 2 pi pi   4096 Dec 24 16:22 .
drwxr-xr-x 9 pi pi   4096 Dec 24 11:59 ..
-rw-r--r-- 1 pi pi 521581 Dec 24 16:22 keyboard.xml
pi@raspbmc:~/.xbmc/userdata/keymaps$
Any ideas on what I need to do to get it to work? Thanks!
Posts: 11
Joined: Tue Dec 11, 2012 6:54 pm
by Dilligaf » Mon Dec 24, 2012 10:51 pm
try this after pairing keyboard
Code: Select all
sudo initctl stop xbmc
sudo initctl start xbmc


If the keyboard then works it means you need to pair the keyboard before xbmc launches, you can do this by pairing the keyboard with a .conf file in /etc/init/ and editing xbmc.conf to require the keyboard .init to run before it launches. You may be able to achieve the same by simply adding a "sleep x" command to xbmc.conf where x is the number of seconds to delay launch. Something like this:
Code: Select all
pre-start script
sleep 10
test -x /scripts/xbmc-watchdog.sh || { stop; logger -t xbmc "cannot execute /scripts/xbmc-watchdog.sh, exiting" ; exit 1; }
FBSET="/bin/fbset"
if [ -e $FBSET ]; then
    FB_RESOLUTION=$(fbset | grep geometry | awk '{print "-xres "$2" -yres "$3" -vxres "$4" -vyres "$5}')
    if [ ! -f /tmp/fb_resolution ]; then
    echo $FB_RESOLUTION > /tmp/fb_resolution
    fi
fi
end script

Note the added sleep 10 line which will delay the script from running for 10 seconds
Posts: 283
Joined: Wed May 23, 2012 6:48 pm
by jonez » Wed Dec 26, 2012 2:01 pm
Thanks for the reply Dilligaf.

Unfortunately the timeout trick didn't work. The only way I can get the keyboard to work is to boot the Pi with a USB keyboard plugged in. When I exit XBMC via the menu/esc, I can use bluez-test-input connect (typing on the USB keyboard) to get the Bluetooth keyboard working in the terminal. When I launch XBMC, it continues to work, which leads me believe you are correct in that it has to be active before XBMC starts. After successfully connecting, when I reboot the Pi it looses connection to the Bluetooth Keyboard. Trying to pair/connect via SSH doesn't seem to work at all, I have to run the commands on the Pi from a USB keyboard. I don't get any errors, but it doesn't respond to key presses other then the challenge/response when pairing.

I'm guessing I need to use your other approach,
If the keyboard then works it means you need to pair the keyboard before xbmc launches, you can do this by pairing the keyboard with a .conf file in /etc/init/ and editing xbmc.conf to require the keyboard .init to run before it launches.

Do you have a link or any additional info on how I might accomplish this?

Thanks again!
Posts: 11
Joined: Tue Dec 11, 2012 6:54 pm
by migube » Mon Jan 21, 2013 9:05 pm
I never myself to get it fully working, as after sometimes it goes in standby, and even if it worked first in xmbc, and works back on the linux behind XBMC, XBMC won't recognize the keyboard 's back, without restarting xbmc :(
didn't find any fix yet...
Posts: 28
Joined: Tue Jul 17, 2012 7:02 am
by Metatronin » Mon Jan 21, 2013 10:09 pm
if you have an android device, they make an XBMC controller app that works great with it on the Pi. If the pi is connected(through ethernet) to a wi-fi router it seems to be a better set up than going with bluetooth at the moment.

Another alternative is to install XBMC directly within raspbian to see if bluetooth works that way(or use the android app). I have XBMC installed within raspbian myself, so I can use an android device as a controller while using XBMC, or use tightVNC and a vnc client(on the android device) to use the android device as a mobile touchscreen for the Raspi. This way, I can leave the raspi on and access it anywhere as long as I have phone sevice or wifi. This also lets you use your raspi(and XBMC) anywhere even though you have it physically somewhere else.
Posts: 55
Joined: Sat Aug 04, 2012 5:19 am
by Dilligaf » Tue Jan 22, 2013 1:22 am
Sorry, never saw the replies to my earlier post till just now. Raspbmc uses upstart an event driven startup process, if you do a Google there are several tutorials/explanations. Ubuntu also uses upstart, their documentation is pretty good.
Posts: 283
Joined: Wed May 23, 2012 6:48 pm
by Fludizz » Thu Jan 24, 2013 11:37 am
I got a little further with this now... In the sense that when the keyboard is active (and not idle-standby) during boot, it will automatically work in xbmc. To get this to work, I changed the following line in /etc/init/xbmc.conf:
Code: Select all
start on (started dbus and started mountall and kiosk-processed)

to this:
Code: Select all
start on (started dbus and started mountall and started bluetooth and kiosk-processed)

This forces XBMC to wait with starting until bluetooth has started.

However, this ONLY works if you keep the keyboard active during XBMC startup! Whenever the keyboard goes to sleep, XBMC will no longer respond to the keyboard.

I think it is a flaw in how XBMC handles HID devices: The same problem applies to USB keyboards. If you have it plugged in during XBMC startup, you can use it and it will work. If you started XBMC without USB keyboard (or you unplugged it) and plug one in later on, the keyboard will NOT work with XBMC.

For the record: The keyboard is available to the OS. After it woke up again I can press crtl+alt+del and the Pi will reboot. It is just XBMC not picking it back up!
Rev1: D14 removed, F1&F2 bypassed and heatsinks installed. Stable at arm 900 / gpu 300 / sdram 400 :(. No overvolting!
Rev2: 512MB version, no mods, just heatsinks installed. Stable at arm 930 / gpu 350 / sdram 500. No overvolting!
User avatar
Posts: 15
Joined: Sat Jan 12, 2013 3:04 pm
by tjhomas » Sat Jan 26, 2013 11:00 pm
I am having the same problem. Adding "started bluetooth" and "sleep 10" to the xbmc.conf did not help. However, by ssh'ing in remotely and executing:

sudo initctl stop xbmc
sudo initctl start xbmc



I am able to get the bluetooth keyboard working again. Now perhaps there's a way to write a script to do that, and execute it from the xbmc interface? I am going to explore that this weekend, for the lack of better options.

Since I don't always need a keyboard, selecting a restart option from the "programs" menu whenever I do would be a feasible solution for me. Selecting "Exit" will restart XBMC, and bluetooth will work, but I'm hoping I can make it more efficient. I'll share the info if I get it working.
Posts: 1
Joined: Sat Jan 26, 2013 3:49 am
by mcneilm » Sun Jan 27, 2013 9:44 pm
Hi does anyone have any updates to this issue? I have this same issue (where xbmc loses the bluetooth keyboard after a period of inactivity, but it's still working in a terminal session, and a restart of xbmc cures the issue) and it's driving me nuts, because if this one issue gets cured, then I think rasbmc is the ultimate media player! Does anyone know if this is a similar issue with openelec or even just xbmc running on a stcok debian installation?
Posts: 3
Joined: Sun Jan 27, 2013 9:37 pm
by migube » Fri Feb 15, 2013 8:18 pm
I opened a bug tracker for it, but no response..
maybe u can support :)
http://trac.xbmc.org/ticket/14028
Posts: 28
Joined: Tue Jul 17, 2012 7:02 am
by dsire » Sun Mar 17, 2013 11:24 am
Is there any update or a fix to this? My keyboard seems to lose connectivity if it goes on idle, is there a way to fix this without having to do the running following command?

sudo initctl stop xbmc
sudo initctl start xbmc
Posts: 2
Joined: Sun Mar 17, 2013 11:21 am
by MooFoo » Mon Mar 18, 2013 11:23 pm
Bluetooth will not run on RaspBMC for me. I'm hoping someone here can help. Keep getting errors with DBUS not running, and there being LSB parameters missing for several things, including dbus. And,sudo apt-get upgrade seems to corrupt my install. Errors suggest that parts of the Raspbmc file system is read only.

Jonez, how did you get bluetooth working by just following the guide you mentioned? I've tried with several fresh images. Best I've discoverred, if I only apt-get update, not do an upgrade, I can install the bluez utils and hciconfig tool without borking everything up.

Every attempt produces the below error, which seems related to all the other LSB errors.
Code: Select all
update-rc.d: error: insserv rejected the script header


Got bluetooth usb dongle and bluetooth keyboard working on the latest Rasbian. My successes are here: http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=37482

Now, I'm attempting to carry over what I've learned to RaspBMC, but I seem to be running into some fundamental issues, ...and I'm a noob. :oops: I'm not sure how to fix all the LSB errors and get dbus running so I can start bluetooth, and then :geek:
Posts: 12
Joined: Sun Mar 17, 2013 7:42 pm
by bluem6 » Tue Mar 19, 2013 6:16 am
I have the exact same issue. Bluetooth keyboard pair and working on Raspbian build but cannot get it to work with RaspBMC, OpenElec or Xbian. I have been trying it for 3 days now and pretty much have run into some problem or or another with all of the guides out there...any help would be appreciated....
Posts: 10
Joined: Wed Jan 23, 2013 2:01 am
by dsire » Tue Mar 19, 2013 10:35 am
try
hciconfig hci0 reset then hcitool scan
Posts: 2
Joined: Sun Mar 17, 2013 11:21 am
by MooFoo » Tue Mar 19, 2013 11:11 am
Had some luck after sleeping on it. I was able to get dbus and the bluetooth service to run. Currently, I am using the bluetooth keyboard on the remote terminal, so I'll have to get a spair before I can try the pairing process.

These are my exact steps so far:
1. Start with fresh image of raspBMC.
2. Leave USB bluetooth dongle unplugged during the first run process.
3. Grab a coffee.
4. After raspBMC is done and sitting idle, I power it down and plug in the USB bluetooth dongle.
5. Power raspBMC back up, and then log into remote ssh terminal from another computer.
6. Now I run the following commands, in this order:

Switch to root:
Code: Select all
sudo bash

Do something to make dbus run (still get LSB errors, but I continue on...):
Code: Select all
update-rc.d -f dbus defaults

Update package listing, but do not upgrade:
Code: Select all
apt-get update

Only install "bluez", and not "bluetooth" since the later will drop a bunch of packages and services that are not needed and seem to break things:
Code: Select all
apt-get install bluez

Now check bluetooth status:
Code: Select all
service bluetooth status

Woot, it's running, so I check more:
Code: Select all
hciconfig

Woot, the USB bluetooth dongle is in an UP state:
For my dongle, I have to turn off SSP since the encryption interfears with my keyboard's pairing process:
Code: Select all
hciconfig hci0 sspmode 0

A quick check to see if bluetooth actually is working:
Code: Select all
hcitool scan

Devices show up.
My next step will be to go through the pairing process after work, but I'll need to grab another keyboard for that. For those steps I plan to do:
Code: Select all
sudo bluez-simple-agent hci0 XX:XX:XX:XX:XX:XX
Enter a passkey at terminal and press ENTER:
Then enter same pass key on keyboard and press ENTER:
sudo bluez-test-device trusted XX:XX:XX:XX:XX:XX yes
sudo bluez-test-input connect XX:XX:XX:XX:XX:XX
Should be paired.
Posts: 12
Joined: Sun Mar 17, 2013 7:42 pm
by bluem6 » Tue Mar 19, 2013 11:01 pm
So I got it working finally but it's only working in "terminal" and not in the gui on RaspBMC, any ideas??
Posts: 10
Joined: Wed Jan 23, 2013 2:01 am
by MooFoo » Tue Mar 19, 2013 11:05 pm
Update:

hcitool scan finds the keybord.

First attempt to; sudo bluez-simple-agent hci0 XX:XX:XX:XX:XX:XX, produces and error:

Line 3. No module named gobject. :roll: Looks like a fairly common object reference to me, but alas, I'm still a linux noob.

Analysis:
The hardware works. The bluetooth service is working and is wirelessly communicating. I know this, because hcitool detects the MAC address of the keyboard. Only thing left is sorting through the software dependency issues. Primarily, raspBMC defenitly can not be reliably updated using apt-get upgrade. In addition, there is a dependency wrapped in the "bluetooth" package that is not automatically reconciled during install. It was one of first packages installed, but it went by so fast I missed it. I think I saw perl something something, could not write to some file and error. Tried apt-get install bluetooth --simulate, which does not reproduce the issue (fresh install). Back to the books...

Does anyone know a way to install only the dependencies for bluez, without updating what looks like over a hundred packages?
Posts: 12
Joined: Sun Mar 17, 2013 7:42 pm
by MooFoo » Tue Mar 19, 2013 11:12 pm
bluem6 wrote:So I got it working finally but it's only working in "terminal" and not in the gui on RaspBMC, any ideas??


Were you able to pair the keyoard (i.e. bluez-simple-agent)? If so, what packages did you install?
Posts: 12
Joined: Sun Mar 17, 2013 7:42 pm
by bluem6 » Tue Mar 19, 2013 11:32 pm
I got it working running your instruction from above but I think it was working before too...just didn't realize it's not working in XBMC gui only. If I exit out to terminal it works fine...the only thing I added was to add a python-gobject install to your instructions...now I need to find out why it's not working in the gui....
Posts: 10
Joined: Wed Jan 23, 2013 2:01 am
by bluem6 » Wed Mar 20, 2013 6:43 pm
So I finally got it working last night but there's a hiccup...it will not work in the XBMC but if I exit out to terminal it will work instantly and let it automatically boot into XBMC gui then everything works fine...I need some help with this, any ideas???
Posts: 10
Joined: Wed Jan 23, 2013 2:01 am
by MooFoo » Thu Mar 21, 2013 12:15 am
bluem6 wrote:So I finally got it working last night but there's a hiccup...it will not work in the XBMC but if I exit out to terminal it will work instantly and let it automatically boot into XBMC gui then everything works fine...I need some help with this, any ideas???


After your post, I too was able to pair the keyboard from the terminal, but it would imediatly disconnect with the gui running. After a reboot, bluez-simple-agent started to have errors for me. I'll have to start from another image. Got some extra sd cards now.

If you have it working reliably before starting the gui, then if it was me, I'd try to find a way to execute the bluez connect utility before xbmc is started.
Code: Select all
sudo bluez-test-input connect XX:XX:XX:XX:XX:XX
Posts: 12
Joined: Sun Mar 17, 2013 7:42 pm
by bluem6 » Thu Mar 21, 2013 12:21 am
I think I got some bad news...after digging and digging it seems the issue is a "timing" thing with XBMC. I got everything to work with the XBMC gui now when it start up but there's one big problem and that is if your bluetooth device goes into standby XBMC will not recognize again. This issue is only in XBMC itself and does not happen if you're in terminal...there's a ticket created for it here at: http://trac.xbmc.org/ticket/14028.....I hope they fix this issue.
Posts: 10
Joined: Wed Jan 23, 2013 2:01 am
by MooFoo » Thu Mar 21, 2013 1:35 am
I wonder if its a simular issue to this link I found no the missing LSB tags. Seems those tags define default starting, stopping, etc, states. I can see if those are not defined, how auto discovery type services would not work.

https://bugs.launchpad.net/ubuntu/+source/dbus/+bug/430112

It's a shame really. This K810 keyboard really is the most enjoyable to use keyboard I've ever used, especially in the living room with the lights turned off. I cn almost live without the numpad, almost, but for a bluetooth, it's the best.
Posts: 12
Joined: Sun Mar 17, 2013 7:42 pm
by MooFoo » Fri Mar 22, 2013 11:16 am
bluem6 wrote:I think I got some bad news...after digging and digging it seems the issue is a "timing" thing with XBMC. I got everything to work with the XBMC gui now when it start up but there's one big problem and that is if your bluetooth device goes into standby XBMC will not recognize again. This issue is only in XBMC itself and does not happen if you're in terminal...there's a ticket created for it here at: http://trac.xbmc.org/ticket/14028.....I hope they fix this issue.


Got mine working in the same way. Then I realized, that when plugging in a wired usb keyboard after boot, it also did not work. Did more digging and found that our issue likely is not related specifically to bluetooth at all, but the fact that xbmc is not able to pick up hot-plugged devices, even though the underlying linux can. Here's some more info to complete the loop.
http://forum.stmlabs.com/showthread.php?tid=3049
Posts: 12
Joined: Sun Mar 17, 2013 7:42 pm
by bluem6 » Fri Mar 22, 2013 4:27 pm
Yep, that definitely is no good after working so hard to just get the darn thing to work..lol...any ideas on how we can "expedite" this to XBMC to get it fix?
Posts: 10
Joined: Wed Jan 23, 2013 2:01 am