Introduction

In this post I will describe my initial tests to use the PiFace to control XBMC. This post is part of a series which is indexed on its introductory post.

 

Installing and configuring needed software

I initially started with a vanilla RaspBMC to get my project started, but soon it turned out that installing the dependency needed to get all software together broke the base functionality. So instead of diving into the reasons why XBMC no longer wanted to run on my adapted RaspBMC, I restarted with a vanilla Raspbian and installed all needed components on top.

 

Installing and configuring XBMC

I installed XBMC following this very nice blogpost: XBMC for Raspberry Pi | Michael Gorven. In order to be able to use the remote interface, you will need to change some settings on your XBMC. In the System section, select Settings and look for Services. Here you should find the section Webserver. Enable the webserver, provide a username and password and select a port number. You can go with the default parameters. r change them if you want to increase your level of security.

 

Screen Shot 2014-02-18 at 20.48.55.pngScreen Shot 2014-02-18 at 20.52.54.pngScreen Shot 2014-02-18 at 20.49.10.png

We now have a webservice available on our  XBMC to control it. This can easily tested from command line with following commands:

 

pi@rpi ~ $ wget  -q --header='Content-Type: application/json' --post-data='{ "jsonrpc": "2.0", "method": "INPUT.right" , "id": 1 }' http://xbmc:xbmc@10.0.1.100:8081/jsonrpc?request





This should move the 'cursor' in XBMC one position right. As you can see, you just need to send the right JSON encoded commands to the webservice in order to control XBMC. Besides controlling XBMC, you can also fetch date from it like the item currently playing, the content of your database, basically all info needed to create a full blown remote interface. I'll probably add some more of this stuff when visualising feedback from the system.  The complete XBMC API is well documented.

 

Installing the PiFace and its libraries

 

The PiFace is an add-on board for the Raspberry Pi offering some easy to control inputs and outputs, some onboard buttons and LEDs and two relays. In the pictures below, you see the my Pi with the PiFace on top. In case you're wondering, the nice little wireless keyboard comes with the XBMC bundle.

photo 1.JPG

photo 2.JPG

In order to control the PiFace, some additional software needs to be installed and the SPI kernel module needs to be activated. This is all well documented on the PiFace Digital Install Guide. These steps worked out pretty well for me.

 

piface-xbmc-remote

 

Using Python (my first python script, so don't be to hard on me ;-) ), it was fairly easy to create a script which catches the key which was pressed on the Piface (for now I just used the buttons on the shield it self) and send a command based on which key was pressed to XBMC.

 

I uploaded the code to GitHub so feel free to fork, extend and improve!

 

I copied the code below as well and it basically consists of two parts: a class 'face' which captures the key presses and a class 'remote' which sends the JSON commands.

 

 

Running the command without parameters will show following usage message:

 

$ ./piface-xbmc-remote.py
usage: piface-xbmc-remote.py [-h] [--debug] host port username password
piface-xbmc-remote.py: error: too few arguments



 

Following parameters can be specified at the command line:

 

  • host: the hostname or IP address where your XBMC is running
  • port: portnumber where the XBMC RPC API is reachable
  • username: username configured to have access to the remote API
  • password: password configured for above user

 

Optionally you can add the --debug flag which will show you some basic output when a key is pressed.

 

And finally, following video shows how it works:

 

Next up ...

 

Now that this basic setup is running, I will try to extend the setup by connecting external buttons. At least the 'enter' functionality is missing today to make this any useful ;-)