Page 1 of 1

[Solved] How to change the behaviour of board LED at boot

Posted: 2024-09-19 13:33
by munecito
Hello.

I am currently using Debain Bookworm on an Orange Pi Zero2 to run pihole and just general testing.

The board is on my desk in an acrylic case and by default the green LED blinks when the system is running.

Orange Pi provides guides to alter the behaviour of the LEDs but they are discarded on boot. So I have to run the command every time I reboot the machine.
The method of setting the green light on/off and flashing is as follows:

Note that the following operations should be performed under the root user.

First enter the setting directory of the green light

root@orangepi:~# cd /sys/class/leds/green_led

The command to set the green light to stop flashing is as follows

root@orangepi:/sys/class/leds/green_led# echo none > trigger

The command to set the green light to be on is as follows

root@orangepi:/sys/class/leds/green_led# echo default-on > trigger

root@orangepi:/sys/class/leds/green_led# echo default-on > trigger

The command to set the green light to flash is as follows

root@orangepi:/sys/class/leds/green_led# echo heartbeat > trigger
So the behaviour is set to heartbeat by default and it goes back to it after reboot.

Is there a way that I can run the instructions at boot or login so they stick? Or is there a file that I could modify?

The system is running headless so I operate via SSH.

Thank you for any help you could provide me on this.

Kind regards.

Re: [Hardware] How to change the behaviour of board LED at boot

Posted: 2024-09-19 20:38
by Aki

Re: [Hardware] How to change the behaviour of board LED at boot

Posted: 2024-09-20 08:33
by munecito
Thank you Aki.

I have a play but I will do a backup first.

I am fairly new so I have not really understood totally what command to include so the echo instruction runs.

If I try to call it from root without entering the subdirectory then it fails.

I tried a few ways but they all failed.

echo /sys/class/leds/green_led\default-on > trigger

-bash /sys/class/leds/green_led\echo default-on > trigger

bash /sys/class/leds/green_led\echo default-on > trigger

/sys/class/leds/green_led\echo default-on > trigger

So I am sure that it is the syntax that is wrong but I just need to understand how to run it either by creating a script or a config file.

What is hard to understand is how to place the instruction in the folder as root in any of those cases.

Kind regards.

Re: [Hardware] How to change the behaviour of board LED at boot

Posted: 2024-09-30 06:16
by Aki
Hello,
munecito wrote: 2024-09-20 08:33 I am fairly new so I have not really understood totally what command to include so the echo instruction runs.

If I try to call it from root without entering the subdirectory then it fails.

I tried a few ways but they all failed.

Code: Select all

echo /sys/class/leds/green_led\default-on > trigger 

-bash /sys/class/leds/green_led\echo default-on > trigger

bash /sys/class/leds/green_led\echo default-on > trigger

/sys/class/leds/green_led\echo default-on > trigger
So I am sure that it is the syntax that is wrong but I just need to understand how to run it either by creating a script or a config file.

What is hard to understand is how to place the instruction in the folder as root in any of those cases.

Kind regards.
Yes, unfortunately the syntax is wrong for a bash script.

According to the example in your first post, it should be (probably logged in as "root" user):

Code: Select all

# turn green led on (this is a comment)
echo default-on > /sys/class/leds/green_led

# turn green led off (this is a comment)
echo none > /sys/class/leds/green_led
Hope this helps.

Re: [Hardware] How to change the behaviour of board LED at boot

Posted: 2024-10-02 05:26
by munecito
@aki Thank you so much.

I managed to make it work modifying a bit the code you gave me.

The way I was able to run this on startup is by creating a cron job according to the page you linked and making a script based on your code:

Code: Select all

# turn green led on (this is a comment)
cd /sys/class/leds/green_led
echo default-on > trigger #/sys/class/leds/green_led

# turn green led off (this is a comment)
#echo none > /sys/class/leds/green_led
When I ran the code the way you gave me nothing happened, even after I commented out the turn green led off code.

There is something that I noticed and that is that even from the terminal I can't run the instruction if I am not inside the folder.

Code: Select all

sudo /sys/class/leds/green_led#echo default on > trigger
sudo: /sys/class/leds/green_led#echo: command not found
So I thought that if I was to change to the folder inside the script before running the echo instruction I would have had a better chance, hence I changed your code to

Code: Select all

# turn green led on (this is a comment)
cd /sys/class/leds/green_led
echo default-on > trigger #/sys/class/leds/green_led
I commented out the path instead of deleting just in case it did not work so I could play with it in the original way you supplied. I also had to add the > trigger part to make it run.

Thank you so very much. Now I think I can even use cron to create a time based job so the LEDs are fully turned off at night, although even staying on all the time is better than the blinking.

Re: [Hardware] How to change the behaviour of board LED at boot

Posted: 2024-10-03 14:46
by Aki
I'm glad you sorted it out. :)

Please, mark the discussion as "solved" manually adding the text tag "[Solved]" at the beginning of the subject of the first message (after other tags).

Thanks.

Happy Debian ! :)