python-lirc icon indicating copy to clipboard operation
python-lirc copied to clipboard

lirc.nextcode() gives [] instead of key

Open Ivan219 opened this issue 10 years ago • 14 comments

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

Ivan219 avatar May 22 '16 10:05 Ivan219

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

hargakanay avatar May 25 '16 23:05 hargakanay

Any ideas?

Ivan219 avatar Jun 06 '16 08:06 Ivan219

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 avatar Jun 06 '16 14:06 Jacq

Jacq, please, if you can, can you share your experience in the use of pylirc2?

Ivan219 avatar Jun 09 '16 18:06 Ivan219

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

Jacq avatar Jun 09 '16 21:06 Jacq

Just load your lircrc file as described in README. The problem is lirc itself, it cannot load the ~/.lircrc and or ~/.config/lircrc

pylover avatar Sep 18 '16 11:09 pylover

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.

fadhilx avatar Sep 24 '17 06:09 fadhilx

I can't test @fadhilnapis' solution at the minute, but if that does fix this issue then maybe I need to update the docs.

tompreston avatar Oct 24 '17 10:10 tompreston

Removing comments didn't work for me (see issue #10).

akkana avatar Oct 26 '17 01:10 akkana

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']

inflexionist avatar Jan 10 '18 02:01 inflexionist

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.

lemonkey avatar Jun 13 '18 02:06 lemonkey

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

matt-alencar avatar Jul 30 '20 21:07 matt-alencar

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.

tompreston avatar Oct 20 '20 17:10 tompreston

Ok I'm going to close for two reasons:

  1. @Ivan219 hasn't responded with a solution or acceptance in four years
  2. python-lirc is now obsolete, use python-evdev instead.

tompreston avatar Nov 17 '20 20:11 tompreston