NSLU2-Linux
view · edit · print · history

This HowTo gives information on how to use the LEDs to display information on Unslung, and more specifically on how to use the disk 1 LED to indicate new mail, and disk 2 LED to indicate a new private message in irssi.

Taking control of the LEDs in Unslung

I couldn't get Unslung to stop updating the LEDs, so instead i made a script to update the disk LEDs by running Set_Led every second, setting them on if a file exists, and off otherwise.

If the the files /led/disk1on and /led/disk2on exists, disk1 and disk2 LEDs is on otherwise they are off.

Make sure the directory /led exists and that it is writable by users.

mkdir /led
chmod 777 /led

/root/ledsetter.sh:

#!/bin/sh
while [ 1 ]
do
        if [ -f /led/disk1on ]
        then
                Set_Led turn_on1
        else
                Set_Led turn_off1
        fi

        if [ -f /led/disk2on ]
        then
                Set_Led turn_on2
        else
                Set_Led turn_off2
        fi

        sleep 1
done

Make sure it's executable by running chmod +x /root/ledsetter.sh.

Run ledsetter.sh as root in the background with ./ledsetter.sh &. To make it work after reboots, create the following file (perhaps with a different number):

/opt/etc/init.d/S89ledsetter:

#!/bin/sh
/root/ledsetter.sh &

Make sure it's executable by running chmod +x /opt/etc/init.d/S89ledsetter.

Making disk 1 LED indicate new mail

This works by checking for new mail through fetchmail, and make sure the file /led/disk1on exists if there were new mail, and that it doesn't exist otherwise.

Install fetchmail by running ipkg install fetchmail as root.

Then (if user is joe) create /home/joe/.fetchmailrc with a single line similar to:
poll mail.isp.com protocol imap user "joe" password "joe_is_secretive"

Make sure the file is secret by running chmod 600 /home/joe.fetchmailrc.

/home/joe/fetchmailcheck.sh: (Unslung)

#!/bin/sh         
if /opt/bin/fetchmail -c --service 143
then
        touch /led/disk1on
else
        rm /led/disk1on
fi

/home/joe/fetchmailcheck.sh: (Debian)

#!/bin/sh         
/usr/bin/fetchmail -c --service 143 && sudo leds disk-1 fast || sudo leds disk-1 off

Debian note: I couldn't figure out how to allow regular users to change led settings, so i used sudo (apt-get install sudo) instead. But sudo by default asks for a password every 15minutes, i changed this by running (as root) "visudo" and add permissions to ex. user joe:

Defaults:joe     timestamp_timeout=-1
...
vk      ALL=(ALL) ALL

Make sure it's executable by running chmod +x /home/joe/fetchmailcheck.sh.

The fetchmail parameter -c simply checks if there is new mail and then stops. The --service 143 parameter tells fetchmail that imap uses port 143 (why are the imap lines commented out in /etc/services ?).

To make this run every 10 minutes add the following line to /etc/crontab:
*/10 * * * * joe /home/joe/fetchmailcheck.sh > /dev/null 2> /dev/null

Making disk 2 LED indicate new private messages in irssi

This works by using a perl script for irssi that creates /led/disk2on when irssi sends a "message private" signal, and deletes the file on a "window changed" signal.

Make sure the /home/joe/.irssi/scripts directory exists by running mkdir -p /home/joe/.irssi/scripts.

/home/joe/.irssi/scripts/fhilight.pl: (Unslung)

use strict;
use Irssi;

sub fhilight {
    system("touch /led/disk2on 2> /dev/null");
}
sub fseenhilight {
    system("rm /led/disk2on 2> /dev/null");
}

Irssi::signal_add('message private', 'fhilight');
Irssi::signal_add('window changed', 'fseenhilight');

Make sure /dev/null is writeable by running chmod 777 /dev/null.

/home/joe/.irssi/scripts/fhilight.pl: (Debian)

use strict;
use Irssi;

sub fhilight {
    system("sudo leds disk-2 fast");
}
sub fseenhilight {
    system("sudo leds disk-2 off");
}

Irssi::signal_add('message private', 'fhilight');
Irssi::signal_add('window changed', 'fseenhilight');

And to actually load this script run "/script load fhilight" in irssi.

view · edit · print · history · Last edited by vk.
Based on work by fcarolo, vk, and vk0.
Originally by vk0.
Page last modified on August 25, 2008, at 10:33 PM