Is it possible to test if specific led or all are enabled?

I want to program specific behaviour of router and daemons based on leds being on or off. Is that possible to read state of LEDs?

Just a quick thought: I don‘t know a specific answear to your question, but those LEDS are on or off for a reason. You could test the status of the underlying device/mechanism.

You can inspect /etc/init.d/setup-led script , resp folder /sys/class/leds/ where you can find sub-folder for each led(family of leds) with several files related to values/parameters coming from uci config file.
“brightness” file indicate if correspond led is off or “shining”
Plus maybe /usr/sbin/sfpswitch.py can give some ideas what-where …

Thanks @Maxmilian_Picmaus that’s close but doesn’t work for me all the times.

Wan led was enabled all the time - brighntess is 0 probably when it’s bliking.

root@turris:~# cat /sys/class/leds/omnia-led:wan/brightness
255
root@turris:~# cat /sys/class/leds/omnia-led:wan/brightness
255
root@turris:~# cat /sys/class/leds/omnia-led:wan/brightness
0
root@turris:~# cat /sys/class/leds/omnia-led:wan/brightness
0

I tried with power and usr1, I typed rainbow usr1 enable, power and usr1 were on, I pressed the button a few times to turn the LEDs off, but it’s still showing their brighntess as full:

root@turris:~# cat /sys/class/leds/omnia-led:user1/brightness
255
root@turris:~# cat /sys/class/leds/omnia-led:user1/brightness
255

The power LED is detected as always off, even when it’s on

root@turris:~# cat /sys/class/leds/omnia-led:power/brightness
0
root@turris:~# cat /sys/class/leds/omnia-led:power/brightness
0

But what I found is that /sys/class/leds/omnia-led\:wan/device/global_brightness is quite(?) reliable and is always 0 when LEDs were disabled manually, and non-zero when shining. I’ll do more automated testing later. Thanks!

I also found that there is only 0 or 255 in “brightness” file (as real intensity is handled via different file (i think)). Anyway “color” file has RGB triplet values, so that might be it.
There is “omnia-led-color” package done by @dpdrown LED color based on bandwidth usage , so there are some other infos, links around.
Cheers :slight_smile:

I know this script, I use it :slight_smile:

Basically, what I want is to enabled/disable network-wide OpenVPN client based on status of lights. Thanks for help, I’ll share my config later.

1 Like

A script I wrote to control VPN client on router using LED lights

#!/bin/bash
while true; do
        if [ `ps | grep "/usr/sbin/openvpn" | wc -l` -eq 2 ]; then
                if [ $(cat /sys/class/leds/omnia-led\:power/device/global_brightness) == "0" ]; then
                        /etc/init.d/openvpn stop
                fi
        fi

        if [ $(cat /sys/class/leds/omnia-led\:power/device/global_brightness) != "0" ]; then
                if [ `ps | grep "/usr/sbin/openvpn" | wc -l` -eq 1 ]; then
                        /etc/init.d/openvpn start
                fi
        fi

        sleep 10;
done;
1 Like