Linux Lirc (usb_irtoy driver) device stops responding

USB infrared remote control receiver/transmitter. Get one for $20, including worldwide shipping.

Linux Lirc (usb_irtoy driver) device stops responding

Postby Joker » Wed Apr 02, 2014 9:51 pm

The device stops responding after a certain amount of successful operations.
When reaching that state only a replug will fix it. Restarting the lirc daemon is not enough.

I first suspected some usb suspend but i noticed it was set off for that
device. To be sure i booted with "usbcore.autosuspend=-1" kernel parameters.
Also the amount of irsend requests seem more related to the problem than
idle time.

Flashing firmware (v22), learning from a remote and similar operations worked
just fine. After 6-15 times calling irsend it locks up and lircd dies off.

I suspeced some bad code in lircd at first, but the fact that a device replug
is required, tells me that it's not in the daemon (it's just handling the event
not gracefully enough).

lirc test client (executed with 1-2s pauses):
~ # irsend SEND_ONCE PHILIPS_26PFL5604H Power
~ # irsend SEND_ONCE PHILIPS_26PFL5604H Power
~ # irsend SEND_ONCE PHILIPS_26PFL5604H Power
~ # irsend SEND_ONCE PHILIPS_26PFL5604H Power
~ # irsend SEND_ONCE PHILIPS_26PFL5604H Power
~ # irsend SEND_ONCE PHILIPS_26PFL5604H Power
~ # irsend SEND_ONCE PHILIPS_26PFL5604H Power
(exit code 1 here)

lircd server daemon output:
---------------------------------
# /usr/sbin/lircd -n -P /var/run/lirc/lircd.pid
lircd-0.9.0[9471]: lircd(usb_irtoy) ready, using /var/run/lirc/lircd
lircd-0.9.0[9471]: accepted new client on /var/run/lirc/lircd
lircd-0.9.0[9471]: removed client
lircd-0.9.0[9471]: accepted new client on /var/run/lirc/lircd
lircd-0.9.0[9471]: removed client
lircd-0.9.0[9471]: accepted new client on /var/run/lirc/lircd
lircd-0.9.0[9471]: removed client
lircd-0.9.0[9471]: accepted new client on /var/run/lirc/lircd
lircd-0.9.0[9471]: removed client
lircd-0.9.0[9471]: accepted new client on /var/run/lirc/lircd
lircd-0.9.0[9471]: removed client
lircd-0.9.0[9471]: accepted new client on /var/run/lirc/lircd
lircd-0.9.0[9471]: removed client
lircd-0.9.0[9471]: accepted new client on /var/run/lirc/lircd
lircd-0.9.0[9471]: irtoy_getversion: couldn't read version
lircd-0.9.0[9471]: please make sure you are using firmware v20 or higher
lircd-0.9.0[9471]: usb_irtoy: No USB Irtoy device found at /dev/ttyACM0
lircd-0.9.0[9471]: Failed to initialize hardware
lircd-0.9.0[9471]: select() failed
lircd-0.9.0[9471]: Bad file descriptor
Segmentation fault

GDB Output of lircd:
------------------------
Program received signal SIGTERM, Terminated.
0x00007ffff7a69235 in raise () from /lib64/libc.so.6
(gdb) bt
#0 0x00007ffff7a69235 in raise () from /lib64/libc.so.6
#1 0x0000000000406eed in waitfordata (maxusec=maxusec@entry=0) at lircd.c:1938
#2 0x000000000040761f in loop () at lircd.c:2022
#3 0x0000000000402839 in main (argc=<optimized out>, argv=0x7fffffffdd08) at lircd.c:2299
Joker
Newbie
Newbie
 
Posts: 7
Joined: Wed Apr 02, 2014 9:24 pm

Re: Linux Lirc (usb_irtoy driver) device stops responding

Postby Joker » Thu Apr 03, 2014 4:58 am

Virtually replugging the USB device using "ioctl(fd, USBDEVFS_RESET, 0)" on the device also works.

While this is easier than hardware based re-plugging, it's not suitable for automated use, because
lircd dies and requires restarting too. This would result in nasty hacks unless it's called from within
the usb_irtoy driver itself.
Joker
Newbie
Newbie
 
Posts: 7
Joined: Wed Apr 02, 2014 9:24 pm

Re: Linux Lirc (usb_irtoy driver) device stops responding

Postby Joker » Thu Apr 03, 2014 3:59 pm

I've left it idle one whole day and it was still running until i accessed it 10 times. So assume i can rule any suspend stuff out and it's really an issue that only gets triggered by using it.
Joker
Newbie
Newbie
 
Posts: 7
Joined: Wed Apr 02, 2014 9:24 pm

Re: Linux Lirc (usb_irtoy driver) device stops responding

Postby Joker » Thu Apr 03, 2014 7:18 pm

While the error remains the same with firmware 21 22 and 23, at least with
firmware 23 i notice a werid state when it locks

~# lsusb -v -d 04d8:fd08
[...]
Device Status: 0xffff
Self Powered
Remote Wakeup Enabled
Test Mode
Debug Mode

While its working it's always this:
Device Status: 0x0000
(Bus Powered)

I notice others had this issue too but i think i've only noticed the Status change.
It locks with all firmwares i've tried (21,22,23) but this could be the case only with 23.
recently.
Joker
Newbie
Newbie
 
Posts: 7
Joined: Wed Apr 02, 2014 9:24 pm

Re: Linux Lirc (usb_irtoy driver) device stops responding

Postby ariel » Tue Apr 29, 2014 8:43 am

Hi Joker and everyone,

I just want to report that I am having the exact same problem.

I purchased a stack of the usb irtoy v2 for a project involving control of airconditioner units and am being stumped by all of them (at least 5 that i have tried) displaying the same behaviour. I am using lirc v0.9.1 in linux (raspbian) and have updated the usb irtoy firmware to v23.

Upon physical connection of the usb irtoy, lirc's "irsend" command will work a few times, and then on a subsequent attempt the lircd daemon will crash. Any following use of irsend produce the error:
irsend: could not connect to socket
irsend: Connection refused

I don't have a huge amount of programming experience, but i can say that I am receiving the same error messages in the lirc log:
lircd: accepted new client on /var/run/lirc/lircd
lircd: irtoy_getversion: couldn't read version
lircd: please make sure you are using firmware v20 or higher
lircd: usb_irtoy: No USB Irtoy device found at /dev/ttyACM0
lircd: WARNING: Failed to initialize hardware
lircd: select() failed
lircd: Bad file descriptor

The last few lines of "lsusb -v -d 04d8:fd08" show:
[...]
Device Status: 0xd458
(Bus Powered)
Debug Mode

...but if i repeat this command the "Device Status" keeps changing to various values ending in 458...I have seen 1458, 3458, 5458, 6458, 7458, 8458, 9458, a458, b458, d458, e458, all within a few seconds of eachother (not in order). I'm not sure if that is of any significance

... when the devices is working normally the same lsusb command gives:
[...]
Device Status: 0x0000
(Bus Powered)

I physically unplug and replug the usb irtoy and manually restart the lircd daemon, and it all works again for 1, 2 or 5 uses. But if i want this to be a stable remote system for controlling the airconditioners, having to physically unplug/replug the irtoy doesn't really cut it.

I would appreciate any assistance anyone could provide! :)
ariel
Newbie
Newbie
 
Posts: 2
Joined: Tue Apr 29, 2014 8:06 am

Re: Linux Lirc (usb_irtoy driver) device stops responding

Postby teknetik » Mon May 12, 2014 1:56 pm

+1 for this. Exact same issue. Not really qualified to provided the details provided above but happy to provide any debug required if someone wishes to investigate.
teknetik
Newbie
Newbie
 
Posts: 7
Joined: Tue Feb 04, 2014 7:20 am

Re: Linux Lirc (usb_irtoy driver) device stops responding

Postby teknetik » Mon May 12, 2014 3:36 pm

Following the advice above I find very similar findings:

Device Status: 0xfa08
Device Status: 0x9a08
Device Status: 0x7a08
Device Status: 0x1a08
Device Status: 0xda08
Device Status: 0xda08
Device Status: 0x8a08
Device Status: 0xfa08
Device Status: 0xea08
Device Status: 0xca08
Device Status: 0x0a08

Working:
Device Status: 0x0000


I would be quite happy to purchase new hardware if thats whys required (can't say the same for the guy who bought a stash!)

This is a really neat little product and I have it working doing some very neat stuff but the instability makes it unfit for purpose really :(

I dont mean to complain, really great job and I cant find anything even close out there. G/J
teknetik
Newbie
Newbie
 
Posts: 7
Joined: Tue Feb 04, 2014 7:20 am

Re: Linux Lirc (usb_irtoy driver) device stops responding

Postby AnalysIR » Fri Jun 20, 2014 4:33 pm

Hi Guys

When implementing support for IR Toy on windows for AnalysIR, we came across similar issues.

We found that these issues were a result of not responding fast enough when sending IR.

Because Windows & Linux are not real time OS's you can hit a problem whereby your code is scheduled out(suspended) by the OS (Linux or Windows).

Our solution was 2 part:
1. make sure the sending code on the PC is as fast/efficient as possible
2. Increase the priority of your code or script or process. (this was the most important issue). (===>nice for Linux?)

Hope that helps!
AnalysIR - Infrared decoder & analyzer, now with support for USB IR Toy
https://www.AnalysIR.com/blog/
User avatar
AnalysIR
Jr. Member
Jr. Member
 
Posts: 67
Joined: Tue Nov 05, 2013 4:47 pm
Location: Dublin, Ireland

Re: Linux Lirc (usb_irtoy driver) device stops responding

Postby ariel » Fri Jul 04, 2014 4:05 am

HI AnalysIR,

Thanks for your insight and your suggestions.

I altered the niceness of the lirc daemon to -20 (ie max prioirity) and also tried running the irsend command with the same -20 niceness and this had no effect :'(

I am still getting the same errors, the device is still falling into debug mode, and the lirc daemon is still crashing.

Has anyone else tried this? Or any other solution?
ariel
Newbie
Newbie
 
Posts: 2
Joined: Tue Apr 29, 2014 8:06 am

Re: Linux Lirc (usb_irtoy driver) device stops responding

Postby Zillode » Sun Jul 06, 2014 5:11 am

I fixed it by resetting the device as mentioned by Joker and MattF (http://www.raspberrypi.org/forums/viewt ... 3&p=388543). This also works for devices that are attached to a powered usb hub.


reset-usb.c:
Code: Select all
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/usbdevice_fs.h>
void main(int argc, char **argv)
{
const char *filename;
int fd;
if (argc != 2) return;
filename = argv[1];
fd = open(filename, O_WRONLY);
ioctl(fd, USBDEVFS_RESET, 0);
close(fd);
return;
}


make reset-usb
./reset-usb /dev/bus/usb/001/003

The usage is usbreset /dev/bus/usb/XXX/YYY where XXX is the bus number (nearly always 001 on the Pi) and YYY is the device number (get both of these from lsusb)."


I wrote a Ruby script that searches for the IRToy device on my raspberry pi and resets it:
Code: Select all
#!/usr/bin/env ruby
usbs = `find /dev/bus/`
usbs.each_line { |usb|
        next unless usb.include?("\/001\/") # Try to disable this line if it does not find it
        ls = `lsusb -D #{usb}`
        next unless ls.include?("04d8:fd08")
        `./reset-usb #{usb}`
}
Zillode
Newbie
Newbie
 
Posts: 7
Joined: Fri Jan 07, 2011 6:47 pm

Re: Linux Lirc (usb_irtoy driver) device stops responding

Postby ISavant01 » Sun Aug 10, 2014 1:57 pm

is this reset a "permanent" fix?

i have been running with a raspberry pi and LIRC and the USB_IRToy for a few years now. it's been rock solid.

then i updated the firmware, preparatory to using the new, 4-USB B+ model, and things went south from there.

like others note here, LIRC starts up - commands run OK for 3 to 4 commands through irsend, then pouf! lircd crashes.

i even went through the process of completely rebuilding and relinking the binaries against the latest system libraries. no help.

so: is this reset a permanent thing? or just a convenient way of not having to un-plug and re-plug?
ISavant01
Newbie
Newbie
 
Posts: 3
Joined: Sun Aug 10, 2014 1:51 pm

Re: Linux Lirc (usb_irtoy driver) device stops responding

Postby Zillode » Sun Aug 10, 2014 2:46 pm

This 'patch' fixed a lot of issues for me but is not 100% reliable.
However, in combination with the dwc_otg.speed=1 flag (viewtopic.php?f=29&t=6655#p58854) I don't have issues with my two IRToys and raspberry pi.
Zillode
Newbie
Newbie
 
Posts: 7
Joined: Fri Jan 07, 2011 6:47 pm

Re: Linux Lirc (usb_irtoy driver) device stops responding

Postby AnalysIR » Sun Aug 17, 2014 3:29 pm

Try increasing the priority of the processes you are using for the IRToy (see 'nice' command in Linux).

...may help
AnalysIR - Infrared decoder & analyzer, now with support for USB IR Toy
https://www.AnalysIR.com/blog/
User avatar
AnalysIR
Jr. Member
Jr. Member
 
Posts: 67
Joined: Tue Nov 05, 2013 4:47 pm
Location: Dublin, Ireland

Re: Linux Lirc (usb_irtoy driver) device stops responding

Postby Forage » Sun Oct 19, 2014 11:10 am

I'm stuck with the same issue as well. After 3-6 send attempts lircd just crashes.

AnalysIR wrote:We found that these issues were a result of not responding fast enough when sending IR.

What is not responding fast enough to what?
AnalysIR wrote:Our solution was 2 part:
1. make sure the sending code on the PC is as fast/efficient as possible
2. Increase the priority of your code or script or process. (this was the most important issue). (===>nice for Linux?)

That's not a solution, but a work-around ;-P

Increasing the priority of lircd, as well as irsend doesn't do the trick.
Forage
Newbie
Newbie
 
Posts: 31
Joined: Sat Jul 12, 2014 7:01 am

Re: Linux Lirc (usb_irtoy driver) device stops responding

Postby Barf » Mon Oct 20, 2014 4:00 pm

As some of you may know, the IrToy driver by Peter Kooiman is now officially in the GIT Lirc, although no official release has been done since. (I even managed to get an improvement into it myself.) See http://sourceforge.net/p/lirc/tickets/20/

I tried the GIT Lirc (master branch) and the included IrToy driver for sending. Slammed 100 irsend commands (without delay, with full debugging turned on) to it -- no problems. Not even being root was necessary. (Full debugging (--loglevel=10) is not really resource friendly either...)

So much for fiddling with priorities :-).

Greets,

Bengt
Barf
Jr. Member
Jr. Member
 
Posts: 64
Joined: Mon Jul 07, 2014 3:12 pm

Next

Return to USB Infrared Toy