Closed neilmunday closed 8 years ago
I haven't touched this in a while. I'll look into adding support for libcec 3.x if I have some free time, but I would also welcome a pull request which adds 3.x support.
No worries. I've since found that libcec now comes with its own Python bindings so I'm using these for now: https://github.com/Pulse-Eight/libcec/blob/master/src/libcec/libcec.i
Great! Do they have a link to documentation? If they do, I'll add a note to my readme recommending their python API for v3 and above
Their README file (https://github.com/Pulse-Eight/libcec/blob/master/README.md) explains how to install the library and mentions the Python API and its example:https://github.com/Pulse-Eight/libcec/blob/master/src/pyCecClient/pyCecClient.py
I found that their example Python app was enough to get my Python scripts working.
Hope this helps.
Hi! Bringing this back up. Try as I might, I cannot get python-cec to work with libcec 3.0.1 on Rasbian Jessie. Is there anyway you can point to what I need to do? I'm having the same CEC_CLIENT_VERSION error as above.
As far as I know, the API for libcec 3 is significantly different from previous versions. Therefore, a lot of work would have to be done to bring python-cec up to date. As I said in my comments above libcec 3 does come with its own Python bindings so you could use these.
If you build libcec from source you can build the Python bindings, e.g.
git clone https://github.com/Pulse-Eight/libcec
cd libcec
mkdir build
cd build
cmake -DRPI_INCLUDE_DIR=/opt/vc/include -DRPI_LIB_DIR=/opt/vc/lib -DCMAKE_INSTALL_PREFIX=/opt/libcec/current ../
make
sudo make install
Note: watch the output from cmake to make sure it's found all the libraries required to compile the Python bindings.
Once installed, you'll need to set your PYTHONPATH environment variable to include the Python bindings which in my case is: /opt/libcec/current/lib/python2.7/dist-packages and you also need to set your LD_LIBRARY_PATH to include the libcec shared objects, e.g. in my case: /opt/libcec/current/lib
Hope this helps,
Neil.
Thanks for the quick reply. Yeah, I've heard about the python binds in LIBCEC 3.0.1. I haven't been able to get them to work. I'm new to Linux and Python so I'm still not entirely confident setting environment variables so I'm sure I'm missing something. When I call "import CEC" it can't find any module. Could you elaborate on your last paragraph a bit more?
Script source here -> https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=117019
No problem. Following on from above, assuming you have installed libcec to /opt/libcec/current proceed as follows:
export LD_LIBRARY_PATH=/opt/libcec/current:$LD_LIBRARY_PATH
export PYTHONPATH=/opt/libcec/current/lib/python2.7/dist-packages:$PYTHONPATH
The first export sets LD_LIBRARY_PATH which is used by the runtime environment when looking for shared libraries to load. In this case we are including the directory where the libcec shared libraries are installed.
The second export tells the Python interpreter where to look for additional Python modules. In this instance we are telling it to include the libcec Python module.
Now in your Python scripts make sure you import the module using:
import cec
Note: you must launch your Python script from the same shell that you issued the export commands above.
Hope this makes sense,
Neil.
Also, having looked at https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=117019 assuming that script completed ok, then you should just be able to import the cec module in Python without setting any environment variables as the install script installs to /usr which means that the libcec shared libraries and Python module will be included in the search paths.
Note: Python module names etc. are case sensitive!
Here's the diff that fixed the libcec 3.0 CEC_CLIENT_VERSION compilation issue for me:
diff --git a/cec.cpp b/cec.cpp
index 5b5df45..a025a75 100644
--- a/cec.cpp
+++ b/cec.cpp
@@ -636,7 +636,9 @@ PyMODINIT_FUNC initcec(void) {
snprintf(CEC_config->strDeviceName, 13, "python-cec");
// CEC_CLIENT_VERSION_CURRENT was introduced in 2.0.4
// just use 2.1.0 because the conditional is simpler
-#if CEC_LIB_VERSION_MAJOR >= 2 && CEC_LIB_VERSION_MINOR >= 1
+#if CEC_LIB_VERSION_MAJOR >= 3
+ CEC_config->clientVersion = LIBCEC_VERSION_CURRENT;
+#elif CEC_LIB_VERSION_MAJOR >= 2 && CEC_LIB_VERSION_MINOR >= 1
CEC_config->clientVersion = CEC_CLIENT_VERSION_CURRENT;
#else
// fall back to 1.6.0 since it's the lowest common denominator shipped with
Thanks! I'll give that a try and merge it in.
Thank you for the package. It works very well for me.
On Thu, Mar 24, 2016, 8:07 PM Austin notifications@github.com wrote:
Thanks! I'll give that a try and merge it in.
— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/trainman419/python-cec/issues/11#issuecomment-201118767
@trainman419, and developments on the test and getting this merged? Love this package, too. Works well!
Build confirmed with both libcec2 on Ubuntu Trust and libcec3 on Ubuntu Xenial, and merged.
Released to PyPi/pip as version 0.2.4.
I didn't upload version 0.2.4 to pypi correctly and managed to burn the version number.
Properly released as version 0.2.5.
Sweet, man! Thanks for keeping this thing alive. Makes CEC easy peasy. Not sure if you're into the home automation game, but this would fit great into Home Assistant. https://home-assistant.io/
Wow, home-assitant has come a long way. I wrote the nmap-based device tracker for home-assitant a while back: https://github.com/balloob/home-assistant/pull/14
Hi,
I've tried to build python-cec against libcec 3.0.1-1 but the compilation fails as the CEC_CLIENTVERSION* constants are no longer defined in libcec's cectypes.h header file.
Are there any plans to support this newer version of libcec?
Cheers,
Neil.