Last active
December 11, 2015 20:28
-
-
Save ssebastianj/4655184 to your computer and use it in GitHub Desktop.
Beginning with Ash (Busybox). This is a "Quick & Dirty" (yep, I'm "learning") script for blinking QSS LED when it reaches every "min" value on "/etc/config/system" file.
Firmware: OpenWRT | Gargoyle.
Hardware: TP-LINK WR1043ND (with little changes it can be ported to another routers).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
led_off() { | |
echo 0 > /sys/class/leds/tp-link:green:qss/brightness | |
return $? | |
} | |
led_on() { | |
echo 1 > /sys/class/leds/tp-link:green:qss/brightness | |
return $? | |
} | |
remove_pid_file() { | |
rm -f $PID_FILE | |
return $? | |
} | |
# Interceptar las señales | |
trap 'led_off; remove_pid_file; exit $?' SIGHUP SIGINT SIGQUIT SIGTERM | |
# Guardar PID del proceso en un archivo temporal | |
PID_FILE="/tmp/run/blinkoption.pid" | |
echo $$ > $PID_FILE | |
MINS='' | |
# Obtener el nombre de los botones asignados al botón QSS (WPS) del router | |
BUTTONS=$(uci -q show system | grep -ioE '\w+.button=wps' | cut -d. -f1) | |
for button in $BUTTONS | |
do | |
MIN=$(uci -q get system.$button.min) | |
MINS="$MINS $MIN" # Guardar mínimo en lista de mínimos | |
done | |
# Apagar LED QSS antes de comenzar a destellar | |
led_off | |
COUNT=0 | |
FLAG=0 | |
while [[ $COUNT -le 90 ]]; | |
do | |
for min in $MINS | |
do | |
if [[ "$COUNT" == "$min" ]]; then | |
led_on | |
break | |
fi | |
done | |
sleep 1 | |
led_off | |
COUNT=`expr $COUNT + 1` | |
done | |
# Apagar LED QSS al finalizar | |
led_off | |
# Eliminar archivo temporal de PID | |
remove_pid_file | |
exit $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config button 'blink_option' | |
option button 'wps' | |
option action 'pressed' | |
option handler '/sbin/blink_options.sh &' | |
option min '0' | |
option max '90' | |
config button 'stop_blinking' | |
option button 'wps' | |
option action 'released' | |
option handler '/sbin/stop_blinking.sh &' | |
option min '0' | |
option max '90' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
PID_FILE="/tmp/run/blinkoption.pid" | |
if [ -f $PID_FILE ]; then | |
PID=$(cat $PID_FILE) | |
echo $PID | |
kill $PID | |
rm -f $PID_FILE | |
fi | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment