OPI PC: Run script on power button push?


Nixes
 Share

0

Recommended Posts

Hello all,

I was wondering if it is possible to run some sort of script when the power button on the Orange Pi PC is pressed?

I was thinking I could use this to run a safe shutdown script of some kind, rather than having to SSH in every time.

 

I've tried looking into the GPIOs but I could never get the button to show up in the list of available inputs. Any advice?

 

Thanks for any input. :)

Link to post
Share on other sites

Armbian is a community driven open source project. Do you like to contribute your code?

Thanks tkaiser, your second link definitely pointed the way.

acpid appears to work great, and is exactly what I was looking for.

 

Extra question, anyway to blink the power led from a shell script?

Link to post
Share on other sites

Actually NVM

 

to set red led to on use:

sudo sh -c "echo 255 > /sys/class/leds/red_led/brightness" 

to set red led to off use:

sudo sh -c "echo 0 > /sys/class/leds/red_led/brightness"

same for green led just "/sys/class/leds/green_led" instead

Link to post
Share on other sites

Regarding leds there's a bit more to say. In Armbian we define the leds in a different way than most if not all of the other available OS images for Orange Pis (OpenELEC being the other exception). With our led definition (see ssvb's commit) we can use different triggers, eg. let the green led blink, switch it off or on you would do:

echo heartbeat >/sys/class/leds/*green*/trigger
echo none >/sys/class/leds/*green*/trigger
echo default-on >/sys/class/leds/*green*/trigger

Adjusting brightness is also possible and in case you set the timer trigger two more sysfs nodes appear you can use to set on/off interval:

root@orangepiplus2e:/sys/class/leds/green_led# echo timer >/sys/class/leds/*green*/trigger
root@orangepiplus2e:/sys/class/leds/green_led# ls -al
total 0
drwxr-xr-x 3 root root    0 Jan  1  1970 .
drwxr-xr-x 4 root root    0 Jan  1  1970 ..
-rw-r--r-- 1 root root 4096 May 25 13:59 brightness
-rw-r--r-- 1 root root 4096 May 25 14:00 delay_off
-rw-r--r-- 1 root root 4096 May 25 14:00 delay_on
lrwxrwxrwx 1 root root    0 May 25 13:59 device -> ../../../leds-gpio
-r--r--r-- 1 root root 4096 May 25 13:59 max_brightness
drwxr-xr-x 2 root root    0 May 25 13:55 power
lrwxrwxrwx 1 root root    0 May 25 13:59 subsystem -> ../../../../../class/leds
-rw-r--r-- 1 root root 4096 May 25 14:00 trigger
-rw-r--r-- 1 root root 4096 Jan  1  1970 uevent

To get a list of all available triggers simply do a 'cat /sys/class/leds/*green*/trigger'.

Link to post
Share on other sites

Guest
This topic is now closed to further replies.
 Share

0