Script to switch on a led when internet connection is availa

sezione dedicata ai sistemi operativi alternativi Open Source

Script to switch on a led when internet connection is availa

Messaggio da leggereda root » 22/01/2018, 12:25

In this specific case I used a green led to indicate that internet connection is available and a red one to warn when internet connection is not available (Router ADB P.DG A4001N1), but if you have just one led, you can set a fixed light when internet is available and a flash light when it is not available.

let's create the script:

nano /root/internet-check.sh

while [ true ]; do
/usr/bin/wget -q --spider http://google.com > /dev/null
if [[ $? -eq 0 ]]; then
/bin/echo "0" > /sys/devices/gpio-leds/leds/A4001N1:red:inet/brightness
/bin/echo "1" > /sys/devices/gpio-leds/leds/A4001N1:green:inet/brightness
else
/bin/echo "0" > /sys/devices/gpio-leds/leds/A4001N1:green:inet/brightness
/bin/echo "1" > /sys/devices/gpio-leds/leds/A4001N1:red:inet/brightness
fi
sleep 15
done


note: change "/sys/devices/gpio-leds/leds/A4001N1:green:inet" with the path for your router.


then give the right permissions to the above script:

chmod 755 /root/internet-check.sh


to launch the script at the startup put the following line right before the "exit 0" line in the /etc/rc.local" file

/bin/sh /root/internet-check.sh &
Maurizio
Avatar utente
root
Amministratore
 
Messaggi: 365
Iscritto il: 10/04/2012, 10:55
Località: Turin

Torna a OpenWRT

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite