CLI control of LED on mt300n

How can I flash the LED on the openwrt routers from command line NOT Luci?
For example, I’d like to flash only the red LED at different speeds then turn it back off on the 300N device. Can the configurable LED be different colors? If so, I’d prefer to use that one.

Running custom firmware; CHAOS CALMER (Chaos Calmer, r47065)

I have tried all of the following with no change what so ever on the router (mt300n).

find /sys/devices/platform/alarmtimer/subsystem/devices/gpio-leds/ ! -path ‘usbpow’ -name brightness -exec sh -c ‘echo 0 > {}’ ;

find /sys/devices/platform/alarmtimer/subsystem/devices/gpio-leds/ ! -path ‘usbpow’ -name brightness -exec sh -c ‘echo 1 > {}’ ;

find /sys/devices/platform/alarmtimer/subsystem/devices/gpio-leds/ ! -path ‘usbpow’ -name brightness -exec sh -c ‘echo 255 > {}’ ; && /etc/init.d/led start

find /sys/devices/platform/alarmtimer/subsystem/devices/gpio-leds/ ! -path ‘usbpow’ -name brightness -exec sh -c ‘echo 1 > {}’ ; && /etc/init.d/led start

find /sys/devices/platform/alarmtimer/subsystem/devices/gpio-leds/ ! -path ‘usbpow’ -name brightness -exec sh -c ‘echo 1 > {}’ ;

find /sys/devices/platform/alarmtimer/subsystem/devices/gpio-leds
! -path ‘usbpow’ -name brightness -exec sh -c ‘echo 1 > {}’ ;

find /sys/devices/platform/alarmtimer/subsystem/devices/gpio-leds ! -path ‘usbpow’ -name brightness -exec sh -c ‘echo 0 > {}’ ;

find /sys/devices/platform/alarmtimer/subsystem/devices/gpio-leds ! -path ‘lan’ -name brightness -exec sh -c ‘echo 1 > {}’ ;

The testing I’d like to achieve is flashing the center LED at different speeds then returning it back to being turned off.

So on your device do

ls /sys/class/leds/

To get a list of the LEDs you can update.
Then to set an LED, you do

echo 1 > /sys/class/leds/<LED_NAME>/brightness

For example for the Mifi i can do:

echo 1 > /sys/class/leds/gl-mifi:green:lan/brightness

That will set the LAN LED to on, and use echo 0 to turn it off.

Sorry, I updated my text before you responded.

I see the following;

lrwxrwxrwx 1 root root 0 Aug 11 19:26 rt2800soc-phy0::assoc → …/…/devices/10180000.wmac/leds/rt2800soc-phy0::assoc
lrwxrwxrwx 1 root root 0 Aug 11 19:26 rt2800soc-phy0::quality → …/…/devices/10180000.wmac/leds/rt2800soc-phy0::quality
lrwxrwxrwx 1 root root 0 Aug 11 19:26 rt2800soc-phy0::radio → …/…/devices/10180000.wmac/leds/rt2800soc-phy0::radio

I am wanting to control the middle LED for example, which if I understand, is a configurable one. No idea if I can also change it’s color.

Is this what I am wanting to control then?

phy0::quality

No changes.

echo 0 > /sys/class/leds/rt2800soc-phy0::quality/brightness
echo 1 > /sys/class/leds/rt2800soc-phy0::quality/brightness
echo 0 > /sys/class/leds/rt2800soc-phy0::assoc/brightness
echo 1 > /sys/class/leds/rt2800soc-phy0::assoc/brightness

Hmmm. If you do

uci export system

and then see what the names of the LEDs are, use those names in the commands above.

You can also use the LED names that Luci has in the LED config…

See if that works for you? :slight_smile:

There is only one reference to LED

config led ‘led_wifi_led’
option name ‘wifi’
option sysfs ‘gl-mt300n:wlan’
option dev ‘wlan0’
option trigger ‘netdev’
option mode ‘link tx rx’

I also tried;

echo 64 >/sys/class/leds/rt2800soc-phy0::assoc/max_brightness

-ash: can’t create /sys/class/leds/rt2800soc-phy0::assoc/max_brightness: Permission denied

Not sure if I am getting closer or not.

echo 1 > /sys/class/leds/gl-mt300n:wlan/brightness

Does nothing? :frowning:

Nope

echo 1 > /sys/class/leds/gl-mt300n:wlan/brightness
-ash: can’t create /sys/class/leds/gl-mt300n:wlan/brightness: nonexistent directory

I’ve even tried

echo 0 >/sys/class/leds/rt2800soc-phy0::assoc/subsystem/rt2800soc-phy0::assoc/brightness

/etc/init.d/led restart

echo 1 >/sys/class/leds/rt2800soc-phy0::assoc/subsystem/rt2800soc-phy0::assoc/brightness

/etc/init.d/led restart

Hmm, then you will have to wait until tomorrow when the devs can help.

Let me call them for you:

@alzhao @kyson-lok

ls -la /sys/class/leds/

lrwxrwxrwx 1 root root 0 Aug 11 19:26 rt2800soc-phy0::assoc → …/…/devices/10180000.wmac/leds/rt2800soc-phy0::assoc
lrwxrwxrwx 1 root root 0 Aug 11 19:26 rt2800soc-phy0::quality → …/…/devices/10180000.wmac/leds/rt2800soc-phy0::quality
lrwxrwxrwx 1 root root 0 Aug 11 19:26 rt2800soc-phy0::radio → …/…/devices/10180000.wmac/leds/rt2800soc-phy0::radio

Thanks for your help. I’ll keep looking in the meantime.

I also found this information in another post;

alzhao Apr '16
The LAN LED is fixed as POWER in hardware. So it is always on.
The WAN LED and WiFi leds can be controlled.

Therefore, tested using another LED (If I am understanding the three LEDs)
echo 255 >/sys/class/leds/rt2800soc-phy0::assoc/subsystem/rt2800soc-phy0::quality/brightness

No change.

Did you changed the firmware to a customized firmware? These LEDs names seems not bind to the physical LEDs.

There should only be three LEDs.
gl-mt300n:wlan/
gl-mt300n:lan
gl-mt300n:wan

Nope, the color of the led isn’t configurable. You only can turn it on or turn it off. Those directory are located in /sys/class/led.

alzhao, the firmware was updated yes.
I posted the version in the first msg. If I recall, the /etc/config/system file was changed a little from factory. In the original, there is only mention of one.
config led ‘led_wifi_led’
Do I just need to put the old one back in and rebuild?
What else could I provide to help?

kyson-lok, I thought one of the LEDs is red which is the one I wanted to use.

You may try the latest openwrt. I think openwrt standard the LEDs names to gl-mt300n:green:wan etc.

LED names is a little mess so if you have your own firmware.

So try latest openwrt or GL stock firmware for LED configurations. Cannot change LED color.

Don’t use usbpow because it is not LED. It is used to control the power of USB port.

ok but I am using my own /files directory. What must I leave that is factory in order to have the LEDs working as they should be? Not sure what I’ve removed that would cause this.

For future reference since no one seemed to have the correct answer, all I needed to do was to install kmod-leds-gpio kmod-ledtrig-usbdev in my build. Not sure if I need both but one or both allow me to control the LED.

Also, yes, there is a RED led, it is the WLAN.

Now this works.
echo 1 > /sys/class/leds/gl-mt300n:wlan/brightness
echo 0 > /sys/class/leds/gl-mt300n:wlan/brightness

With the above, I can turn it on and off but how can i make it flash also for example? Any other controls?

To make it flash you add a delay between on and off :stuck_out_tongue:

I’m not sure about that. I’ve read that there is something else, using the kmod-ledtrig-timer if I understand correctly. However, I cannot find a way to send the LED a command to do anything but go on and off.

kmod-ledtrig-gpio
kmod-ledtrig-heartbeat
kmod-ledtrig-morse
kmod-ledtrig-oneshot
kmod-ledtrig-timer
kmod-ledtrig-transient

are some interesting packages you can try.

Morse and heartbeat are basically just turning the LED’s on and off and predefined intervals, which you can do using sleep in a bash script with the commands above for on and off so…

You can either write your own bash script to do what you want, or make a c++ program and compile it for more advanced things.

This basically what the GL UI is doing for the reset blinking and other blinking apart from the automatic from OpenWRT (which is probably also just calling the LED’s to be on or off).