[solved] Night LED timer for wifi router for OpenWrt

My feature request is same as the issue raised by a guy here :blush: , so can someone help :

as the comment to the issue above:

All components are there, LED config, and cron.

if you want more - the code is open-source so you can set-up a luci addon to wrap everything up just the may you want :slight_smile:

2 Likes

Just FYI - Depending on the device and particular LED, the lights may be controlled by hardware.

If they are software controlled, you can always configure a cron job.

In fact, a GitHub reply from @systemcrash also agrees:

All components are there, LED config, and cron.

1 Like

@maurer @lleachii Thank you, I understood what you explained but I am a beginner and dont know how to go forward, so how can I integrate this timer with openwrt ?

Your current setup please:

cat /etc/config/system
1 Like

Note: I have not tested any of this, since I don't own your particular device.

  1. Write this script and store in /root/leds_on:
#!/bin/sh
cd /sys/class/leds/green:lan
echo netdev > trigger
echo br-lan > device_name
echo 1 > link
echo 1 > tx
echo 1 > rx
cd /sys/class/leds/green:wan
echo netdev > trigger
echo wan > device_name
echo 1 > link
echo 1 > tx
echo 1 > rx
  1. Write this script and store in /root/leds_off:
#!/bin/sh
cd /sys/class/leds/green:lan
echo none > trigger
cd /sys/class/leds/green:wan
echo none > trigger
  1. Do chmod +x on both scripts.

  2. Verify that the scripts do what you want by directly invoking them in SSH.

  3. In the LuCI interface, go to System → Scheduled Tasks and enter your desired crontab entries. Look up "cron syntax" with your favorite search engine to learn more. For example, to turn on LEDs at 6:00 AM and turn off LEDs at 9:00 PM:

0 6 * * * /root/leds_on
0 21 * * * /root/leds_off

You can do the same thing with crontab -e if you know your way around vi.

5 Likes

ok, updating you after trying

Got this as unexpected after trying your mentioned path in script, i looked using Filezilla(sftp) and found that the path you mentioned is just a pointer to anothher path so i replaced with the real path as you can see in 2nd output but still same output, also using ssh terminal/Filezilla(sftp) i cant see/access/read anything above the root folder, so i had to install a package from luci gui named openssh-sftp-server which allowed me to read/edit folder hierarchy of openwrt firmware from Filezilla(sftp) but not from ssh terminal still :

root@openwrt:~# sh ./leds_off
: No such file or directory't cd to /sys/class/leds/green:lan
: No such file or directory't cd to /sys/class/leds/green:wan
root@openwrt:~# sh ./leds_off
./leds_off: cd: line 2: can't cd to /sys/devices/platform/leds/leds/green:la: No such file or directory
./leds_off: cd: line 4: can't cd to /sys/devices/platform/leds/leds/green:wa: No such file or directory
root@openwrt:~#

It's possible that /etc/config/system is misconfigured and the LED names in that file are wrong. Let's look what's actually inside the leds directory:

ls /sys/devices/platform/leds/leds

If this directory doesn't exist, then either:

  • You typed the path incorrecty
  • LEDs on the device are not controllable by software
  • The device tree is incorrect (fixing this requires rebuilding the firmware image)

This shouldn't matter, the shell will correctly follow symlinks.

1 Like

Got this using your command :

root@openwrt:~# ls /sys/devices/platform/leds/leds
amber:wan     green:lan     green:power   green:wan     green:wlan-2  green:wlan-5
root@openwrt:~#
1 Like

Your device has the right LED names in the right directories, and yet the script can't cd into those exact same directories? That's the kind of thing that makes me question my eyesight and my sanity.

Can you check for typos in the script? Do cat ./leds_on in the device's shell and check that the upload didn't somehow mangle the script.

Can you also double check the error message you've pasted in one of your prior posts? Did the shell really output "No such file or directory't cd to..."?

2 Likes

Output of cat ./leds_on :

PS C:\Users\user> ssh root@192.168.1.1
root@192.168.1.1's password:


BusyBox v1.36.1 (2023-11-14 13:38:11 UTC) built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 OpenWrt 23.05.2, r23630-842932a63d
 -----------------------------------------------------
root@openwrt:~# ls
leds_off  leds_on   trigger?
root@openwrt:~#  cat ./leds_on
#!/bin/sh
cd /sys/devices/platform/leds/leds/green:lan
echo netdev > trigger
echo br-lan > device_name
echo 1 > link
echo 1 > tx
echo 1 > rx
cd /sys/devices/platform/leds/leds/green:wan
echo netdev > trigger
echo wan > device_name
echo 1 > link
echo 1 > tx
echo 1 > rx
root@openwrt:~#  cat ./leds_off
#!/bin/sh
cd /sys/devices/platform/leds/leds/green:lan
echo none > trigger
cd /sys/devices/platform/leds/leds/green:wan
echo none > trigger
root@openwrt:~#

I think the config leds listed in the output I got using your given command cat /etc/config/system are files not directories to cd to :

root@openwrt:~# cat /etc/config/system

config system
        option hostname 'openwrt'
        option timezone 'UTC-0:00'
        option ttylogin '0'
        option log_size '64'
        option urandom_seed '0'
        option compat_version '1.1'
        option zonename 'UTC'
        option log_proto 'udp'
        option conloglevel '8'
        option cronloglevel '5'

config timeserver 'ntp'
        list server '0.openwrt.pool.ntp.org'
        list server '1.openwrt.pool.ntp.org'
        list server '2.openwrt.pool.ntp.org'
        list server '3.openwrt.pool.ntp.org'

config led 'led_lan'
        option name 'LAN'
        option sysfs 'green:lan'
        option trigger 'netdev'
        option dev 'br-lan'
        list mode 'link'
        list mode 'tx'
        list mode 'rx'

config led 'led_wan'
        option name 'WAN'
        option sysfs 'green:wan'
        option trigger 'netdev'
        option mode 'link tx rx'
        option dev 'wan'

I double checked and same output as this :

root@openwrt:~# sh


BusyBox v1.36.1 (2023-11-14 13:38:11 UTC) built-in shell (ash)

root@openwrt:~# ls
leds_off  leds_on   trigger?
root@openwrt:~# sh leds_off
: No such file or directory cd to /sys/devices/platform/leds/leds/green:lan
: No such file or directory cd to /sys/devices/platform/leds/leds/green:wan
root@openwrt:~# sh leds_on
: No such file or directorycd to /sys/devices/platform/leds/leds/green:lan
: No such file or directorycd to /sys/devices/platform/leds/leds/green:wan
root@openwrt:~#

True, I also pointed the same thing but the output on terminal says otherwise where its checking for file as well still it says no such file :

: No such file or directory cd to /sys/devices/platform/leds/leds/green:lan

I think there is some more improvement in this matter. I did cd=/....<path> instead of cd /....<path> in the script and the error output of can't find file or directory vanished and is not coming up now. Though no errors are coming on successful execution of sh leds_off or sh leds_on , still the leds on my router don't turn on or off on explicitly running the 2 scripts by me on ssh terminal as you can see in the detailed long output below. Also I observed that the 2 scripts are trying to change values of files: device_name, link, tx, rx and trigger but no effect on leds' state occurs, instead some new files have popped up in the /root/ folder where I had placed leds_off and leds_on files which are : device_name? , link? , rx? , tx? , trigger? and changes by both script files are being observed in these files (those which are in /root/ folder) instead of the files in the /sys/devices/platform/leds/leds/ ' s green:wan or green:lan folders of firmware. I don't know how the things in the last observation is happening when the script is trying to change contents of files in /sys/devices/platform/leds/leds/ ' s green:wan or green:lan folders but instead contents of new formed files in /root/ folders are being changed. All this can be seen in the long output I have shown here :

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 OpenWrt 23.05.2, r23630-842932a63d
 -----------------------------------------------------
root@openwrt:~# ls
device_name?  leds_off      leds_on       link?         rx?           trigger?      tx?
root@openwrt:~# scho leds_on
-ash: scho: not found
root@openwrt:~# echo leds_on
leds_on
root@openwrt:~# echo -e leds_on
leds_on
root@openwrt:~# echo -f leds_on
-f leds_on
root@openwrt:~# cat leds_on
#!/bin/sh
cd /sys/devices/platform/leds/leds/green:lan
echo netdev > trigger
echo br-lan > device_name
echo 1 > link
echo 1 > tx
echo 1 > rx
cd /sys/devices/platform/leds/leds/green:wan
echo netdev > trigger
echo wan > device_name
echo 1 > link
echo 1 > tx
echo 1 > rx
root@openwrt:~# cd /sys/devices/platform/leds/leds/green:lan
root@openwrt:/sys/devices/platform/leds/leds/green:lan# cat leds_on
cat: can't open 'leds_on': No such file or directory
root@openwrt:/sys/devices/platform/leds/leds/green:lan# ls
brightness      device_name     link            rx              trigger         uevent
device          interval        max_brightness  subsystem       tx
root@openwrt:/sys/devices/platform/leds/leds/green:lan# cd
root@openwrt:~# ls
device_name?  leds_off      leds_on       link?         rx?           trigger?      tx?
root@openwrt:~# sh leds_on
: No such file or directorycd to /sys/devices/platform/leds/leds/green:lan
: No such file or directorycd to /sys/devices/platform/leds/leds/green:wan
root@openwrt:~# cd /sys/devices/platform/leds/leds/green:lan/
root@openwrt:/sys/devices/platform/leds/leds/green:lan# cd
root@openwrt:~# sh leds_on
: No such file or directorycd to /sys/devices/platform/leds/leds/green:lan/
: No such file or directorycd to /sys/devices/platform/leds/leds/green:wan/
root@openwrt:~# ls
device_name?  leds_off      leds_on       link?         rx?           trigger?      tx?
root@openwrt:~# bash led_off
-ash: bash: not found
root@openwrt:~# ./led_off
-ash: ./led_off: not found
root@openwrt:~# sh led_off
sh: can't open 'led_off': No such file or directory
root@openwrt:~# bash leds_off
-ash: bash: not found
root@openwrt:~# ./leds_off
-ash: ./leds_off: not found
root@openwrt:~# sh leds_off
: No such file or directory cd to /sys/devices/platform/leds/leds/green:lan/
: No such file or directory cd to /sys/devices/platform/leds/leds/green:wan/
root@openwrt:~# sh leds_on
: No such file or directorycd to /sys/devices/platform/leds/leds/green:lan/
: No such file or directorycd to /sys/devices/platform/leds/leds/green:wan/
root@openwrt:~# sudo su
-ash: sudo: not found
root@openwrt:~# su
-ash: su: not found
root@openwrt:~# ls
device_name?  leds_off      leds_on       link?         rx?           trigger?      tx?
root@openwrt:~# cd
root@openwrt:~# cd /
root@openwrt:/# ls
bin      dev      etc      lib      mnt      overlay  proc     rom      root     sbin     sys      tmp      usr      var      www
root@openwrt:/# cd sys
root@openwrt:/sys# ls
block     bus       class     dev       devices   firmware  fs        kernel    module
root@openwrt:/sys# cd devices
root@openwrt:/sys/devices# ls
platform  soc0      system    virtual
root@openwrt:/sys/devices# cd platform
root@openwrt:/sys/devices/platform# ls
1e000000.palmbus   1e149000.pcie-phy  1fbf0000.cpc       clkctrl            pinctrl            rstctrl
1e100000.ethernet  1e14a000.pcie-phy  1fbf8000.mc        keys               reg-dummy          serial8250
1e140000.pcie      1e1c0000.xhci      Fixed MDIO bus.0   leds               regulatory.0       uevent
root@openwrt:/sys/devices/platform# cd leds
root@openwrt:/sys/devices/platform/leds# ls
driver           driver_override  leds             modalias         of_node          subsystem        uevent
root@openwrt:/sys/devices/platform/leds# cd leds
root@openwrt:/sys/devices/platform/leds/leds# ls
amber:wan     green:lan     green:power   green:wan     green:wlan-2  green:wlan-5
root@openwrt:/sys/devices/platform/leds/leds# cd green:wan
root@openwrt:/sys/devices/platform/leds/leds/green:wan# ls
brightness      device_name     link            rx              trigger         uevent
device          interval        max_brightness  subsystem       tx
root@openwrt:/sys/devices/platform/leds/leds/green:wan# ls
brightness      device_name     link            rx              trigger         uevent
device          interval        max_brightness  subsystem       tx
root@openwrt:/sys/devices/platform/leds/leds/green:wan# cd
root@openwrt:~# sh leds_on
: No such file or directorycd to sys/devices/platform/leds/leds/green:lan/
: No such file or directorycd to sys/devices/platform/leds/leds/green:wan/
root@openwrt:~# cd "/sys/devices/platform/leds/leds/green:lan/"
root@openwrt:/sys/devices/platform/leds/leds/green:lan# cd
root@openwrt:~# ls
device_name?  leds_off      leds_on       link?         rx?           trigger?      tx?
root@openwrt:~# sh leds_off
: No such file or directory cd to sys/devices/platform/leds/leds/green:lan/
: No such file or directory cd to sys/devices/platform/leds/leds/green:wan/
root@openwrt:~# sh leds_on
: No such file or directorycd to sys/devices/platform/leds/leds/green:lan/
: No such file or directorycd to sys/devices/platform/leds/leds/green:wan/
root@openwrt:~# sh leds_off
: No such file or directory cd to sys/devices/platform/leds/leds/green:lan/
: No such file or directory cd to sys/devices/platform/leds/leds/green:wan/
root@openwrt:~# sh leds_on
: No such file or directorycd to sys/devices/platform/leds/leds/green:lan/
: No such file or directorycd to sys/devices/platform/leds/leds/green:wan/
root@openwrt:~# sh leds_off
: No such file or directory cd to sys/devices/platform/leds/leds/green:lan/
: No such file or directory cd to sys/devices/platform/leds/leds/green:wan/
root@openwrt:~# sh leds_off
root@openwrt:~# sh leds_off
root@openwrt:~# sh leds_off
root@openwrt:~# sh leds_on
root@openwrt:~# sh leds_off
root@openwrt:~# cat leds_off
#!/bin/sh
cd=/sys/devices/platform/leds/leds/green:lan/
echo none > trigger
cd=/sys/devices/platform/leds/leds/green:wan/
echo none > trigger
root@openwrt:~# cat trigger
cat: can't open 'trigger': No such file or directory
root@openwrt:~# cat trigger?
none
root@openwrt:~# sh leds_on
root@openwrt:~# cat trigger?
netdev
root@openwrt:~# chmod +x leds_off
root@openwrt:~# chmod +x leds_on
root@openwrt:~# sh leds_off
root@openwrt:~# cd /bin/sh
-ash: cd: can't cd to /bin/sh: Not a directory
root@openwrt:~# ls
device_name?  leds_off      leds_on       link?         rx?           trigger?      tx?
root@openwrt:~# cat link?
1
root@openwrt:~# ls
device_name?  leds_off      leds_on       link?         rx?           trigger?      tx?
root@openwrt:~# sh leds_off
root@openwrt:~# cat /sys/devices/platform/leds/leds/green:lan/trigger
none timer heartbeat default-on [netdev] mt7530-0:00:link mt7530-0:00:1Gbps mt7530-0:00:100Mbps mt7530-0:00:10Mbps mt7530-0:01:link mt7530-0:01:1Gbps mt7530-0:01:100Mbps mt7530-0:01:10Mbps mt7530-0:02:link mt7530-0:02:1Gbps mt7530-0:02:100Mbps mt7530-0:02:10Mbps mt7530-0:03:link mt7530-0:03:1Gbps mt7530-0:03:100Mbps mt7530-0:03:10Mbps mt7530-0:04:link mt7530-0:04:1Gbps mt7530-0:04:100Mbps mt7530-0:04:10Mbps phy0rx phy0tx phy0assoc phy0radio phy0tpt phy1rx phy1tx phy1assoc phy1radio phy1tpt
root@openwrt:~# cat /sys/devices/platform/leds/leds/green:lan/trigger/
cat: can't open '/sys/devices/platform/leds/leds/green:lan/trigger/': Not a directory
root@openwrt:~# cat /sys/devices/platform/leds/leds/green:lan/trigger
none timer heartbeat default-on [netdev] mt7530-0:00:link mt7530-0:00:1Gbps mt7530-0:00:100Mbps mt7530-0:00:10Mbps mt7530-0:01:link mt7530-0:01:1Gbps mt7530-0:01:100Mbps mt7530-0:01:10Mbps mt7530-0:02:link mt7530-0:02:1Gbps mt7530-0:02:100Mbps mt7530-0:02:10Mbps mt7530-0:03:link mt7530-0:03:1Gbps mt7530-0:03:100Mbps mt7530-0:03:10Mbps mt7530-0:04:link mt7530-0:04:1Gbps mt7530-0:04:100Mbps mt7530-0:04:10Mbps phy0rx phy0tx phy0assoc phy0radio phy0tpt phy1rx phy1tx phy1assoc phy1radio phy1tpt
root@openwrt:~# cat /sys/devices/platform/leds/leds/green:lan/tx
1
root@openwrt:~# cat /sys/devices/platform/leds/leds/green:lan/rx
1
root@openwrt:~# cat /sys/devices/platform/leds/leds/green:lan/device_name
br-lan
root@openwrt:~# cat /sys/devices/platform/leds/leds/green:lan/link
1
root@openwrt:~# sh leds_off
root@openwrt:~# cat /sys/devices/platform/leds/leds/green:lan/trigger
none timer heartbeat default-on [netdev] mt7530-0:00:link mt7530-0:00:1Gbps mt7530-0:00:100Mbps mt7530-0:00:10Mbps mt7530-0:01:link mt7530-0:01:1Gbps mt7530-0:01:100Mbps mt7530-0:01:10Mbps mt7530-0:02:link mt7530-0:02:1Gbps mt7530-0:02:100Mbps mt7530-0:02:10Mbps mt7530-0:03:link mt7530-0:03:1Gbps mt7530-0:03:100Mbps mt7530-0:03:10Mbps mt7530-0:04:link mt7530-0:04:1Gbps mt7530-0:04:100Mbps mt7530-0:04:10Mbps phy0rx phy0tx phy0assoc phy0radio phy0tpt phy1rx phy1tx phy1assoc phy1radio phy1tpt
root@openwrt:~# sh leds_on
root@openwrt:~# cat /sys/devices/platform/leds/leds/green:lan/trigger
none timer heartbeat default-on [netdev] mt7530-0:00:link mt7530-0:00:1Gbps mt7530-0:00:100Mbps mt7530-0:00:10Mbps mt7530-0:01:link mt7530-0:01:1Gbps mt7530-0:01:100Mbps mt7530-0:01:10Mbps mt7530-0:02:link mt7530-0:02:1Gbps mt7530-0:02:100Mbps mt7530-0:02:10Mbps mt7530-0:03:link mt7530-0:03:1Gbps mt7530-0:03:100Mbps mt7530-0:03:10Mbps mt7530-0:04:link mt7530-0:04:1Gbps mt7530-0:04:100Mbps mt7530-0:04:10Mbps phy0rx phy0tx phy0assoc phy0radio phy0tpt phy1rx phy1tx phy1assoc phy1radio phy1tpt
root@openwrt:~# sh leds_off
root@openwrt:~# cat trigger?
none
root@openwrt:~# sh leds_on
root@openwrt:~# cat trigger?
netdev
root@openwrt:~#

Why? I applaud your initiative and persistence, but this works best if you understand what you are doing first before executing random lines like this.

The error message vanishes because cd= does not change any directory. All it does is assign whatever is on the right hand side to a variable called cd. That's why you're seeing all those files in /root, because it's not writing them into the correct directories.

No, they are supposed to be directories. If they're actually files, then something seriously strange is going on, or there's a serious misunderstanding.

Let me show what it's supposed to look like. On a Ubiquiti U6+ I have running OpenWrt on, the LED directory tree is:

/sys/devices/platform/leds/leds/
├── blue:dome
│   ├── brightness
│   ├── device -> ../../../leds
│   ├── max_brightness
│   ├── power
│   │   ├── autosuspend_delay_ms
│   │   ├── control
│   │   ├── runtime_active_time
│   │   ├── runtime_status
│   │   └── runtime_suspended_time
│   ├── subsystem -> ../../../../../class/leds
│   ├── trigger
│   └── uevent
└── white:dome
    ├── brightness
    ├── device -> ../../../leds
    ├── device_name
    ├── interval
    ├── link
    ├── max_brightness
    ├── power
    │   ├── autosuspend_delay_ms
    │   ├── control
    │   ├── runtime_active_time
    │   ├── runtime_status
    │   └── runtime_suspended_time
    ├── rx
    ├── subsystem -> ../../../../../class/leds
    ├── trigger
    ├── tx
    └── uevent

These are not real files and folders in the normal sense of files stored in flash. These are kernel data structures being presented as such to the user. Notice that each LED is in fact a directory that contains several files. One file of interest is the trigger file. You can cat the trigger file to show the currently selected trigger, as well as a list of valid trigger modes. For example, cat /sys/devices/platform/leds/leds/blue:dome shows:

[none] timer heartbeat default-on netdev mmc0 phy0rx phy0tx phy0assoc phy0radio phy0tpt phy1rx phy1tx phy1assoc phy1radio phy1tpt

This means that no trigger mode is currently selected for this LED. If I want to make it blink based on network activity, I can write "netdev" into the trigger file using echo netdev > trigger. To specify which device to look at for network activity, you write the interface name to device_name in the same directory.

That's why I keep asking you to cd into the directories under /sys/devices/platform/leds/leds, because that's the only place where it will work. And it's also why I'm completely dumbfounded at why you keep getting this error when doing cd:

No such file or directory cd to /sys/devices/platform/leds/leds/green:lan

Yet at the same time you are able to list the contents of that exact same directory you're trying to cd into:

root@openwrt:~# ls /sys/devices/platform/leds/leds
amber:wan     green:lan     green:power   green:wan     green:wlan-2  green:wlan-5

This literally makes no sense. Either your OpenWrt's shell is corrupted in some odd way, or there's a typo or something else going on.

Does the command ls /sys/devices/platform/leds/leds/green:lan work? Does its output include trigger as one of the entries?

1 Like

You can rest assured that I am telling everything as there 's no reason for me to not tell anything. Instead I myself need help for solving this issue so why would I not tell everything ? It might be possible inadvertently but I don't think so as I cross checked everything possible at my level and knowledge.

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 OpenWrt 23.05.2, r23630-842932a63d
 -----------------------------------------------------
root@openwrt:~# ls /sys/devices/platform/leds/leds/green:lan
brightness      device_name     link            rx              trigger         uevent
device          interval        max_brightness  subsystem       tx

So yes.Trigger option is coming under output above. And I am grateful for the detailed view of things provided by you. I needed them and you provided them without me asking, so I appreciate that.

Can you please check if

/bin/echo "0" > /sys/class/leds/green\:lan/brightness
/bin/echo "0" > /sys/class/leds/green\:wan/brightness

turn off the leds?
This is how I have it setup on my system

1 Like

I disable LEDS completely. LEDS are bloat.

1 Like