Saturday, November 13, 2010

IR control for your router

There are no buttons on my router but very often I need to start some task without accessing the shell. For example I want to switch wireless interface off if I don't need it and the problem here is that I cannot switch it on again wirelessly because wireless interface is off. So I thought I need some kind of a one button USB keyboard or mouse but there is no such thing. Second thought was to use some kind of IR receiver with a remote control. As far as I already have a universal remote control Logitech Harmony 885 I only needed an IR receiver that is supported by Linux. So I bought one manufactured by TechniSat for 15,20Euro with delivery (just google for - TechniSat USB IR receiver)
[Image]



I have OpenWRT on my router and with the kmod-usb-hid module installed it recognized the dongle without additional tweaks (any other Linux distribution with 'HID devices support' shall also work).
usb 1-1.3: new low speed USB device using ehci_hcd and address 14
usb 1-1.3: configuration #1 chosen from 1 choice
input: Formosa21 USB IR Receiver as /devices/pci0000:00/0000:00:0f.5/usb1/1-1/1-1.3/1-1.3:1.0/input/input5
generic-usb 0003:04B4:0100.0005: input: USB HID v1.11 Keyboard [Formosa21 USB IR Receiver] on usb-0000:00:0f.5-1.3/input0


Next is to add proper device profile to my remote control. I didn't know exact name of the device the dongle is compatible with so I went to the amazon and checked related products and found 'TechniSat SkyStar HD 2 PCI' device name. The remote didn't have a profile exactly for this device but offered a compatible one which worked perfectly.

Router registeres my IR dongle as a HID Keyboard device and attaches it to the /dev/input/event1. Pressing a button on my remote produces series of characters
root@Alix:~# cat /dev/input/event1 | hexdump
0000000 b42f 4cde b5fa 000d 0004 0004 0028 0007
0000010 b42f 4cde b609 000d 0001 001c 0001 0000
0000020 b42f 4cde b60f 000d 0000 0000 0000 0000
0000030 b42f 4cde 13c2 000e 0004 0004 0028 0007
0000040 b42f 4cde 13cf 000e 0001 001c 0000 0000
0000050 b42f 4cde 13d2 000e 0000 0000 0000 0000

With a little help script unique id's are filtered
root@Alix:~# cat ./ircmd
#!/bin/sh

while true
do
 cmd=`hexdump -n 96 /dev/input/event1 | head -n 1 | \
      cut -d' ' -f8`
 echo "$cmd"
done


Pressing 5 different buttons on my remote results in:
root@Alix:~# ./ircmd
0028
0052
0051
004f
0050

The only thing left is to assign actions for buttons! But more elegant solution for the IR commands handling is to use triggerhappy

With the WLAN and UMTS modem switched off processor temperature decreases 3,5 degrees C:
[Image]
On this picture both interfaces were switched on at 19:30. Previously I never switched off both interfaces because I was too lazy to open the shell. Now I do it with only one button click on my remote ; )

P.S. also check my other posting regarding an IR receiver development

2 comments:

SandUhrGucker said...

i have the same router and want to controll a ir device (send ir-codes).
but howto? i cant install root@OpenWrt:~# opkg install kmod-usb-hid
Collected errors:
* Cannot find package kmod-usb-hid.

any help/tip/link?
thanks a lot
Rene

alex said...

@SandUhrGucker Maybe you forget to 'opkg update' first? Anyway you can ask OpenWRT related questions on the OpenWRT forum to get some help