Check connectivity and switch on/off a LED (GL-AR150)

Written by pmd - - no comments

Shell script that will check if there is connectivity to a defined website every 60 seconds and switch ON/OFF the led :

  • /usr/bin/WANLED :
#!/bin/sh
while [ true ]; do
        /usr/bin/wget -q --tries=2 --spider http://google.com
        if [ $? -eq 0 ]; then
                #echo "Connected ! LED OFF."
                echo "none" >  /sys/class/leds/gl-ar150:orange:wlan/trigger
        else
                #echo "Not connected ! LED ON."
                echo "default-on" >  /sys/class/leds/gl-ar150:orange:wlan/trigger
        fi
        sleep 60
done

 

Schell script to autostart the above script :

  • /etc/init.d/WANLED :
#!/bin/sh /etc/rc.common

START=99
STOP=1

start(){
        /usr/bin/WANLED &
}

stop(){
        killall -9 WANLED
}

Now let's make these script executable and started at startup:

# chmod +x /usr/bin/WANLED
# chmod +x /etc/init.d/WANLED
# /etc/init.d/WANLED enable
# /etc/init.d/WANLED start

Now the orange LED should be ON when there is no connectivity to Google.

FYI OpenWRT in use was : OpenWrt 19.07.2, r10947-65030d81f3

Source: LED, Start script at startup, LED on when Internet is available

Write a comment

What is the last letter of the word guqth?