Using cec-client


17 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: 454
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
by mrblue1234 » Mon May 22, 2017 6:38 pm
Hello everyone!

1.) I am using cec-client with a TV and a external HDMI speaker.

2.) The setup is Raspberry Pi 3 connected to the external HDMI speaker. The external HDMI speaker is then connected to the TV.

3.) Scanning for the device on the "CEC Bus" I get something like this:

pi@raspberrypi:~ $ echo scan | cec-client -s -d 1
opening a connection to the CEC adapter...
requesting CEC bus information ...
CEC bus information
===================
device #0: TV
address: 0.0.0.0
active source: no
vendor: <Removed Vendor name>
osd string: TV
CEC version: 1.4
power status: on
language: eng


device #1: Recorder 1
address: 1.3.0.0
active source: no
vendor: Pulse Eight
osd string: CECTester
CEC version: 1.4
power status: on
language: eng


device #4: Playback 1
address: 1.0.0.0
active source: no
vendor: <Removed Vendor name>
osd string: <removed model>
CEC version: 1.4
power status: on
language: ???


device #5: Audio
address: 1.0.0.0
active source: no
vendor: <Removed Vendor name>
osd string: <removed model>
CEC version: 1.4
power status: on
language: ???
--------------------------------------

4.) Since my Raspberry Pi is not connected directly to the TV but the HDMI external speaker is in between the Pi and the TV I wanted to see if a CEC command would work from the Pi to the TV. When I issue a

echo "standby 0" | cec-client -s

the TV turns off and goes into standby.

5.) I'd like to be able to send mute and unmute commends to the TV and the external HDMI speaker separately. How can I do this with cec-client, based on the addresses and names from step #3?

For example, mute the TV and unmute the HDMI external speaker.

Thanks!

-Mike
Posts: 31
Joined: Wed Mar 29, 2017 11:42 pm
by IfThenERROR » Tue Jun 06, 2017 9:32 am
These commands should get you further.

To mute/unmute the TV:
echo "mute 0" | cec-client -s -d 1

To mute/unmute the speaker:
echo "mute 5" | cec-client -s -d 1

Please note that since you removed the vendor and osd strings, I can only guess the speaker registered as device #5. Might also be #4. Commands for muting and unmuting are the same. So if you want to make sure to e.g. always set the TV to mute and the speaker to unmute you need to first retrieve the current audio state for both devices.

echo "tx 10 71" | cec-client -s -d 1 should give you an idea here. Read more at http://www.cec-o-matic.com.
Posts: 1
Joined: Tue Jun 06, 2017 9:12 am
by mrblue1234 » Tue Jun 06, 2017 3:16 pm
Thank you so much. I appreciate the post.
Posts: 31
Joined: Wed Mar 29, 2017 11:42 pm
by Jon.maron » Wed Jul 19, 2017 7:03 pm
I am using the client and trying to get the OSD to read "Incoming Call'' which fits in the 13 char limit. I am using a RPI 3 model B with Raspbian. When I enter the command
Code: Select all
echo tx 10:64:00:49:6E:63:6F:6D:69:6E:67:20:43:61:6C:6C|cec-client -s -d 1
the console says "opening a connection to the CEC adapter...." and then just gives me a new line and nothing happens. Other commands work in this way, such as
Code: Select all
echo tx 10:36|cec-client RPI -s -d 1
to turn off the TV. But I cant seem to get it to work with the OSD command. using
Code: Select all
echo h|cec-client -s -d 1
I found the OSD command uses [osd] {addr} {string}, but using that format, I tried:
Code: Select all
echo osd 0:RPI|cec-client -s -d 1
and it didnt work. I came up with the code using cec-o-matic.com. Does anyone know what I am doing wrong?

Additionally I would like to also have the RPI switch inputs on the TV (using echo tx 1f:82:20:00|cec-client RPI -s -d 1) using a web application. Does anyone have nay ideas as to how I would use a web application to rigger the RPI into changing HDMI inputs on the TV?
Posts: 1
Joined: Wed Jul 19, 2017 6:43 pm