OpenWrt Forum Archive

Topic: WR703N + lirc and IR remote remote problem

The content of this topic has been archived on 21 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello,

My goal is to setup OpenWrt+ LIRC + USB audio mic input + IR remote system.
I was following this FAQ: http://wiki.openwrt.org/doc/howto/lirc-audio_alsa

I've two OpenWrt setups: one is OpenWrt (AA) x86 Virtualbox and second is OpenWrt (AA) on WR703N.
Both systems has the same ALSA, LIRC configuration files.

The same piece of hardware (IR receiver+USB audio) is working well on OpenWrt x86, and irexec proceeds commands well, but on OpenWrt WR703N is doesn't work:
- irw doesn't shows any messages coming
- irexec doesn't executes any commands
- BUT irrecord util is able to record signals from IR remote, and makes LIRC configuration file (which works on x86 btw)
- mode2 util also shows good signals coming from IR remote

Lircd log file doesn't shows any errors, or problems. Lirc is recompiled with alsa support.

OpenWrt on WR703N plays audio files well using this USB card. Alsamixer also shows this card as recognized.

Could you please help me to debug this situation?

Where to start?

The strange part is, that sometimes (after reboots, or after some time) irw&irexec starts working well for several minutes, and then stops with no reason. No changes are done in configuration during that time...

Thanks,
Valentas

could it be the usual ar9331 usb full speed problems? could you try to use a high speed usb hub?

(Last edited by nebbia88 on 24 Jul 2013, 20:39)

Could be...
Hm, where to get high speed usb hub? I guess all new hubs are full speed?
Maybe there are way to limit speed using software?

to simplify, full speed means 1.1, high speed is 2.0

not all (chinese quality) usb hubs are really high speed wink

you will see on dmesg anyway..

dmesg shows after usb audio reconnection:
[11156.240000] usb 1-1.4: USB disconnect, device number 4
[11165.180000] usb 1-1.4: new full-speed USB device number 5 using ehci-platform

Looks like a problem...

Does powered usb hub could solve this problem?

i don't think it's a power problem.. don't you have a "normal" usb 2.0 hub to try?

I tried to connect usb audio card to notebook with x86 OpenWrt, and it shows it as full-speed device.
Another usb audio card also appears as full-speed device.

So, it looks that most of cheap usb audio cards are full-speed devices...

Does it means, that I've to look for another usb audio, which is high speed?

"don't you have a "normal" usb 2.0 hub to try?"

what is not clear to you in this sentence?!?

The word "normal" smile
I think my hub is quite normal (>10eur)

Sure, I will get another one to test.

Hi,
I think I know what your problem is. When I started trying to accomplish the same thing I spent like two days trying to figure out a solution.
I don't think this has nothing to do with the ar9331 problem.
So, good and bad news. Bad news: I still dont know what the causes are. Good news: If it's the same problem it's just a matter of running a script every time you reboot (which luckily in my case is when the AC power goes down or something like that).
As you said, the strange thing is that after you mess a little with lircd it works, but then somehow when you try to reproduce that you just can't. The only thing one can do then is try to find a way of improving chances.
In my case this was a call in rc.local to a script:

#!/bin/ash

if [ "$1" == "boot" ]; then

for countv in 1 2; do
amixer sset Speaker "0%,0%"
killall lircd
mpc play
lircd -d plughw@8000 /etc/lirc/lircd.conf
irexec --daemon /etc/lirc/lircrc 
sleep 1
mpc stop
amixer sset Speaker "68%,68%"
sleep 1
done

else

amixer sset Speaker "0%,0%"
killall lircd
mpc play
lircd -d plughw@8000 /etc/lirc/lircd.conf
irexec --daemon /etc/lirc/lircrc 
sleep 1
mpc stop
amixer sset Speaker "68%,68%"

fi

Now I don't know why but I discovered that whenever you make mpd(already running and with an mp3 loaded at this point) silently play something the chances of getting lircd to work were a lot higher. I play-start_lirc-stop twice at boot and sometimes it works, but sometimes it doesn't so after it's done booting I ssh into the router and run the script(without the boot flag) and try if the remote works. If it doesn't I do it once more.
I have been using this trick for like two years now and I don't think I ever needed to run the script manually more than two or three times per boot. It usually works at boot time is what I'm saying.
My thoughts on why this needs to be done is that the music player does something to the soundcard when playing music, that the lirc's alsa driver is missing. But it is just speculation because I don't have the knowledge to trace the error.
What baffles me is that sometimes it works at boot, sometimes you have to run the script once after boot and sometimes twice. When computers approach randomness I usually get scared. So there has to be some logical explanation, as with the Flite software.
Finally, I couldn't generate a usable configuration file using irrecord but luckily I found one that works on a web site. The only thing I had to correct is the aeps value (to 200) and that improved sensitivity a lot.
Let me know how it goes or if you find a better way of dealing with this issue.

valentast wrote:

The word "normal" smile
I think my hub is quite normal.


i'm sorry i do not see the word "hub" in your previous post, only the word "usb audio card".., that was confusing me!

Thank you gsenna!!!

Amazing, but it works! At least predictable smile

Some other problems discovered:
1. I always have to run script my hand 1-2 times after boot. Can't understand why running from rc.local doesn't work. Maybe some longer sleep needed? Or problem with environment variables?

2. MPD works only with oss audio output, when starting with alsa ->

 output: line 199: No such audio output plugin: alsa 

The problem with oss, I can't control volume, regardless what mixer settings...

mpd installed via opk, mpd-mini - 0.16.5-2

Valentas

nebbia88: sorry it was my mistake, I forgot to mention, that usb audio is connected over usb hub.

Cheers! I'm glad I was able to help you.

valentast wrote:

1. I always have to run script my hand 1-2 times after boot. Can't understand why running from rc.local doesn't work. Maybe some longer sleep needed? Or problem with environment variables?

Yes, you're right. But sometimes it works at boot time I think. You could try changing to "for countv in seq 1 2 3 ; do" but I think it'll be the same. It is my understanding that in a system like this rc.local is the last thing that's executed.

valentast wrote:

2. MPD works only with oss audio output, when starting with alsa ->

 output: line 199: No such audio output plugin: alsa 

The problem with oss, I can't control volume, regardless what mixer settings...

mpd installed via opk, mpd-mini - 0.16.5-2

Valentas

That's easy to explain I think. If you look at the Makefile of mpd, you'll see:

ifeq ($(BUILD_VARIANT),mini)
      # oggflac is not compatible with tremor
      CONFIGURE_ARGS += \
            --disable-aac \
            --disable-alsa \

Solution: Install mpd-full.

Thanks for tip!
Ok, now mpd starts with alsa enbled. But still can't change volume....

audio_output {
        type            "alsa"
        name            "My ALSA Device"
        device          "hw:0,0"        # optional
        format          "44100:16:2"    # optional
        mixer_type      "hardware"      # optional
        mixer_device    "/dev/mixer"       # Also tried "default"
        mixer_control   "PCM"           # optional
} 
root@OpenWrt:~# cat /proc/asound/cards
 0 [Device         ]: USB-Audio - Generic USB Audio Device
                      Generic USB Audio Device at usb-ehci-platform-1.2, full speed
root@OpenWrt:~#
root@OpenWrt:~# ls /dev/mix*
/dev/mixer
root@OpenWrt:~#

I can change volume using amixer, but not from mpd...

You're welcome! You may have a wrong mpd.conf.
Please run amixer and post the results.

(Last edited by gsenna on 26 Jul 2013, 04:00)

Here it is:

root@OpenWrt:~# amixer
Simple mixer control 'Speaker',0
  Capabilities: pvolume pswitch pswitch-joined penum
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 151
  Mono:
  Front Left: Playback 64 [42%] [-16.38dB] [on]
  Front Right: Playback 64 [42%] [-16.38dB] [on]
Simple mixer control 'Mic',0
  Capabilities: pvolume pvolume-joined cvolume cvolume-joined pswitch pswitch-joined cswitch cswitch-joined penum
  Playback channels: Mono
  Capture channels: Mono
  Limits: Playback 0 - 32 Capture 0 - 16
  Mono: Playback 23 [72%] [34.36dB] [off] Capture 0 [0%] [0.00dB] [on]
Simple mixer control 'Auto Gain Control',0
  Capabilities: pswitch pswitch-joined penum
  Playback channels: Mono
  Mono: Playback [on]
root@OpenWrt:~#
root@OpenWrt:~# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Device [Generic USB Audio Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
root@OpenWrt:~# aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
default:CARD=Device
    Generic USB Audio Device, USB Audio
    Default Audio Device
root@OpenWrt:~#

Yes, as I suspected. You have a wrong configuration option set. So, fixing the volume control is easy.
Having said that, if you have a similar USB sound card to the one I have you may have another problem with that configuration. With some mp3 files I used to hear like a metallic sound. So I recommend you to try something like:

audio_output {
         type "alsa"
         name "My ALSA Device"
         mixer_control "Speaker" 
         device "plughw:0,0"  
} 

That is the one my sound card liked the most. Also, if I tried changing the resampling option it downgraded the quality. So keep the following options disabled and see how it goes:

#audio_output_format        "48000:16:2"
#samplerate_converter        "internal"

Thanks again!
Now I can control mpd volume from iPhone as well:)

I think your script should be included in OpenWrt Wiki for Lirc:) Because Alsa support in Lirc for ar71xx platform (other?) is somehow broken. The same setup on x86 platfrom works fine.

Hi, I'm also having this problem.

I used lirc audio_alsa in Backfire with customized firmwares without this issue.

But newer revisions have this problem. It is very easy to reproduce for me. With alsa-utils installed, arecord does the job. Just make dummy records

/usr/bin/arecord -q -d 1 -r44100 -f S16_LE -c1 -t raw > /dev/null

- Let's start in a state where  lirc audio_alsa works perfectly, irw shows the remote codes, close irw, and execute arecord, then open again irw --> it stops working or working bad
- Execute three more times again --> now irw starts working fine again
- Execute four times arecord --> irw works fine

root@OpenWrt:/# irw
00000000000005e9 00 + rct3004
00000000000005e9 00 + rct3004
00000000000005e9 00 + rct3004
00000000000005e9 00 + rct3004
^C
root@OpenWrt:/# /usr/bin/arecord -q -d 1 -r44100 -f S16_LE -c1 -t raw > /dev/null
root@OpenWrt:/# irw
^C
root@OpenWrt:/# /usr/bin/arecord -q -d 1 -r44100 -f S16_LE -c1 -t raw > /dev/null
root@OpenWrt:/# irw
^C
root@OpenWrt:/# /usr/bin/arecord -q -d 1 -r44100 -f S16_LE -c1 -t raw > /dev/null
root@OpenWrt:/# irw
^C
root@OpenWrt:/# /usr/bin/arecord -q -d 1 -r44100 -f S16_LE -c1 -t raw > /dev/null
root@OpenWrt:/# irw
00000000000005e9 00 + rct3004
00000000000005e9 01 + rct3004
00000000000005e9 00 + rct3004
00000000000005e9 00 + rct3004
00000000000005e9 00 + rct3004
00000000000005e9 01 + rct3004
^C
root@OpenWrt:/# /usr/bin/arecord -q -d 1 -r44100 -f S16_LE -c1 -t raw > /dev/null
root@OpenWrt:/# irw
^C
root@OpenWrt:/# /usr/bin/arecord -q -d 1 -r44100 -f S16_LE -c1 -t raw > /dev/null
root@OpenWrt:/# irw
^C
root@OpenWrt:/# /usr/bin/arecord -q -d 1 -r44100 -f S16_LE -c1 -t raw > /dev/null
root@OpenWrt:/# irw
^C
root@OpenWrt:/# /usr/bin/arecord -q -d 1 -r44100 -f S16_LE -c1 -t raw > /dev/null
root@OpenWrt:/# irw
00000000000005e9 00 + rct3004
00000000000005e9 00 + rct3004
00000000000005e9 00 + rct3004
00000000000005e9 00 + rct3004
00000000000005e9 01 + rct3004

As you can see poking alsa with arecord exactly 4 times turns the alsa/audio stuff in a state where irw works perfectly. I tested it many times and always after 4 arecord dummy recordings all works fine.

The problem here is, other stuff in the system pokes alsa/audio stuff, so we need to poke manually with arecord 1,2, or 3 times to complete the cycle of 4 pokes.

When booting the system I only need 1 poke, once irexec handle the usb soundcard no other stuff will ruin the remote detections. I do it before mpd starts. I'm currently using this ugly init script

START=90

start() {
        #create lircd directory
        /bin/mkdir /var/run/lirc/
        #start lirc daemon
        /usr/sbin/lircd --driver=audio_alsa -d plughw@24000
        #give some time to lircd to finish handling the soundcard
        /bin/sleep 1
        #poke alsa input with one dummy recording
        /usr/bin/arecord -q -d 1 -r44100 -f S16_LE -c1 -t raw > /dev/null
        #this sleep shouldn't be need
        /bin/sleep 1
        /usr/sbin/irexec --daemon /etc/streamradio/lircrc
}

stop() {
        /usr/bin/killall lircd
}

I suspect this might be an endianess problem, 4 bytes defines the endianess, and 4 times executing arecord returns the audio card to a sane state, well who knows.

Did anyone get IR to work on a WR703N?

I have uploaded a Makefile and binaries for Barrier Breaker on https://github.com/probonopd/lirc-audio … or-openwrt

I can see some signals with mode2, but irw shows nothing and I get "irrecord: gap not found, can't continue".

(Last edited by probono on 1 Jan 2015, 22:02)

The discussion might have continued from here.