lirc.nextcode() gives [] instead of key
Hello, I try to use lirc-1.2.1 on python 3.4 on raspberry pi.
I wrote this code:
import lirc while 1: sockid = lirc.init("myprogram2", blocking = False) codeIR = lirc.nextcode() print (codeIR)//must give one
I have two erros: blocking is true alltime (python 2 hasn't this bug) and print (codeIR) gives [] when i press button on tv remote, not config (in all pythons).
lircrc: begin button = KEY_1 # what button is pressed on the remote prog = myprogram2 # program to handle this command config = one# configs are given to program as list end Please, help
I have the same problem with lirc.nextcode() - it doesn't return anything. This happens with python 2 and 3.
$cat /etc/lirc/lircrc
begin
button = KEY_1 # what button is pressed on the remote
prog = myprogram # program to handle this command
config = one,two # configs are given to program as list
end
$cat lirctest.py
import lirc
sockid = lirc.init("myprogram")
lirc.nextcode()
lirc.deinit()
The script waits until I press a button, and then exits without returning anything.
lirc is correctly configured as far as I can see. Running irw gives sensible-looking results:
$ irw
0000000008e76897 00 KEY_1 /home/pi/lircd.conf
0000000008e76897 01 KEY_1 /home/pi/lircd.conf
0000000008e7a857 00 KEY_2 /home/pi/lircd.conf
0000000008e7a857 01 KEY_2 /home/pi/lircd.conf
0000000008e728d7 00 KEY_3 /home/pi/lircd.conf
0000000008e7708f 00 KEY_4 /home/pi/lircd.conf
0000000008e7708f 01 KEY_4 /home/pi/lircd.conf
0000000008e7b04f 00 KEY_5 /home/pi/lircd.conf
0000000008e7b04f 01 KEY_5 /home/pi/lircd.conf
0000000008e730cf 00 KEY_6 /home/pi/lircd.conf
Any ideas?
I've moved to pylirc2 as it is used already in mopidy-ircontrol and it's working for me I've this issue with python-lirc and not with pylirc2 with the same lirc.conf
Jacq, please, if you can, can you share your experience in the use of pylirc2?
Not much indeed, I was going to start an app for the modify server but then I found the existing plugin. You can have a look at the working code https://github.com/spjoe/mopidy-ircontrol/blob/master/mopidy_IRControl/actor.py
Just load your lircrc file as described in README. The problem is lirc itself, it cannot load the ~/.lircrc and or ~/.config/lircrc
i have same problem, but i fixed it by removing extra character on .lircrc file such as comment #. i think lircrc detect # as value...
try to remove comment(#) on .lircrc file:
from
begin
button = KEY_1 # what button is pressed on the remote
prog = myprogram # program to handle this command
config = one # configs are given to program as list
end
to
begin
button = KEY_1
prog = myprogram
config = one
end
hope this will help you. Please add good reaction to this comment if it work, and if not, let us know.
I can't test @fadhilnapis' solution at the minute, but if that does fix this issue then maybe I need to update the docs.
Removing comments didn't work for me (see issue #10).
It seems to work fine for me. I believe you are missing the command:
lirc.deinit()
If you consider the output of irw, there is a count associated with long presses of buttons which increments. It seems that python-lirc interprets the first button press and offers the "config" arguments from your .lircrc file(as expected) and long presses are followed by multiple lines of empty lists []. if you do not deinitialize the socket every time you record a command, it will think that all subsequent presses are part of the original press. I used the following python script and it works great...
import lirc
while True:
sockid = lirc.init("myprogram")
code = lirc.nextcode()
print (code)
lirc.deinit()
producing the following output when I use the power button with different durations:
['power, on']
['power, on']
[]
[]
[]
[]
['power, on']
[]
[]
['power, on']
[]
['power, on']
You definitely need to use the correct key names that are in your lirc.conf file that was originally generated. I had a typo in my python script that was returning [] for the keypresses.
I just add "repeat = 1" parameter on each key on my configuration file aka: "~/.lircrc" to get rid of this behavior.
And take a time to read the official documentation: https://www.lirc.org/html/configure.html
There is actually a lot of possible configuration behavior for each key. :grin:
begin
button = KEY_1
prog = myprogram
repeat = 1
config = one,two
end
Have you considered configuring in-kernel IR events and using python-evdev instead? This might better solve your problem. I'm thinking about archiving this repo. More info in this comment:
- https://github.com/tompreston/python-lirc/issues/28#issuecomment-712454662
Let me know how you get on, I'm trying to think of valid use cases for LIRC and python-lirc.
Ok I'm going to close for two reasons:
- @Ivan219 hasn't responded with a solution or acceptance in four years
- python-lirc is now obsolete, use python-evdev instead.