Increase your laziness with LIRC and Perl

I have some speakers on my patio, driven by an old Pioneer VSX-305 receiver inside my house. The only device supplying audio to the receiver is my kitchen computer, which is a Linux computer with a touch screen running a home-brew GUI for playing music, looking up recipes, weather, TV, displaying kitchen timers, news, etc. The normal stuff you need while cooking breakfast. Here is a picture of the kitchen set up:

Japi's kitchen linux computer

The receiver also powers two speakers inside, and it has toggles to control if the inside speakers, outside speakers or both sets of speakers are powered. To allow me to control the volume of music playback and navigate the playlist without having to be in front of the computer I have an old X10 “Lola” RF remote (model UR89A) hooked up to the USB port. It is supported by LIRC, and since it is RF it works from outside. The patio is right next to where the kitchen computer is, so range isn’t often a problem from there. But, sometimes I forget to bring the remote outside, or I am working elsewhere in the yard and am out of range. What to do? Well, the obvious answer is to set up a Web gateway to send LIRC button events from my cell phone!

Luckily LIRC has a built in driver for UDP input, which is perfect for instant, easy synthetic button event generation. The bad thing about this driver is that it is “mode2”, not the already-encoded button codes. But, mode2 is just a series of pulses and spaces, which are converted into the code in a fairly simple and predictable way (at least for the remote I chose to use as a tester for development). So, I whipped up a little bit of perl code that will take an LIRC code (such as 0x000000014dd080000), and convert it into a UDP packet of all the pulses and spaces that are needed for LIRC to recognize it. The packet is sent out the broadcast interface, so any LIRC clients listening will receive it. This code is available for download
here.

Once that was working, it was easy to write a quick perl CGI script to display some buttons to the user, a field for entering in a password (for very minimal security), and toss it on my server. That perl file is available for download here. I do recommend against having it publicly accessible, since it makes a “system()” call, and doesn’t do much validation. Here is a picture of the interface on my T-Mobile MDA cell phone (ChanUp/ChanDown navigate the playlist):

LIRC-CGI on T-Mobile MDA

Accessing the page through my WiFi is pretty snappy (the returned HTML is less then 1300 bytes), certainly fast enough for the occasional button pushes that I need to do. Since many pieces of Linux software support LIRC, this code should be useful for controlling other things too, such as XMMS, MPlayer, MythTV, xawtv, etc.

1 Comment

  1. Pingback: Perl Coding School » Blog Archive » perl news [2008-02-18 00:09:40]

Leave a Comment