[Solved] Changing WAN LED light to amber depending on network status

[ Sidenote: Oddly, OpenWrt LuCI UI shows a state (LED Name) as "green:wan", but actually it's white in the router. But I'll describe everything based on what OpenWrt shows. ]

When I was in stock, the WAN LED light worked like:

a) Wire connected and internet working - green
b) Wire connected but internet not working - amber
c) Wire not connected - (off)

By wire I mean the wire that's coming from outside from ISP to the router. I connect with PPPoE if that's important.

By default LED lights blink like crazy, so I deleted default configs and created my own rules to mimic default behavior. The trouble is with WAN LED. With some fiddling around I was able to set it up like:

a) Wire connected and internet working - green
b) Wire connected but internet not working - (off) [but I want it to show amber!]
c) Wire not connected - (off)

So far I have an entry for WAN LED in System - LED configuration which has:

LED Name: green:wan
Trigger: Network device activity
Device: eth1
Trigger mode: Link On

I can't figure out how to show amber for condition (b) in OpenWrt. Please help!

Model:	TP-Link TL-WR841HP v3
Architecture:	Qualcomm Atheros QCA9533 ver 2 rev 0
Target Platform:	ath79/generic
Firmware Version:	OpenWrt SNAPSHOT r18944-aae7af4219 / LuCI Master git-22.046.84457-2178444
Kernel Version:	5.10.100

Set the amber one.

I changed it to amber, now it shows amber when internet is available.

Did you mean create a new rule for amber? If so, please suggest which options to use. I've tried many ways before but couldn't achieve what I want.

It is going to be complicated, as you need first to set a condition under which the internet is not available. For example ping to google fails, or you cannot resolve an address. Then based on that condition you can send the uci command to change the colour of the led and restart the system service. Also after the internet is back you need to revert it.

1 Like

I tried the following and it seems to be working so far.

I SSHed into router and saved the following as /etc/hotplug.d/iface/30-wanled:

#!/bin/sh
#/etc/hotplug.d/iface/30-wanled
#written for TL-WR841HP v3 LED names in mind, may need change for other devices

[ "$INTERFACE" = wan ] || exit 0
if [ "$ACTION" = ifup ] ; then
  # WAN interface went up
  echo "none" > /sys/class/leds/amber:wan/trigger
  echo "default-on" > /sys/class/leds/green:wan/trigger
fi
if [ "$ACTION" = ifdown ] ; then
  # WAN interface went down
  echo "none" > /sys/class/leds/green:wan/trigger
  echo "default-on" > /sys/class/leds/amber:wan/trigger
fi
if [ "$ACTION" = free ] ; then
  # WAN wire disconnected physically
  echo "none" > /sys/class/leds/green:wan/trigger
  echo "none" > /sys/class/leds/amber:wan/trigger
fi
exit 0

If you find any issues with the script, please let me know. This is my first time trying this. Thanks to @takimata for the extremely useful post with an example script. The post says if connecting with PPPoE (which I am), it doesn't need to ping anywhere, which is also convenient.

As much as I looked around, LuCI UI alone might not be able achieve this. As @takimata said:

Unfortunately it's not possible to have an LED light up when the interface is down through the LED configuration. (Oh how nice would an "invert LED" flag be.)

It would be great if it could be done with UI, but the way everything is right now, this script is necessary. Oh and I kept the LED rule intact as described in first post, but something tells me it might not be necessary since the script takes care of the 3 conditions by itself. I'll try later without the rule to see if that works.

For testing:

  • I stopped the wan interface and it shows amber.
  • When I restarted wan from LuCI, it turned to "green" again.
  • I disconnected the WAN cable physically and the LED went off as expected.

So far so good.

For other routers, the led names (green:wan, amber:wan) might be different. ls /sys/class/leds/ will list them and cat /sys/class/leds/<led name>/trigger will show possible values.

Useful sources:

3 Likes

Oh and I kept the LED rule intact as described in first post... I'll try later without the rule to see if that works.

When I deleted the LED rule and applied changes, the WAN LED turned off, even though internet was working.
So I rebooted the device and it seems to be working.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.