天天看點

LEDE/OpenWRT控制gpio-ledLed configurationLeds sectionHow to add Leds to this sectionLed triggersNoneTimerExamples

The Led configuration is located in system uci subsystem, and written in the /etc/config/system file.

The leds section contains settings that apply to non-default leds

(default leds are usually “power connected” led, “system alive” led, leds showing ethernet port activity and leds showing wifi radio status. Their settings are defined somewhere else, see development guides)

This is an example of leds on a tp-link router with usb port.

All LEDs are represented by entries in the sys filesystem. You can check which LEDs are available in the /sys/class/leds directory.

The name of an entry typically consists of the name of the hardware providing the LED (the router model), the color of the LED, and it’s designation (usually the label on the case).

Some LEDs can show different colors. In this case, you will find one entry per color.

The LED can be controlled by various events in the system, which is selected by the trigger option. Depending on the trigger, additional options must be specified. First of all, you need to know which triggers are available for a led, to do that simply look at the trigger file of that led. Example:

If we wanted to (temporarily) assign a default-on trigger to the led, we would write

<code>root@lede: echo "default-on" &amp;gt; /sys/class/leds/tp-link:green:qss/trigger</code>

You can confirm that you changed this by using cat again, you will see it has changed and the selected trigger is highlighted.

Now, this change will be lost on reboot, if you want to make a permanent change, you need to add the trigger in uci configuration.

If you have already a section in uci configuration that shows the led you want to set up, you just need to add the trigger.

For example, if you want change the trigger assigned to tp-link:green:wlan into “default-on” and you already have a block of options for it like this when you write uci show system | grep “system.led” (you can have more or less, it may also not have a trigger already assigned).

then you can write

If you don't have any configuration for it, you can add it and the trigger by editing the following example text (that sets wps led as “default-on” and then copy-pasting it whole in the terminal window.

Now we explain in detail what each trigger does.

The LED is always in default state. Unlisted LED are default OFF, so this is only useful to declare a LED to be always ON.

LEDE/OpenWRT控制gpio-ledLed configurationLeds sectionHow to add Leds to this sectionLed triggersNoneTimerExamples

The LED blinks with the configured on/off frequency.

If not installed already, install it with:

<code>root@lede:/# opkg install kmod-ledtrig-timer</code>

LEDE/OpenWRT控制gpio-ledLed configurationLeds sectionHow to add Leds to this sectionLed triggersNoneTimerExamples

Default-on

The LED is ON. Deprecated, use default=1 trigger=none instead. If not installed already, install it with:

<code>root@lede:/# opkg install kmod-ledtrig-default-on</code> 

LEDE/OpenWRT控制gpio-ledLed configurationLeds sectionHow to add Leds to this sectionLed triggersNoneTimerExamples

Heartbeat

The LED flashes to simulate actual heart beat thump-thump-pause. The frequency is in direct proportion to 1-minute average CPU load. If not installed already, install it with:

<code>root@lede:/# opkg install kmod-ledtrig-heartbeat</code>

LEDE/OpenWRT控制gpio-ledLed configurationLeds sectionHow to add Leds to this sectionLed triggersNoneTimerExamples

Flash Writes

The LED flashes as data is written to flash memory.

LEDE/OpenWRT控制gpio-ledLed configurationLeds sectionHow to add Leds to this sectionLed triggersNoneTimerExamples

Network Activity

The LED flashes with link status and/or send and receive activity on the configured interface. If not installed already, install it with:

<code>root@lede:/# opkg install kmod-ledtrig-netdev</code>

LEDE/OpenWRT控制gpio-ledLed configurationLeds sectionHow to add Leds to this sectionLed triggersNoneTimerExamples

WiFi Activity triggers

The LED flashes on events triggered in physical interface, rather than in software network interface. Besides phy triggers have more events, it also provides possibility of static LED setup in case you want to monitor your 2.4 GHz radio (phy0 usually) and 5 GHz radio (phy1 usually) separately. netdev can’t guarantee this distinguishing since wlan0 may be referring to 2.4 GHz or 5 GHz radio based on current network setup.

LEDE/OpenWRT控制gpio-ledLed configurationLeds sectionHow to add Leds to this sectionLed triggersNoneTimerExamples

phy0rx - flashes on reception.

phy0tx - flashes on transmission.

phy0assoc - flashes on client association.

phy0radio - (unknown, this option did nothing on my tl-wr1043nd)

phy0tpt - flashes slowly and steadily on network activity.in comparison to energetic flashes of tx and rx modes

USB Device

The LED turns ON if USB device is connected. If not installed already, install it with:

<code>root@lede:/# opkg install kmod-ledtrig-usbdev</code>

LEDE/OpenWRT控制gpio-ledLed configurationLeds sectionHow to add Leds to this sectionLed triggersNoneTimerExamples

To find out device name use logread to search for it or list /sys/bus/usb/devices (for this example, there would be /sys/bus/usb/devices/1-1 device).

Morse Code

The LED signals a message using Morse code. If not installed already, install it with:

<code>root@lede:/# opkg install kmod-ledtrig-morse</code>

LEDE/OpenWRT控制gpio-ledLed configurationLeds sectionHow to add Leds to this sectionLed triggersNoneTimerExamples

GPIO

Allows LEDs to be controlled by gpio events. If not installed already, install it with:

<code>root@lede:/# opkg install kmod-ledtrig-gpio</code>

LEDE/OpenWRT控制gpio-ledLed configurationLeds sectionHow to add Leds to this sectionLed triggersNoneTimerExamples

Net filter

Flash LEDs when a particular packets passing through your machine. If not installed already, install it with:

<code>root@lede:/# opkg install kmod-ipt-led</code>

According to this, the package was named kmod-ledtrig-netfilter in older versions

For example to create an LED trigger for incoming SSH traffic:

<code>root@lede:/# iptables -A INPUT -p tcp --dport 22 -j LED --led-trigger-id ssh --led-delay 1000</code>

Then attach the new trigger to an LED on your system:

<code>root@lede:/# echo netfilter-ssh &amp;gt; /sys/class/leds/&amp;lt;ledname&amp;gt;/trigger</code>

LEDE/OpenWRT控制gpio-ledLed configurationLeds sectionHow to add Leds to this sectionLed triggersNoneTimerExamples

Please remember to change the sysfs option to LEDs that are actually present on your router.

This can be done easily through LuCI. Following examples are from /etc/config/system file:

Heartbeat led

WLAN led

3G led

This led lights up when an USB-dongle properly registers with the 3G/EDGE/GPRS network.

Timer led - 500ms ON, 2000ms OFF

版權聲明:原創作品,如需轉載,請注明出處。否則将追究法律責任

本文轉自 Linux_woniu 51CTO部落格,原文連結:http://blog.51cto.com/linuxcgi/2046604

繼續閱讀