Script that flashes power red LED with frequency as a function of free space in Flash ROM

I have developed a simple script that indicates the free space at flash ROM on my router by incrementing the red LED power light speed.
It is designed for a Buffalo WBMR-HP-G300H, but seems easy to adapt to any other device.

Here you have, in case someone could consider it useful:

$ cat RedPowerLED-func-of-Flash-free-space.sh
#!/usr/bin/env bash
# Adapta el LED Power Rojo a parpadeo con frecuencia función del espacio libre en Flash ROM.
# 100% libre --> 5.000 milisegundos entre parpadeos.
# 50% libre --> 2.500 milisegundos entre parpadeos.
# 0% libre --> 0 milisegundos entre parpadeos (luz roja fija).
### Requisitos:
## Configuración base en "/etc/config/system" :
#config led 'saturacionflash'
#        option default '0'
#        option name 'saturacionflash'
#        option sysfs 'wbmr:red:power'
#        option trigger 'timer'
#        option default '0'
#        option delayon '50'
#        option delayoff '5000'
version="v0.01Alfa - 2020-06-13"
PorcentajeOcupado="$( df -h | grep overlay | tail -n 1 | awk '{print $5}' | cut -d "%" -f 1 )"
PorcentajeLibre=$(( 100 - PorcentajeOcupado ))
MilisegundosEspera=$( expr $PorcentajeLibre \* 50 )
if [ $(cat /sys/devices/platform/gpio-leds/leds/wbmr:red:power/delay_off) -ne $MilisegundosEspera ]
then 
	echo $MilisegundosEspera > /sys/devices/platform/gpio-leds/leds/wbmr:red:power/delay_off
fi

The script is internally (variables and comments) in spanish, sorry. Feel free to translate and publish it.

Examples:

100% free ROM --> 5.000 ms between blinks.
50% free ROM --> 2.500 ms between blinks.
0% free ROM --> 0 ms between blinks (fixed red).

... etc

I call it via CRON:

# crontab -l
* * * * * RedPowerLED-func-of-Flash-free-space.sh
2 Likes

very usefull :grinning: