Dangerous Prototypes

Dangerous Prototypes => USB Infrared Toy => Topic started by: Joker on April 03, 2014, 04:51:47 am

Title: Linux Lirc (usb_irtoy driver) device stops responding
Post by: Joker on April 03, 2014, 04:51:47 am
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
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: Joker on April 03, 2014, 11:58:47 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.
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: Joker on April 03, 2014, 10:59:35 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.
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: Joker on April 04, 2014, 02:18:22 am
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.
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: ariel on April 29, 2014, 03:43:30 pm
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! :)
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: teknetik on May 12, 2014, 08:56:23 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.
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: teknetik on May 12, 2014, 10:36:11 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
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: AnalysIR on June 20, 2014, 11:33:11 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!
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: ariel on July 04, 2014, 11:05:19 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?
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: Zillode on July 06, 2014, 12:11:40 pm
I fixed it by resetting the device as mentioned by Joker and MattF (http://www.raspberrypi.org/forums/viewt ... 3&p=388543 (http://www.raspberrypi.org/forums/viewtopic.php?t=49903&p=388543)). This also works for devices that are attached to a powered usb hub.


reset-usb.c:
Code: [Select]
#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

Quote
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]
#!/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}`
}
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: ISavant01 on August 10, 2014, 08:57:55 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?
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: Zillode on August 10, 2014, 09:46:47 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 (http://dangerousprototypes.com/forum/viewtopic.php?f=29&t=6655#p58854)) I don't have issues with my two IRToys and raspberry pi.
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: AnalysIR on August 17, 2014, 10:29:32 pm
Try increasing the priority of the processes you are using for the IRToy (see 'nice' command in Linux).

...may help
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: Forage on October 19, 2014, 06:10:53 pm
I'm stuck with the same issue as well. After 3-6 send attempts lircd just crashes.

[quote author="AnalysIR"]We found that these issues were a result of not responding fast enough when sending IR.[/quote]
What is not responding fast enough to what?
[quote author="AnalysIR"]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?)[/quote]
That's not a solution, but a work-around ;-P

Increasing the priority of lircd, as well as irsend doesn't do the trick.
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: Barf on October 20, 2014, 11:00:33 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/ (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
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: Forage on October 23, 2014, 08:10:43 pm
[quote author="Barf"]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...)[/quote]
Thanks for the heads-up and good to hear it's working for you.

I tried a build from the latest sources, but despite using the same conf file as before it doesn't work. I don't get errors, the toy lights up as normal when trying to send a command, but nothing happens with the device that I'm trying to control.
It always worked in the past with the same device and conf file, be it only for 5-6 times of course.

Did you did anything special when building the latest sources or are doing so when running/using lirc in order to make it work with the toy?
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: Barf on October 25, 2014, 09:03:38 am
It is really hard to remotely diagnose this. There are a number of things that can go wrong.

The command line I used was

./lircd  --driver  irtoy --nodaemon  --listen  --device=/dev/ttyACM0 --loglevel=10

First of all, start with --loglevel=10 and either --nodaemon or a logfile, and look for errors. If that does not give a clue, I would use IrScrutinizer (on a PC, Linux or Windows) to capture known good signals for your device. Capture all (or some) the commands, and try to  transmit them from the Scrutinizer, all using the 'toy. If that works, generate a lirc configuration file agaiin with the Scrutinizer, and try it with your Lirc setup. If that still does not work, file a bug report at http://sourceforge.net/p/lirc/tickets/ (http://sourceforge.net/p/lirc/tickets/) giving as many details as possible.
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: Forage on November 22, 2014, 05:57:17 pm
[quote author="Barf"]It is really hard to remotely diagnose this. There are a number of things that can go wrong.

The command line I used was

./lircd  --driver  irtoy --nodaemon  --listen  --device=/dev/ttyACM0 --loglevel=10[/quote]
Playing with the latest lirc sources brings me back to the initial problem. Only a few attempts work, after that the toy is gone.

The lirc debug output gives me the following on the first failing attempt:
Code: [Select]
lircd: Debug registering local client
lircd: Notice accepted new client on /run/lirc/lircd
lircd: Debug irtoy_getversion: Got version V222
lircd: Debug irtoy_reset: Got protocol S01
lircd: Debug Version hw 2, sw 22, protocol 1
lircd: Info irtoy_found on /dev/ttyACM1
lircd: Debug received command: "SEND_ONCE ENTONE_URC-4021ABA1-006-R KEY_POWER"
lircd: Debug Sending once, msg: SEND_ONCE ENTONE_URC-4021ABA1-006-R KEY_POWER
, args: ENTONE_URC-4021ABA1-006-R KEY_POWER, once: 1
lircd: Debug clearing transmit buffer
lircd: Debug adding to transmit buffer: 2564
lircd: Debug adding to transmit buffer: 917
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 944
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 944
lircd: Debug adding to transmit buffer: 1158
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 944
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 772
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 944
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 772
lircd: Debug adding to transmit buffer: 944
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 772
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug adding to transmit buffer: 472
lircd: Debug adding to transmit buffer: 386
lircd: Debug transmit buffer ready
lircd: Debug irtoy ready for 0 bytes
lircd: Debug irtoy ready for 2 bytes
lircd: Debug irtoy ready for 0 bytes
lircd: Debug irtoy ready for 58 bytes
lircd: Debug irtoy ready for 0 bytes
lircd: Debug irtoy ready for 6 bytes
lircd: Debug irtoy ready for 0 bytes
lircd: Debug irtoy ready for 57 bytes
lircd: Debug irtoy ready for 0 bytes
lircd: Debug  01 EC

lircd: Error irtoy_send: invalid byte count indicator received: 0F
lircd: Debug Sending error
lircd: Error error processing command: SEND_ONCE ENTONE_URC-4021ABA1-006-R KEY_POWER
lircd: Error transmission failed
lircd: Debug irtoy_raw_rec
lircd: Debug new signal after large space
lircd: Debug readdata 0 1000000
lircd: Debug c1000000
lircd: Debug trying "ENTONE_URC-4021ABA1-006-R" remote
lircd: Debug decode: enter
lircd: Debug <s1000000
lircd: Debug sync
lircd: Debug read_raw 0aff
lircd: Debug read_raw 60053
lircd: Debug readdata 1 60053
lircd: Debug +p60053
lircd: Debug failed on header
lircd: Debug decode: 0
lircd: Debug failed "ENTONE_URC-4021ABA1-006-R" remote
lircd: Debug decoding failed for all remotes
lircd: Info removed client
Judged by the number of issues reported in the forum and the different work-arounds provided (increase process priority, using a USB reset tool, etc.) I personally think it all comes down to either a hardware design flawed or unstable USB firmware. Too bad both don't get any attention any more.
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: Barf on November 24, 2014, 08:36:03 pm
Quote
lircd: Debug irtoy ready for 0 bytes

This does not look sane.

As an experiment to isolate the problem. let me suggest that you try it out with IrScrutinizer (version 1.1.1).  It has a completely different driver. You can import your Lirc configuration, and send it through the 'Toy, for example, 100 times in a row.

You may also try it with AnalysisIR.
Title: Re: Linux Lirc (usb_irtoy driver) device stops responding
Post by: eugenet8k on March 29, 2017, 03:43:59 am
I had the same errors where connection to usb device fails after number of sent IR signals. I use IrDroid USB stick which is based on irtoy. Nothing worked for me in Raspberry Pi 3. But I finally fixed it, the solution is not trivial and was found here: https://gist.github.com/bullshit/918d74 ... nt-1815751 (https://gist.github.com/bullshit/918d74db9473355d7181#gistcomment-1815751)

Basically I took the lircd sources 0.9.4d and updated manually plugins/irtoy.c file, the deal was to increase timeouts:

Code: [Select]
#define IRTOY_TIMEOUT_READYFORDATA 2000000
#define IRTOY_TIMEOUT_FLUSH 20000
#define IRTOY_TIMEOUT_SMODE_ENTER 1000000
#define IRTOY_TIMEOUT_VERSION 1500000

After recompiling and installing lircd everything works great.