Tuesday, 20 October 2015 22:02

OpenWrt: Control LED manually

Written by

Control LED manually

Due to the limited GPIO availability on the wireless router, you may want use the router LED pin to provides a few more GPIOs. This describes how to use the LED pin on a wireless router as binary outputs. 


By default, all the LED is controlled for its original function, therefore you must set the trigger file (/sys/class/leds/LED_NAME/trigger) to none before you can manually control a LED. 

  • First, we need to check what LEDs are available
    ls -1 /sys/class/leds/
  • Example of output from my GL.iNet router:


    Where gl-connect:green:lan LED is controlled by lan activities and gl-connect:red:wlan LED is control by wlan activities.
  • You may want to know the LED trigger name before go to the next step, this is not require but is necessary if you want to set the LED to go back to its default function later.
    cat /sys/class/leds/gl-connect:red:wlan/trigger
  • Example below shows the trigger name is phy0tpt (with square bracket)
    none switch0 timer default-on netdev phy0rx phy0tx phy0assoc phy0radio [phy0tpt]
  •  Suppose we want to control the gl-connect:red:wlan LED manually, we can use the following command to disable its default function.
    echo none> /sys/class/leds/gl-connect:red:wlan/trigger
  • The LED can be turned on and off using the 'brightness' file,  set brightness to 0 will turn off the LED and any value greater than 0 will turn on the LED.
    echo 1 > /sys/class/leds/gl-connect:red:wlan/brightness #turn on LED
    echo 0 > /sys/class/leds/gl-connect:red:wlan/brightness #turn off LED
  •  You may want the LED to go back to its default function.
    echo phy0tpt> /sys/class/leds/gl-connect:red:wlan/trigger

Set the trigger file to none after router boots up

Save the following code to /etc/init.d/manualControlLED, this will disable the trigger for gl-connect:red:wlan LED.

  1. #!/bin/sh /etc/rc.common
  3. START=99
  4. STOP=15
  6. start() {
  7. echo none> /sys/class/leds/gl-connect:red:wlan/trigger
  8. }
  10. stop() {
  11. echo phy0tpt> /sys/class/leds/gl-connect:red:wlan/trigger
  12. }
  • Set file permission to 0755
    chmod 0755 /etc/init.d/manualControlLED
  • Disable trigger for LED, you can now control the LED manually.
    /etc/init.d/manualControlLED start
  • Go back to its default function.
    /etc/init.d/manualControlLED stop
  • Enable service autostart
    /etc/init.d/manualControlLED enable
  • Disable service autostart
    /etc/init.d/manualControlLED disable
Read 25457 times Last modified on Wednesday, 21 October 2015 20:37
Back to Top