Controlling leds status in OpenWrt
This is a quick how-to about controlling the status of the leds from userspace in OpenWrt.
If you have installed OpenWrt on your router the leds should be controlled by the
leds_gpio kernel module. Every led will have an entry in sysfs under
To manually control a led you should first set the
trigger file to
none, otherwise the led will be controlled for its original function, i.e. ethernet activity indicator:
echo none > trigger
Then you can set the value by writing to the
brightness file. This file represents the brightness level which should range from 0 to the value contained in the
max_brightness file. However, in most cases there will not be hardware brightness control for the leds (like with GPIO), so 0 will turn OFF the led and any non-zero value will turn it ON:
echo 0 > brightness
echo 1 > brightness
An example on my TP-Link MR3020:
root@OpenWrt:~# cd /sys/class/leds/tp-link\:green\:3g/
root@OpenWrt:/sys/devices/platform/leds-gpio/leds/tp-link:green:3g# echo none > trigger
root@OpenWrt:/sys/devices/platform/leds-gpio/leds/tp-link:green:3g# echo 1 > brightness
root@OpenWrt:/sys/devices/platform/leds-gpio/leds/tp-link:green:3g# echo 0 > brightness
Note: if you don’t already know, those files are not actual files in flash, they’re virtual files that act as an interface from userland to kernel.
Note 2: if you want more control on the GPIO lines you may prefer to unload the
leds_gpio module (with
#rmmod leds_gpio) and directly control the GPIO and/or configure a bus on some lines, like i2c or spi.