Using cec-client


13 posts
by GrandAdmiral » Wed Aug 21, 2013 9:26 pm
I have the cec-client and libcec working on my Raspberry Pi. I would like to use it for more than just turning on and off the television, I would like to be able to query the other devices for their system information. Then maybe control them through the RPi. :)

Anyway, I'm wondering if there are some good sources of information on the cec-commands. I know I can send the following:
Code: Select all
echo "on 0" | cec-client -s
to turn on the television and
Code: Select all
echo "standby 0" | cec-client -s
to turn it off. I even found
Code: Select all
echo 'lang 0' | cec-client -t p -p 1 -d 1 -s | tail -n1 | grep 'language' | awk '{print $3}'
which will tell me the television language is 'eng'. All of the commands were found in the libcec/support/cec-test-device.sh script. Is there a complete list of built-in libcec commands somewhere?

Alternatively I did look at the http://www.cec-o-matic.com/ tool. What type of source is the Raspberry Pi or does it matter? Is there a way to query what devices are connected to the television from the RPi? For example, if I connect and disconnect a Blu-ray player, is there a way to tell that has happened?
Posts: 21
Joined: Thu Apr 18, 2013 2:34 pm
by blamarpa » Thu Aug 22, 2013 7:12 pm
Posts: 447
Joined: Thu May 23, 2013 4:02 pm
Location: España
by GrandAdmiral » Fri Aug 23, 2013 8:43 pm
Thanks, that's been added to the reading list. Another person told me about this command:

echo h | cec-client -s -d 1


That will tell you about the shortcuts the cec-client knows. For example, "echo scan | cec-client -s -d 1" will tell you what devices are connected to the television. The "-d 1" option is nice for making the returned information more readable.
Posts: 21
Joined: Thu Apr 18, 2013 2:34 pm
by GrandAdmiral » Tue Aug 27, 2013 1:54 pm
I've been reading through the spec (almost halfway through), but I'm a bit puzzled by something. How do you tell from cec-client if a feature is supported? The spec says:

This section describes the message transfer and additional details for a number of common features enabled
by CEC. Note that where a feature is supported, all messages within that feature should be implemented.


The implication, to me, is that not every feature is supported. If the feature is not supported, the device should respond with "Feature Abort". Right now I'm experimenting with <Set OSD String> by using the following command:

Code: Select all
echo "tx 10 64 00 41 20 42 20 43" | cec-client -s -d 1


This should put the text "A B C" on the screen, but it does not. The tail of the cec-client output looks like this:

DEBUG: [ 1404] >> TV (0) -> Recorder 1 (1): give osd name (46)
DEBUG: [ 1405] << Recorder 1 (1) -> TV (0): OSD name 'CECTester'
TRAFFIC: [ 1407] << 10:47:43:45:43:54:65:73:74:65:72
TRAFFIC: [ 1772] >> 01:90:00
DEBUG: [ 1775] >> TV (0) -> Recorder 1 (1): report power status (90)
DEBUG: [ 1776] TV (0): power status changed from 'unknown' to 'on'
DEBUG: [ 1777] expected response received (90: report power status)
TRAFFIC: [ 1781] << 10:64:00:41:20:42:20:43
DEBUG: [ 1995] unregistering all CEC clients
NOTICE: [ 1998] unregistering client: libCEC version = 2.1.1, client version = 2.1.1, firmware version = 1, logical address(es) = Recorder 1 (1) , physical address: 1.0.0.0, host: armv6l-unknown-linux-gnueabihf, features: 'P8 USB' 'P8 USB detect' 'RPi', compiled on: Wed Apr 24 21:12:36 UTC 2013 by me@raspberrypi on Linux 3.2.27+ (armv6l)
DEBUG: [ 2000] Recorder 1 (1): power status changed from 'on' to 'unknown'
DEBUG: [ 2001] Recorder 1 (1): CEC version unknown
DEBUG: [ 2003] Recorder 1 (1): osd name set to 'Recorder 1'
DEBUG: [ 2004] Recorder 1 (1): device status changed into 'unknown'
DEBUG: [ 2005] unregistering all CEC clients
DEBUG: [ 2008] UnregisterLogicalAddress - releasing previous logical address
DEBUG: [ 2011] logical address changed to Broadcast (f)

I don't see any evidence of "Feature Abort". What am I missing?
Posts: 21
Joined: Thu Apr 18, 2013 2:34 pm
by geekuskhan » Wed Sep 04, 2013 4:49 pm
Is there a command to change the label that displays in the input menu on the TV? I would like mine to say HTPC or Movies or something easier for other people to understand what it's for.
Posts: 8
Joined: Tue Jul 03, 2012 3:58 am
by GrandAdmiral » Wed Sep 04, 2013 5:42 pm
Is there a command to change the label that displays in the input menu on the TV?


Sure, if you go to the CEC-O-MATIC website you can select your source (mine is Recording 1) and the destination (the TV). Then go to the "Supporting Features" tab and select the "Device OSD Name Transfer" item. "Set OSD Name" is what you want. For example, to change my Raspberry Pi from CECTester to RPi, I used the following command:

Code: Select all
echo "tx 10 47 52 50 69" | cec-client -s -d 1

The first byte contains the source (upper nibble) and destination (lower nibble) addresses. The next byte is the command. The following bytes contain the string.
Posts: 21
Joined: Thu Apr 18, 2013 2:34 pm
by geekuskhan » Wed Sep 04, 2013 6:34 pm
Thanks, I will give this a shot.
Posts: 8
Joined: Tue Jul 03, 2012 3:58 am
by geekuskhan » Wed Sep 04, 2013 9:03 pm
Thanks to your helo I got that working. Any idea how to make it stick after a reboot?
Posts: 8
Joined: Tue Jul 03, 2012 3:58 am
by GrandAdmiral » Wed Sep 04, 2013 9:17 pm
Any idea how to make it stick after a reboot?


TV or Raspberry Pi? You should be able to handle the Raspberry Pi reboot by adding the command to your .bashrc (or similar) file. For the TV you might have to write a program/script to monitor the TV's power status and resend the command if it goes through an OFF/ON cycle.
Posts: 21
Joined: Thu Apr 18, 2013 2:34 pm
by geekuskhan » Wed Sep 04, 2013 9:23 pm
Im not sure I know the difference. But I would like the Pi to show up as the label that I give it even if I unplug it and move it to another TV. I guess I can just run the command at boot but it would be so much nicer if I could just change wherever it is labeled "raspberry" in the first place.

It's just a little nicety to make my little pc project perfect so I don't know if it is worth changing it every time on reboot.
Posts: 8
Joined: Tue Jul 03, 2012 3:58 am
by GrandAdmiral » Wed Sep 04, 2013 9:27 pm
Well, I suppose you could search for "CECTester" in the cec-client source, change it to what you want, and rebuild it. That might be the simplest solution, although I don't remember what I all did to build the cec-client. :)
Posts: 21
Joined: Thu Apr 18, 2013 2:34 pm
by geekuskhan » Wed Sep 04, 2013 9:31 pm
I don't think that would help since it showed on my TV as "raspberry" before I installed the cec-client. Might be in the kernel somewhere.
Posts: 8
Joined: Tue Jul 03, 2012 3:58 am
by cyanarnofsky » Thu Jan 16, 2014 6:08 pm
Sorry for the below rambling but maybe it will help someone else. I do have a standing question. Is there a single command to turn on tv and switch input to active input? I tried the one below I found on Google. It turns on my tv but does not switch connection. The echo "as" however when sent will switch it.

Source: Best Article I could find on setting up CEC for the Pi

http://nyxi.eu/blog/2013/04/15/raspbian-libcec/


EDIT:
Added both commands in order to /etc/rc.local and turned CEC-HDMI=ON in my TV menu (most tvs you have to enable CEC I found out from stock). Pi Boots and kicks everything over great :). Possible way to turn off the pi when the TV powers down? <- Actually scratch that, if a Pi is "Powered Down" it would need to be power cycled through hardware to turn back on. Could be put in a standby but problematic I have read. Seems easier to leave active and power tv off.

Answered:
I was curious to the best way to send the on and switch input commands at boot. Boot Pi which would kick tv on and over to correct input if CEC enabled.

On Command: echo "on 0" | cec-client -s

Switch Input: echo "as" | cec-client -s

I tried this command: echo 'on 0'|cec-client -s -d 1
-Which said this would turn on tv and switch input with one command, tv turns on but input never switches. Other "as" command does work for switching though.

Is there a "best" method to running this soon as possible in boot? Thanks!
Posts: 70
Joined: Tue Jul 31, 2012 11:33 pm