Using System LEDs for Recording Status

Version 2 (brfransen, 03/25/2010 04:19 pm) → Version 3/4 (brfransen, 03/25/2010 04:19 pm)

h1. Using System LEDs for Recording Status

If you I don't personally care to have the Power LED or the HDD LED reflect system power or disc activity you can re-purpose them to show the -- I figured it would be nice if these two LEDs showed me if my dual tuner MythTV box was recording status of each encoder in your MythTV box.
Follow the instructions below for installation on your LinHES system or see the original article on the "MythTV Wiki.":http://www.mythtv.org/wiki/Using_System_LEDs_for_Recording_Status

h2. Hardware
(and specifically which tuner(s) were recording).

You will need:
To do this I used

* "Python":http://python.org/ 2.3.3 (any 2.2 or later Python should work)
* py Serial 2.1
*
A female DB9 db9 serial connector, preferably with wires connected to the pins

* Some extra wire

On my system I ended up using COM1, my script reflects this.

The first thing you have to do is connect your serial port to the LEDs. To do this, cut the little back connector from the HDD LED wires and Power LED wires which normally you would connect to your motherboard. Strip the ends of the wires. Each wire pair will be some color and white. If you want this to be reversible don't cut the black thing off, just figure out a better way to connect the wires.

Next, focusing on the female DB9. If you face the connector toward you there are 9 holes, the pinout is:
<pre>

5 4 3 2 1

9 8 7 6
</pre>
The pins we want to work with are 4 (DTR), 5 (Ground), and 7 (RTS).

You will now use your extra wire to connect 5 (Ground) to the two white cables coming from the case LEDs.

Next, connect 4 (DTR) to one of the colored cables. Optionally you could use a resistor in this connection, something like a 1000 ohm resistor from what I hear. I didn't do it and it didn't seem necessary, but, this maybe a good idea. These resistors are probably really cheap at Radio Shack.

Finally, connect 7 (RTS) to the other colored cable. Again, maybe a resistor.

I would recommend soldering and/or electrical taping all of the connections. Personally I have just twisted the wires together and electirical taped them, but, do what you like.

> _Note: Note: I just ran the wires from the DB9 plugged into the serial port at back of the case through one of the PCI slot openings. You may have a better way to do it, I couldn't think of one._ one.

Plug the DB9 into a serial port and note which port number it is. (preferably COM1).

h2. Software

Now for the Python script to monitor if the encoders you are recording. recording (OR watching LiveTV, there is no real difference)...

To install on LinHES:
<pre>
sudo pacman -Sy recstat
</pre>

Edit @/usr/bin/recstat.py@
As this script only checks for recording status of the two tuners once a minute, I believe it should add very low overhead. If you want the check to occur more or less often just adjust the time.sleep(60) statement to meet your system:
* Modify encoder lines
needs.

Assuming you wired the cable
to match the name LEDs correctly, you are plugged into COM1, and number of encoders listed do have two tuners on the MythWeb Status page.
* Modify the @s = serial.Serial(0)@
/dev/video0 and /dev/video1 this script should run fine for you. The last bit to do is to make it being execution on system startup. To do this (using Redhat) I added a line to match my "/etc/rc.d/rc.local"

# /root/checkrecording.py &

Enjoy! Kevin C. Dorff

Special thanks to Travis Kelley for posting
the COM port you plugged `fuser ...` stuff to the DB9 into (ie. COM1 would be @s = serial.Serial(0)@, COM2 would be @s = serial.Serial(1)@)
MythTV mailing list so I knew how to see if /dev/video0 or /dev/video1 was recording.

* OPTIONAL: Change
o This nice script has
the @time.sleep(1)@ line one slight problem, it is unable to change how often differentiate between a 'live tv' display and a 'recording' display.

You should be able to do this. Try this instead: ls -l /proc/`fuser /dev/video0 | awk '{print $2}'`/fd/ 2>&1 | grep nuv$

This tells you if
the status of the encoders process that is checked using /dev/video0, also has a file handle open to a file that ends in nuv. Give this a try and integrate into your script.

To start Scott Carlson

As someone pointed out on
the recstat program mailing list -- another extremely low-tech way to do this, at boot run @sudo add_service.sh recstat@ least on a combined frontend/backend box, is to hook up a hard disk activity LED ;) -- Justin Mason