CEC anyway - remote control application
#1
cec anyway

A small application to help control xbmc by CEC. Licensed under GPL2. © 2013 Magnus Kulke.

What?

CEC (Consumer Electronics Control) is an HDMI feature which is implemented in many A/V products (TVs, receivers, consoles)
these days. Manufacturers of course use their own brands for it (Sony: BRAVIA Sync, Samsung: Anynet+, Onkyo: RIHD). Among
other things CEC allows controlling several devices with a single remote.

There is an open source library called libcec which provides an interface to cec hardware. This is not only handy to limit
the amount of remotes with redundant buttons, but especially useful for devices like the raspberry pi, which do not have
ir hardware built in. Meanwhile it has been integrated well into XBMC.

Why?

Imagine the following scenario:

Code:
+------+                   +------+                    +------+
|`.    |`.                 |`.    |`.                  |`.    |`.
|  `+--+---+               |  `+--+---+                |  `+--+---+  
|   |  | o=|=================o |  | o=|==================o |  |   |  
+---+--+   |               +---+--+   |                +---+--+   |
_`. |   `. |                `. |   `. |                 `. |   `. |
_  `+------+                   +------+                    +------+

Raspberry Pi with             CEC-enabled               TV, panel or beamer
libcec installed              A/V receiver              without CEC support

Now, in theory the XBMC instance on Raspberry Pi could be controlled by the A/V receiver's remote. If you enable CEC input
in XBMC and inspect the debug logs you can see the keypress events if you press butons on the remote. However it does not
work, the buttons are ignored. This is because the spec requires a root display device (usually a TV) to be present, so it
is not a bug in libcec or XBMC, but rather an unsupported scenario. Your TV might be older or your display device unusual
(like a beamer or a computer monitor). In this case you cannot use handy CEC. Therefore i wrote "cec anyway", which ignores
the spec, captures button presses, and uses those to control XBMC.

How?

cec anyway is a tiny c++ app, which uses libcec and can be run as daemon in the background. It communicates with xbmc using
its json-rpc api. It has been tested and developed on debian linux, but it might work on other platforms as well. The
following description assumes a linux setup.

Requirements:
  • libcec2
  • xbmc 11

Installation:

Code:
make
sudo make install
chkconfig cecanyway on
/etc/init.d/cecanyway start

Usage:

By default the CEC key events left, right, down, up, select, exit, play, stop, pause, rewind, backward, ff, forward are
mapped to their XBMC equivalents.

If you want to map more key events or overwrite the default mapping you can specify that in a configuration file. To add
new mappings cecanyway can be run standalone with logging enabled. You should see the key codes when the you press buttons
on the remote.

Code:
/etc/init.d/cecanyway stop
/usr/bin/cecanyway -l

Those keycodes can be mapped in a config file (/etc/cecanyway.conf) using the following syntax (no newlines in the json parts):

Code:
22 => {"jsonrpc": "2.0", "method": "Player.Stop", "params": { "playerid": 1 }, "id": 1}
66 => {"jsonrpc": "2.0", "id": 1, "method": "Input.Back"}

The XBMC json-rpc api is described here: http://wiki.xbmc.org/index.php?title=JSON-RPC_API/v6

Available options:
  • -d (daemonize)
  • -l (log key events)
  • -f </path/to/myconf.conf> (change path to config file, default: /etc/cecanyway.conf)
  • -p <port> (change json-rpc port, default: 9090)

Download:

https://github.com/mkulke/cecanyway
Reply
#2
great - this seems to be just what i have been looking for!

however, I have problems compiling it (seel error message below). So I wondered how you compile it. I am trying to get it to work on an OpenELEC 3.2.2 system which has libcec 2.0.1 installed by default.

Thanks

########
main.cpp: In Function »int main(int, char**)«:
main.cpp:261:33: Error: expected primary-expression before »;« token
main.cpp:263:30: Error: ungültige Umwandlung von »int (*)(void*, CEC::cec_keypress&)« in »CEC::CBCecKeyPressType {aka int (*)(void*, CEC::cec_keypress)}« [-fpermissive]
make: *** [main.o] Error 1
########
Reply
#3
hi, i had similar issues on raspbmc when compiling against libcec1 (which raspian, the underlying distro provides, while libcec2 is bundled with xbmc seperately). Are you sure you compile against libcec2 headers?
Reply
#4
Thanks so much for this. Working great here in raspbmc.

Just a couple of questions.

1) Is is possible to have 2 JSON-RPC actions for a single button? The "Player.Stop" action for example has a parameter to select which player ID to use. The player ID is different for video than for audio. This means that one single stop button cannot stop both movies AND music, The same applies to pause.

2) DHCP seems to have broken on the Pi on the reboot after the cecanyway install. Static IP works fine. Any ideas why this might be?

Thanks again for this very helpful program.
Reply
#5
I have solved problem no1.

In /etc/cecanyway.conf

The following will give a pause button which will work with movies AND music. There is no need for 2 actions.

70 => {"jsonrpc": "2.0", "method": "Input.ExecuteAction", "params": { "action": "pause" }, "id": 1}

..similar ExecuteAction methods are probably better than the Player.Playpause (and suchlike) as they seem to work with more xbmc functions.
Reply

Logout Mark Read Team Forum Stats Members Help
CEC anyway - remote control application0