TechInfoDepot:DD-WRT/LED Scripts

From TechInfoDepot
Jump to navigationJump to search

The example LED scripts below are written using the GPIO info for the Linksys WRT. Remember to change them for whatever router you have.

You can't use the GPIOS on Atheros chips (Fonera, Meraki, etc.) without PROC_GPIO or some other utility. PROC_GPIO is a driver, and thus it must be compiled for your specific kernel. Broadcom routers do not need an external driver to drive GPIOs.

GPIO Info for Linksys WRT

Pin	Direction	Name		Use
GPIO 0	Output	WLAN  LED  	(LED - wireless)
GPIO 1	Output	POWER LED	(LED - power)
GPIO 2	Output	ADM_EECS   	(LED - white, Cisco button v. 3.0+)
GPIO 3	Output	ADM_EESK  	(LED - amber, Cisco button v. 3.0+)
GPIO 4	Input	ADM_EEDO  	(Button - Cisco Button v. 3.0+)
GPIO 5	Output	ADM_EEDI    	(Unknown) Seems to cycle all LED colors disabled.
GPIO 6	Input	RESET		(Button - reset button)
GPIO 7	Output	DMZ LED		(LED - DMZ)

GPIO Info for Linksys WRT150N v1.1 (dd-wrt.v24_mini_generic)

Here is a short summary of my experiments with WRT150N v1.1 on dd-wrt.v24_mini_generic firmware. WRT150N has a SECURITY LED (the most right LED)

root@DD-WRT:~# gpio enable 5 #(SECURITY LED - off - green)
root@DD-WRT:~# gpio disable 5 #(SECURITY LED - on - green)
root@DD-WRT:~# gpio disable 3 #(SECURITY LED - on - amber)
root@DD-WRT:~# gpio enable 3 #(SECURITY LED - off - amber)

When you switched to gpio disable 3 (SECURITY LED - on - amber)

root@DD-WRT:~# gpio enable 5 #(SECURITY LED - will give you amber)
root@DD-WRT:~# gpio disable 5 #(SECURITY LED - will give you amber bright)

GPIO Info for Linksys WRTSL54GS

This is for the WRTSL54GS model only.

Pin     Direction       Name            Use
GPIO 5  OUTPUT          SES LED         (Cisco white LED)
GPIO 7  OUTPUT          SES LED         (Cisco amber LED)

GPIO Info for Buffalo WHR

Pin	Direction	Use
GPIO 0	Input		AOSS button
GPIO 1	Output		Bridge LED
GPIO 2	Output		WLAN LED
GPIO 3	Output		Extra LED between bridge and WLAN
GPIO 4	Input		Reset button
GPIO 5	Input		Bridge/auto switch
GPIO 6	Output		AOSS LED
GPIO 7	Output		DIAG LED
GPIO 8	n/a		Unkown/none
GPIO 9	Output		Power LED

GPIO Info for LaFonera 2100

Pin	Use
0	TP3
1	pin 5 of SW1
2	WLAN LED
3	pin 1 of SW1
4	pin 2 of SW1
5	Reset (!)
6	Reset button
7	pin 6 of SW1

La Fonera 2200

2 WIFI LED contact at bottom of local resistor
5 Reset! (Can be used as a GPIO, but you lose reset functionality) This is the line closest to the RP4 component (next to 3 other lines, GPIOS 6, 2, and 7)
   Cut the trace and use the end closest to the CPU as a GPIO.
6 Reset button (other end of button is VDD, (3.3 V)) remove nearby capacitor
7 Power LED contact at bottom of local resistor

La Fonera 2201

1 WLAN Orange LED
2 WLAN Green LED
4 Power Green LED
7 Power Orange LED

GPIO Button Wifi Toggle D-Link DIR-300

This script will enable the button on the righte side to act as a wifitoggle. on press the button-led will light up

  • RED, when wifi is going to be disabled. wifi-led on the front will go out.
  • BLUE, when wifi is going to be enabled again. wifi-led on the front will light up.
#!/bin/sh
/sbin/gpio enable 4
echo "0" > /proc/gpio/4_out
echo "0" > /proc/gpio/4_in
while : ; do
WIFI=`nvram get ath0_net_mode`
sleep 1;
        if [ "$(cat /proc/gpio/4_in )" = "1" ]; then
        if [ "$WIFI" == "disabled" ]; then
		/sbin/gpio enable 1
		nvram set ath0_net_mode=mixed
                /sbin/ifconfig ath0 up
		/sbin/gpio enable 2
		echo "0" > /proc/gpio/4_in
		sleep 3
		/sbin/gpio disable 1
        else
		/sbin/gpio enable 3
		nvram set ath0_net_mode=disabled
                /sbin/ifconfig ath0 down
		/sbin/gpio disable 2
		echo "0" > /proc/gpio/4_in
		sleep 3
		/sbin/gpio disable 3
        fi
fi
done &

GPIO Info D-Link DIR-320

Pin	Direction	Use
GPIO 0	Output	(LED - WIRELESS)
GPIO 1	Output	(LED - STATUS)
GPIO 3	Output	(LED - RED)
GPIO 4	Output	(LED - BLUE)
GPIO 5	Output	(LED - USB)
GPIO 6	Input	(Button on the right)

For GPIO information, send a private message to DD-WRT user "meltyblood"

To turn cisco led blue / white ...

Per Eko here

Yellow cisco led on Linksys routers means that router got WAN ip. If you prefer it blue (white, ..) do:

In latest builds only (13522+):

nvram set connblue=1
nvram commit
reboot

Display Load via LED (load.sh)

  • Uses front button LED to display current load on router.
  • For WRT54G/GL/GS
#!/bin/sh
gpio="gpio"

amber=3
white=2

delay=3

meltdown=400
overload=100
highload=70
medload=30

while sleep $delay;do
  set -- $(cat /proc/loadavg)
  load="${1%.*}${1#*.}"

  if [ $load -gt $meltdown ];then
    $gpio disable $amber
    usleep 50000
    $gpio disable $white
    usleep 50000
    reboot
  elif [ $load -gt $overload ];then
    $gpio disable $amber
    usleep 50000
   elif [ $load -gt $highload ];then
    $gpio disable $amber
    usleep 12500
    $gpio enable $amber
    usleep 12500
    $gpio disable $amber
    usleep 12500
    $gpio enable $amber
    usleep 12500
    $gpio disable $amber
    usleep 12500
    $gpio enable $amber
    usleep 12500
  elif [ $load -gt $medload ];then
    $gpio enable $amber
    $gpio disable $white
    usleep 25000
    $gpio enable $white
    usleep 25000
    $gpio disable $white
    usleep 25000
    $gpio enable $white
    usleep 25000
  else
    $gpio disable $white
    usleep 50000
    $gpio enable $white
    usleep 50000
  fi
done

Modified Script for simple display of cpu usage/load -- I use the power LED Low activity/idle (led off), medium (short flashes), high (long flashes), max (led on solid)

#!/bin/sh
gpio="gpio"

#This is the LED to flash
led=0

extreme=110
high=75
med=35

while [ 0 ];do
  set -- $(cat /proc/loadavg)
  load="${1%.*}${1#*.}"

  counter=10

  if [ $load -gt $extreme ];then
    $gpio disable $led
    sleep 8
  elif [ $load -gt $high ];then
    while [ $counter -gt 0 ];do
      usleep 200000
      $gpio disable $led
      usleep 800000
      $gpio enable $led
      let counter-=1
    done
  elif [ $load -gt $med ];then
    while [ $counter -gt 0 ];do
      usleep 800000
      $gpio disable $led
      usleep 200000
      $gpio enable $led
      let counter-=1
    done
  else
    $gpio enable $led
    sleep 8
  fi
done

WDS link and/or associated wireless clients

  • illuminates front button LED white when able to ping the gateway
  • illuminates front button LED amber when wireless clients are connected
  • illuminates both colors on the button when both conditions are true
  • no light when neither condition is true
  • developed / tested on a WRT54G-TM
GATEWAY=`ip route | awk '/default via/ {print $3}'`
WDS_LINK_ACTIVE=false
ASSOC_CLIENTS=false
LOOP=0

[ `sh -c "ps | grep $0 | grep -v grep -c"` -gt 1 ] && echo Already running && exit

while sleep 1
do

	[ $LOOP -lt 300 ] && LOOP=$(( $LOOP + 1 )) || LOOP=1

	while ! $WDS_LINK_ACTIVE
	do
		sleep 5
		ping -c 1 $GATEWAY >/dev/null && WDS_LINK_ACTIVE=true
	done

	[ $LOOP -eq 1 ] && {
		ping -c 1 $GATEWAY >/dev/null || WDS_LINK_ACTIVE=false
	}

	[ -z $(wl -i `nvram get wl0_ifname` assoclist) ] && ASSOC_CLIENTS=false || ASSOC_CLIENTS=true

	$WDS_LINK_ACTIVE && gpio disable 2 || gpio enable 2
	$ASSOC_CLIENTS && gpio disable 3 || gpio enable 3

done

WLAN Status (wlan.sh)

Works on k2.4 and k2.6

  • Uses front button LED to show WLAN state. Amber LED indicates one or more associated clients, white LED flashes when data is sent over WLAN.
#!/bin/sh
I=`nvram get wl0_ifname`

while sleep 1; do
  if [ -z `wl -i $I assoclist` ]; then
    XFER=`ifconfig $I|grep bytes`
    if [ "$XFER" != "$PXFER" ]; then
      LED='gpio disable 3 ; gpio disable 2'
      PXFER=$XFER
    else
      LED='gpio disable 3 ; gpio enable 2'
    fi
  else
    LED='gpio enable 3 ; gpio enable 2'
  fi
  
  if [ "$LED" != "$PLED" ]; then
    eval $LED
    PLED=$LED
  fi
done

WLAN Status (wlan.sh) - Buffalo Routers

  • AOSS LED to show WLAN is associated with clients.
  • Bridge LED flashes when data is transmitted over WLAN.
#!/bin/sh
I=`nvram get wl0_ifname`

while sleep 1; do
  if [ -z `wl -i $I assoclist` ]; then
    XFER=`ifconfig $I|grep bytes`
    if [ "$XFER" != "$PXFER" ]; then
      LED='gpio disable 1 ; gpio enable 1 ; gpio disable 6'
      PXFER=$XFER
    else
      LED='gpio disable 6'
    fi
  else
    LED='gpio enable 6'
  fi

  if [ "$LED" != "$PLED" ]; then
    eval $LED
    PLED=$LED
  fi
done

WLAN Client Mode Status

Works on k2.4 and k2.6
Works on Repeater Bridge as well

  • White LED if we can ping the gateway
  • Orange LED if associated to an AP, but pinging fails.
#!/bin/sh
AMBER='gpio disable 3 ; gpio enable 2'
WHITE='gpio enable 3 ; gpio disable 2'
BLACK='gpio enable 3 ; gpio enable 2'
PACKETS='1'
INTERVAL='10'

trap lightsoff 1 2 3 6 14 15
lightsoff()
{
gpio enable 3 ; gpio enable 2 ; exit 1
}

while true ; do
 if [ -z $(wl -i `nvram get wl0_ifname` assoclist) ]; then
   TARGET=`ip route | awk '/default via/ {print $3}'`
   RET=`ping -c $PACKETS $TARGET 2> /dev/null | awk '/packets received/ {print $4}'`
     if [ "$RET" -eq "$PACKETS" ]; then
       LED=$WHITE
     else
       LED=$AMBER
     fi
  else
    LED=$BLACK
  fi
  if [ "$LED" != "$PLED" ]; then
    eval $LED
    PLED=$LED
  fi
  sleep $INTERVAL
done

WLAN Disable Radio If No Clients Connected

This is a cron job that will run every hour and turn off the radio if no clients are connected as requested here.

0 * * * * root I=`nvram get wl0_ifname`;[ -z `wl -i $I assoclist` ] && wl -i $I radio off

Show VPN status/activity with SES/Cisco LED

I worked out this little script out for my WRT54G-TM and WRT54GL and I thought I would share here since its based from examples shown on this forum and the wiki.

The script requires that you set 2 options in your vpn config file:

status /path/to/file (example: /tmp/vpn-status)
status-version 2

For activity it parses the info in /proc/net/dev

Be sure to edit the first 2 lines (VPN_STATUS= and VPN_DEV=) of this script to match your settings.. then Paste the following into your Startup script. Code:

vpn_leds() {
VPN_STATUS=/tmp/vpn-status
VPN_DEV=tap0

# make sure status file exists
[ ! -f "$VPN_STATUS" ] && return 1
 
# Set initial Cisco/SES Led mode
AMBER='gpio disable 3 ; gpio enable 2'
WHITE='gpio enable 3 ; gpio disable 2'
BLACK='gpio enable 3 ; gpio enable 2'
eval $BLACK

LAST_ACT=0
while [ 1 ]; do
    if [ $(cat "$VPN_STATUS" |grep -c "") -gt 6 ]; then
      # tunnel up. White LED
      LED=$WHITE
      ACT_STRING="$(cat /proc/net/dev |grep "$VPN_DEV")"
      if [ "$ACT_STRING" != "$LAST_ACT" ]; then
        LED=$AMBER
        LAST_ACT=$ACT_STRING
      else
        LED=$WHITE
        LAST_ACT=$ACT_STRING
      fi
    else
      # tunnel down. All leds OFF
      LED=$BLACK
    fi 
    if [ "$LED" != "$PLED" ]; then
      eval $LED
      LAST_LED=$LED
    fi
    sleep 1
done
}
vpn_leds &

Reboot your router and viola!

Light off = Tunnel down
White = Tunnel up
Amber = Activity

You can change the behavior of this script by changing each LED=$COLOR line.

Response time for tunnel up/down indication for my setup is 60sec for client connect and 120sec for disconnect. I believe the disconnect response could be improved by changing your keepalive setting in your VPN config.

Mine is set to: keepalive 10 120

This means OpenVPN will ping the client every 10sec and assume the client has disconnect if no reply is received within 120sec. lowering the last value should improve the response time but be careful not to lower it too much as not to cause connection drops due to timeout

Hope this helps,
-onemyndseye
Original Post

Update: Fun with egrep!

Here is an updated version that will monitor for activity on ANY tap or tun device that exists. Still only showing up/down status for 1 tunnel

vpn_leds() {
VPN_STATUS=/tmp/vpn-status

# make sure status file exists
[ ! -f "$VPN_STATUS" ] && return 1
 
# Set initial Cisco/SES Led mode
AMBER='gpio disable 3 ; gpio enable 2'
WHITE='gpio enable 3 ; gpio disable 2'
BLACK='gpio enable 3 ; gpio enable 2'
eval $BLACK

LAST_ACT="$(cat /proc/net/dev |egrep "tap|tun")"
while [ 1 ]; do
    if [ $(cat "$VPN_STATUS" |grep -c "") -gt 6 ]; then
      # tunnel up. White LED
      LED=$WHITE
      ACT_STRING="$(cat /proc/net/dev |egrep "tap|tun")"
      if [ "$ACT_STRING" != "$LAST_ACT" ]; then
        LED=$AMBER
        LAST_ACT=$ACT_STRING
      else
        LED=$WHITE
        LAST_ACT=$ACT_STRING
      fi
    else
      # tunnel down. All leds OFF
      LED=$BLACK
    fi
    if [ "$LED" != "$PLED" ]; then
      eval $LED
      LAST_LED=$LED
    fi
    sleep 1
done
}
vpn_leds &

USB Disc Mount Status and Umount Button (DIR-320 running v24-sp2 mini-usb-ftp)

  • SES red LED to indicate disc mounted
  • SES button to umount disc
  • SES blue LED to indicate umounting proccess

Script /jffs/etc/config/mount_status.startup (disc mount status)

#!/bin/sh
mp="/`nvram get usb_mntpoint`"

RED_ON='gpio disable 3'
RED_OFF='gpio enable 3'

while sleep 1; do
  if [ "`mount | grep $mp`" ]; then
     LED=$RED_OFF
  else
     LED=$RED_ON
  fi
  
  if [ "$LED" != "$PLED" ]; then
     eval $LED
     PLED=$LED
  fi
done

Script /jffs/etc/config/mount.sesbutton

#!/bin/sh
mp="/`nvram get usb_mntpoint`"
proftpd_enable="`nvram get proftpd_enable`"


RED_ON='gpio disable 3'
RED_OFF='gpio enable 3'
BLUE_ON='gpio disable 4'
BLUE_OFF='gpio enable 4'

if [ "`mount | grep $mp`" ]; then
   $RED_OFF
   $BLUE_ON
   if [ "$proftpd_enable" == "1" ]; then
      killall proftpd
   fi
   umount $mp
   if [ "$proftpd_enable" == "1" ]; then
      proftpd
   fi
fi

if [ "`mount | grep $mp`" ]; then
   $RED_ON
else
   $RED_OFF
fi

$BLUE_OFF

Display signal strength over the SES light - Linksys router

http://www.dd-wrt.com/phpBB2/viewtopic.php?p=461193
Use this script
If you want to catch a better signal without computers.

Script not work in dd-wrt micro version

Linksys routers where this script will work :

- WRT54GL v1.0
- WRT54GL v1.1
- WRT54G-TM
- WRT54G v4.0

Linksys routers where the script does not work:
- WRT54GS v6.0
- WRT54G v5
- WRTSL54GS

has not yet been tested on other models

Discuss here.


Script Version 1

SES light Black.jpg - No signal or very weak

SES light White.jpg SES light Black.jpg SES light White.jpg - Low signal

SES light Amber.jpg SES light Black.jpg SES light Amber.jpg - Good signal

SES light Amber.jpg SES light White.jpg SES light Amber.jpg - Excellent signal


Installation is pretty simple:

1. Go to "Administration -> Commands"
2. Paste script in "Command Shell"
3. Click on "Save Startup"
4. Reboot router

Works great in Client mode and Repeater mode

To work in AP mode, you must put the mac address

#!/bin/sh
############Created by MOJSO####################
#  White / Black / White - low signal      #
#  Amber / Black / Amber - good signal     #
#  Amber / White / Amber - excellent signal#
############################################
while sleep 3; do
BLACK=`gpio enable 3 ; gpio enable 2`
S=`wl rssi` #(put mac adress if in AP mod example: S=`wl rssi 00:11:22:33:44:55` )
N=`wl noise`

SC=`expr $S - $N` 
RSC=`expr $SC / 10`

if  [ $RSC -eq 0 ]; then
gpio enable 3 ; gpio enable 2 ;

elif  [ $RSC -eq 1 ]; then
   gpio enable 3 ; gpio disable 2 ;
sleep 1
   gpio enable 3 ; gpio enable 2 ;
sleep 1
   gpio enable 3 ; gpio disable 2 ;
   
elif  [ $RSC -eq 2 ]; then
   gpio enable 3 ; gpio disable 2 ;
sleep 1
   gpio enable 3 ; gpio enable 2 ;
sleep 1
   gpio enable 3 ; gpio disable 2 ;
   
elif  [ $RSC -eq 3 ]; then
   gpio enable 3 ; gpio disable 2 ;
sleep 1
   gpio enable 3 ; gpio enable 2 ; 
   sleep 1
  gpio enable 3 ; gpio disable 2 ;
  
elif [ $RSC -eq 4 ];  then 
  gpio disable 3 ; gpio enable 2 ;
sleep 1
  gpio enable 3 ; gpio enable 2 ;
sleep 1
  gpio disable 3 ; gpio enable 2 ;
  
elif [ $RSC -eq 5 ];  then 
  gpio disable 3 ; gpio enable 2 ;
sleep 1
  gpio enable 3 ; gpio enable 2 ;
sleep 1
  gpio disable 3 ; gpio enable 2 ;
  
elif [ $RSC -ge 6 ];  then 
  gpio disable 3 ; gpio enable 2 ;
sleep 1
  gpio enable 3 ; gpio disable 2 ;
sleep 1
  gpio disable 3 ; gpio enable 2 ;
else  gpio enable 3 ; gpio enable 2 ;
fi
done

Script Version 2

Script version two show signal more precise

SIGNAL STRENGTH

  • 0 blink = SNR < 9 No signal or very weak
  • 1 blink = SNR 10-19
  • 2 blinks = SNR 20-29
  • 3 blinks = SNR 30-39
  • 4 blinks = SNR 40-49
  • 5 blinks = SNR 50-59
  • 6 blinks = SNR 60 > Excellent signal
#!/bin/sh
###############################################
#----Created by MOJSO-----Script version 2----#
###############################################
#         SIGNAL STRENGTH                         
# 0 blink   =  SNR  < 9  No signal or very weak     
# 1 blink   =  SNR 10-19                           
# 2 blinks  =  SNR 20-29                           
# 3 blinks  =  SNR 30-39                      
# 4 blinks  =  SNR 40-49                 
# 5 blinks  =  SNR 50-59                 
# 6 blinks  =  SNR 60 >   Excellent signal 
###############################################
while sleep 3; do
BLACK=`gpio enable 3 ; gpio enable 2`
S=`wl rssi` #(put mac adress if in AP mod example: S=`wl rssi 00:11:22:33:44:55` )
N=`wl noise`

SC=`expr $S - $N` 
RSC=`expr $SC / 10`

if  [ $RSC -eq 0 ]; then
gpio enable 3 ; gpio enable 2 ;

elif  [ $RSC -eq 1 ]; then
   gpio enable 3 ; gpio disable 2 ;
usleep 500000
   gpio enable 3 ; gpio enable 2 ;

   elif  [ $RSC -eq 2 ]; then
   gpio enable 3 ; gpio disable 2 ;
usleep 500000
   gpio enable 3 ; gpio enable 2 ;
 usleep 500000
   gpio enable 3 ; gpio disable 2 ;
usleep 500000
   gpio enable 3 ; gpio enable 2 ;

   elif  [ $RSC -eq 3 ]; then
    gpio enable 3 ; gpio disable 2 ;
usleep 250000
   gpio enable 3 ; gpio enable 2 ;
   usleep 250000
   gpio enable 3 ;  gpio disable 2 ;
usleep 250000
   gpio enable 3 ; gpio enable 2 ;
   usleep 250000
   gpio enable 3 ; gpio disable 2 ;
usleep 250000
   gpio enable 3 ; gpio enable 2 ;
   
   elif  [ $RSC -eq 4 ]; then
    gpio disable 3 ; gpio enable 2 ;
usleep 250000
   gpio enable 3 ; gpio enable 2 ;
   usleep 250000
   gpio disable 3 ; gpio enable 2 ;
usleep 250000
   gpio enable 3 ; gpio enable 2 ;
   usleep 250000
   gpio disable 3 ; gpio enable 2 ;
usleep 250000
   gpio enable 3 ; gpio enable 2 ;
   usleep 250000
   gpio disable 3 ; gpio enable 2 ;
usleep 250000
   gpio enable 3 ; gpio enable 2 ;
   
   elif  [ $RSC -eq 5 ]; then
   gpio disable 3 ; gpio enable 2 ;
usleep 250000
   gpio enable 3 ; gpio enable 2 ;
   usleep 250000
   gpio disable 3 ; gpio enable 2 ;
usleep 250000
   gpio enable 3 ; gpio enable 2 ;
   usleep 250000
   gpio disable 3 ; gpio enable 2 ;
usleep 250000
   gpio enable 3 ; gpio enable 2 ;
   usleep 250000
   gpio disable 3 ; gpio enable 2 ;
usleep 250000
   gpio enable 3 ; gpio enable 2 ;
   usleep 250000
   gpio disable 3 ; gpio enable 2 ;
usleep 250000
   gpio enable 3 ; gpio enable 2 ;
   
   elif  [ $RSC -ge 6 ]; then
   gpio disable 3 ; gpio enable 2 ;  
usleep 250000
   gpio enable 3 ; gpio enable 2 ;   
   usleep 250000
   gpio enable 3 ; gpio disable 2 ;  
usleep 250000
   gpio enable 3 ; gpio enable 2 ;   
   usleep 250000
   gpio disable 3 ; gpio enable 2 ; 
usleep 250000
   gpio enable 3 ; gpio enable 2 ;  
   usleep 250000
   gpio enable 3 ; gpio disable 2 ; 
usleep 250000
   gpio enable 3 ; gpio enable 2 ;  
    usleep 250000
   gpio disable 3 ; gpio enable 2 ; 
usleep 250000
   gpio enable 3 ; gpio enable 2 ; 
    usleep 250000
   gpio enable 3 ; gpio disable 2 ; 
usleep 250000
   gpio enable 3 ; gpio enable 2 ;  
 else  gpio enable 3 ;
 fi
 done