Change LED Lights Depending If WAN Connection Is Receiving Data

Hi

I have a Linksys WRT1900ACS aka Shelby (https://openwrt.org/toh/hwdata/linksys/linksys_wrt1900acs_v1)

and I would like to configure the WAN light behaviour exactly like the stock firmware whereby if there is no WAN connection the WAN light is a solid amber, else the WAN light goes to white with blinking when packets of data are moving.

I have tried playing around with the https://192.168.1.1/cgi-bin/luci/admin/system/leds page but I can't get them to behave when the conditions change.

It is possible to do via LuCI or is there another way? I have read another post on this forum regarding making a script but I wouldn't know where to start. All I know is the first line would be to check the WAN connection and set the light to amber if the connection isn't active. If it is active set WAN light to white.

Any help appreciated

Will

This is kinda vague... more information about what you tried would facilitate better help.

And yes, on most devices/modern releases ... basic options can be modified via LUCI. Specifically... the TRIGGER option is key.

Here's the /etc/config/system

config led 'led_wan'
	option name 'WAN_OFF'
	option sysfs 'pca963x:shelby:amber:wan'
	option trigger 'netdev'
	option dev 'eth1.2'
	option default '0'

config led 'led_usb1'
	option name 'USB 1'
	option sysfs 'pca963x:shelby:white:usb2'
	option trigger 'usbport'
	option default '0'
	list port 'usb1-port1'

config led 'led_usb2'
	option name 'USB 2'
	option sysfs 'pca963x:shelby:white:usb3_1'
	option trigger 'usbport'
	list port 'usb2-port1'
	list port 'usb3-port1'
	option default '0'

config led 'led_usb2_ss'
	option name 'USB 2 SS'
	option sysfs 'pca963x:shelby:white:usb3_2'
	option trigger 'usbport'
	option default '0'
	list port 'usb3-port1'

config led
	option name 'WAN_ON'
	option sysfs 'pca963x:shelby:white:wan'
	option default '0'
	option trigger 'netdev'
	option mode 'link'
	option dev 'eth1.2'

I made a WAN_OFF and set the LED for WAN to amber using the WAN connect eth1.2 (WAN interface).

The stock firmware uses a script to probe for an actual connection to the Internet (e.g.by pinging the manufacturer's site.) That functionality is not included in OpenWRT by default but you could look at modifying something like watchcat to turn LEDs on and off based on ping success or failure.

try adding

config led 'led_wanamber'
        option sysfs 'pca963x:shelby:amber:wan'
        option trigger 'netdev'
	    option dev 'eth1.2'
	    option default '1'

config led 'led_wanwhite'
    option sysfs 'pca963x:shelby:white:wan'
    option mode 'link tx rx'
    option trigger 'netdev'
	option mode 'link'
	option dev 'eth1.2'

Cheers for the reply.

I placed the above configuration into the 'system' file and now I have the orange and amber lights both on at the same time.

This is the other post I was referring to > Help for LED Configuration

/etc/rc.local
I have modified the '/etc/rc.local' to suit my router

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

#Check WAN Connection
while :
	do
	
	Status=$(ping -q -c 20 -W 1 208.67.222.222 > /dev/null 2>&1 && echo "ok" || echo "FAIL")
	
	if [ "$Status" = "ok" ]; then

	echo 255 > /sys/class/leds/pca963x:shelby:amber:wan/brightness
	echo 0 > /sys/class/leds/pca963x:shelby:white:wan/brightness

	else 

	echo 255 > /sys/class/leds/pca963x:shelby:white:wan/brightness
	echo 0 > /sys/class/leds/pca963x:shelby:amber:wan/brightness


	fi
	
	sleep 10
done

exit 0

I have also added in both lights to they function as normal. The script above simply controls the brightness of each lights so once is only one is on at one time.

/etc/config/system

config led
	option default '0'
	option sysfs 'pca963x:shelby:white:wan'
	option trigger 'netdev'
	option dev 'eth1.2'
	option mode 'link tx rx'
	option name 'WAN_ON'

config led
	option default '0'
	option name 'WAN_OFF'
	option sysfs 'pca963x:shelby:amber:wan'
	option trigger 'netdev'
	option dev 'eth1.2'

However, I would like to know how to put a loop on this code if the WAN connection does go down. Any ideas?

I think the following code could perform what you want.

But then rc.local will never exit/terminate , so it would be better to create a file
for example lights.sh with #!/bin/bash in first line.

And call it from rc.local via /path/to/your/lights.sh &

The & will start the script in Background and rc.local will continue and exit.

while true ; do
	Status=$(ping -q -c 20 -W 1 208.67.222.222 > /dev/null 2>&1 && echo "ok" || echo "FAIL")
	
	if [ "$Status" = "ok" ]; then

	echo 255 > /sys/class/leds/pca963x:shelby:amber:wan/brightness
	echo 0 > /sys/class/leds/pca963x:shelby:white:wan/brightness

	else 

	echo 255 > /sys/class/leds/pca963x:shelby:white:wan/brightness
	echo 0 > /sys/class/leds/pca963x:shelby:amber:wan/brightness


	fi
	
	sleep 10
done
1 Like

Is there anyway of testing the lights via SSH without having to reboot the router for the script to run? I tried

echo 255 > /sys/class/leds/pca963x:shelby:amber:wan/brightness

but it gave me permission denied. I have even tried rebooting the router but I have a feeling the script isn't running. I'll check logs and post update on here when I'm back home.

I think the script run with the same permission as you when you ssh.
So if you can't change the attribute the script should also not change the attribute.

Maybe the device only allow 1 time a change.

May you add a line before sleep
date >> /tmp/testfile

Then the current time will be added to testfile on each loop