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

No code detected by next code()

Open tripledee opened this issue 10 years ago • 8 comments

I try to build a rain sensor using 38 kHz IR transmitter/receiver. I set up the two components and installed LIRC and python-lirc on a Raspberry Pi (running Jessie Debian), and used irrecord to build a configuration (to mimick a TV IR Remote).

The LIRC configuration is OK, as I can use irsend or irw from the shell and get the appropriate code.

Using python-lirc from a small python script, I have no result. The lirc.nextcode() returns an empty list.

import lirc
lirc.init("myprog", blocking = False)  
while (True):
    try:
            list = lirc.nextcode()
            if len(list) != 0: print "match!"
    except KeyboardInterrupt:
            lirc.deinit()
            break;

The /etc/lirc/lircrc file is:

begin
  remote = myRemote
  button = KEY_UP          # what button is pressed on the remote
  prog = myprog    # program to handle this command
  config = KEY_UP # configs are given to program as list
  repeat = 0
end

tripledee avatar Jul 05 '16 09:07 tripledee

Mee too the lirc.nextcode() returns an empty list. Why ? But irw work $ irw 000000000000000a 00 BUT_0 car_mp3 000000000000000b 00 BUT_100 car_mp3 0000000000000008 00 BUT_VOL_UP car_mp3 000000000000000a 00 BUT_0 car_mp3 000000000000000b 00 BUT_100 car_mp3

gnunicky avatar Jul 28 '16 10:07 gnunicky

Hi, I just received an email about this. What happens if you follow the example in the README exactly?

Have you tried looking into the function itself? It's only a couple of lines long: https://github.com/tompreston/python-lirc/blob/master/lirc/lirc.pyx#L218-L242

Perhaps the list isn't being built properly.

tompreston avatar Sep 05 '16 18:09 tompreston

Hello,

When I follow the README example, I get the same problems: the nextcode() function always returns []. The same button presses are correctly seen by irw.

I didn’t understand why you asked my to look inside the function in the library… Should I modify it (how?) and then compile pylirc?

regards

Denis

Le 5 sept. 2016 à 20:55, Thomas Preston [email protected] a écrit :

Hi, I just received an email about this. What happens if you follow the example in the README exactly?

Have you tried looking into the function itself? It's only a couple of lines long: https://github.com/tompreston/python-lirc/blob/master/lirc/lirc.pyx#L218-L242 https://github.com/tompreston/python-lirc/blob/master/lirc/lirc.pyx#L218-L242 Perhaps the list isn't being built properly https://github.com/tompreston/python-lirc/blob/master/lirc/lirc.pyx#L232-L242.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tompreston/python-lirc/issues/10#issuecomment-244799124, or mute the thread https://github.com/notifications/unsubscribe-auth/ANH-qn1BgnFhJu6B5BZR6NKME9V_sUdRks5qnGWcgaJpZM4JE7Cq.

tripledee avatar Sep 07 '16 09:09 tripledee

I've noticed that nextcode() always returns [] on a keypress, unless you've defined a button for it in lircrc.

michaelarnauts avatar Dec 12 '16 09:12 michaelarnauts

Have you tried removing the comments in /etc/lirc/lircrc? As in issue https://github.com/tompreston/python-lirc/issues/7#issuecomment-331690654

tompreston avatar Oct 24 '17 10:10 tompreston

I have the same problem: nextcode() function always returns []. I even wrote a script to take every key in my lircd.conf and add a stanza for it in .lircrc, so all the buttons would be defined, but it doesn't help: I still get [] every time. irw works fine and prints the name of each button when I press it, but I haven't found any way to get the same info from Python, short of running irw from subprocess and parsing the output.

akkana avatar Oct 24 '17 19:10 akkana

Hi @tripledee and @akkana. It seems to work fine for me. try moving the lirc.deinit() command into the try: rather than the except:

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 press durations:

['power, on']
['power, on']
[]
[]
[]
[]
['power, on']
[]
[]
['power, on']
[]
['power, on']

inflexionist avatar Jan 10 '18 02:01 inflexionist

Since there's been no update from the issue creator I'm going to close this.

See also https://github.com/tompreston/python-lirc/issues/28#issuecomment-712454662

tompreston avatar Nov 17 '20 20:11 tompreston