Friday, November 24th 2017, 4:59am UTC+1

Giriş yapmadınız.

  • Giriş
  • Kayıt

Sayın ziyaretçi, NAS Forum sitesine hoş geldiniz. Eğer buraya ilk ziyaretiniz ise lütfen Yardım bölümünü okuyunuz. Yardım bölümü bu sitenin nasıl çalıştığını açıklamaktadır. Site özelliklerinin tümünü kullanabilmeniz için öncelikle kayıt yaptırmanız gerekmektedir. Kayıt yaptırmak için kayıt formunu okuyabilir ya da kayıt işlemi hakkında daha fazla bilgi edinebilirsiniz. Eğer önceden kayıt yaptırdıysanız, buraya tıklayarak giriş yapabilirsiniz.

AQUAR

Stajyer

Mesajlar: 100

Konum: Australia

1

Tuesday, January 29th 2013, 1:43pm

Easy Button Control (UCI)

The OpenWRT port for the MBox/Clones has the hotplug package installed by default.

Good use of this package can be made by using it to control the hardware buttons on the front of the NASBOX.
On the OpenWRT site there is a script called "Atheros' 00-button + UCI" that integrates button control into the UCI system.

An example of how to use it follows.

Step 1:
Log into the NAS box with a SSH program like WINSCP.

Step 2:
Create /etc/hotplug.d/button/00-button with your favorite editor, then paste the following code:

Kaynak kod

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
. /etc/functions.sh
do_button () {
        local button
        local action
        local handler
        local min
        local max

        config_get button $1 button
        config_get action $1 action
        config_get handler $1 handler
        config_get min $1 min
        config_get max $1 max

        [ "$ACTION" = "$action" -a "$BUTTON" = "$button" -a -n "$handler" ] && {
                [ -z "$min" -o -z "$max" ] && eval $handler
                [ -n "$min" -a -n "$max" ] && {
                        [ $min -le $SEEN -a $max -ge $SEEN ] && eval $handler
                }
        }
}

config_load system
config_foreach do_button button


Note:This is the script that integrates button control into the UCI system.

Step 3:
Edit /etc/config/system to add at the bottom the following code:

Kaynak kod

1
2
3
4
5
6
7
8
9
10
11
12
13
config 'button'
	option 'button' 'BTN_0'
	option 'action' 'released'
	option 'handler' '/mnt/HDD1/OWRT_SYS/SCRIPT_Shutdown.txt'
	option 'min' '5'
	option 'max' '100'
	
config 'button'
	option 'button' 'BTN_1'
	option 'action' 'released'
	option 'handler' '/mnt/HDD1/OWRT_SYS/SCRIPT_Reboot.txt'
	option 'min' '5'
	option 'max' '100'


Note: These codes invoke the Shutdown and Reboot scripts if the front buttons are pressed for more than 5 sec.

Step 4:
On the HDD1 create a folder called OWRT_SYS

Step 5:
In the OWRT_SYS folder create these two text files:

First Text file is called SCRIPT_Shutdown.txt and holds the following code:

Kaynak kod

1
2
3
echo 0 > /sys/devices/platform/leds-gpio/leds/mvixbox:blue:power/brightness

exec kill -USR1 1


Second Text file is called SCRIPT_Reboot.txt and holds the following code:

Kaynak kod

1
reboot


With these system modifications in place:
1) The top button will shutdown the OS of the NASBOX so that it is safe to turn Off the power (also turns Off the power LED to let you know).
2) The bottom button will reboot the OS of the NASBOX.
3) Most importantly you can now issue UCI commands to change the behaviour of these buttons.

UCI commands to setup the buttons are:
uci add system button
uci set system.@button[-1].button=BTN_1
uci set system.@button[-1].action=pressed
uci set system.@button[-1].handler='logger BTN_1 pressed'
uci commit system

button is the name as the button, action is the event (two values: pressed and released), handler contains the command line to be run when the event is detected (can be a script as well).
Issuing the UCI commands adds entries in the system configuration file like the ones we added manually at Step 3 (to get things set up quickly!).
Try to generate some entries with the UCI commands yourself and see how easy it is to generate these entries in the system configuration file. Soon you will be able to redefine the behaviour of these buttons to suit your own needs.

Finally, see also the Button Script For MBox posted here for a simple way to achieve shutdown and reboot functions for the hardware buttons.

Aquar

AQUAR

Stajyer

Mesajlar: 100

Konum: Australia

2

Wednesday, January 30th 2013, 11:23am

Looks like the kill function is so quick that there is no time to turn off the power LED.
To fix this add some sleep to the shutdown script.

Kaynak kod

1
2
3
4
5
6
7
8
echo 0 > /sys/devices/platform/leds-gpio/leds/mvixbox:blue:power/brightness 
echo 0 > /sys/devices/platform/leds-gpio/leds/mvixbox:blue:status/brightness 
echo 0 > /sys/devices/platform/leds-gpio/leds/mvixbox:blue:sata0/brightness 
echo 0 > /sys/devices/platform/leds-gpio/leds/mvixbox:blue:sata1/brightness 
echo 0 > /sys/devices/platform/leds-gpio/leds/mvixbox:blue:usb1/brightness 
echo 0 > /sys/devices/platform/leds-gpio/leds/mvixbox:blue:usb2/brightness 
sleep 10 
exec kill -USR1 1

The extra echo 0> lines are for turning off the other front panel LED's.
Include some or all of them as you wish.