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
I know this script, I use it
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.
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;