Support of shutdown scripts

I would like to see volumio supporting any shutdown scripts.

I’m using RemotePi Board from MSL Digital Solution for controlling the power of my Raspberry Pi. The RemotePi Board supports cutting the power if it receives a special signal sequence sent on one of the GPIOs.

Built in support possibly activated by web interface or at least an instruction on how to modify the shutdown sequence executed by volumio is highly appreciated!

Hi,

You’ll have to edit the file /var/www/command/player_wrk.php at line 359:

                case 'poweroff':
                $cmd = 'mpc stop && poweroff';
                sysCmd($cmd);
                break;

Instead of poweroff just invoke your script.

Hi Stephane,

many thanks for your support!

I created the following script called shutdown.sh in /etc and made it executable.

[code]#!/bin/bash
GPIOpin=15
echo “$GPIOpin” > /sys/class/gpio/export

execute shutdown sequence on pin

echo “out” > /sys/class/gpio/gpio$GPIOpin/direction
echo “1” > /sys/class/gpio/gpio$GPIOpin/value
sleep 0.125
echo “0” > /sys/class/gpio/gpio$GPIOpin/value
sleep 0.2
echo “1” > /sys/class/gpio/gpio$GPIOpin/value
sleep 0.4
echo “0” > /sys/class/gpio/gpio$GPIOpin/value[/code]

Can you explain how I call this script in player_wrk.php?

BR

Michael

Hello Michael,

As I wrote, you’ll have to edit the file at line 359 replacing the command poweroff by the script you wrote, e.g. /etc/shutdown.sh, like this:

case 'poweroff': $cmd = 'mpc stop && /etc/shutdown.sh'; sysCmd($cmd); break;
You’ll have to reboot.
There might be a better place to put your script, in /etc/init.d/halt for example.
By the way, I don’t see the command poweroff in your script, is this normal?

Hi Stephane,

what I already tried is to replace

$cmd = 'mpc stop && poweroff';

simply by

$cmd = '/etc/shutdown.sh';

This should trigger the RasPi to send a dedicated signal pattern on GPIO15. The RemotePi usually recognizes this pattern and itself sets GPIO14 to high level.
The following script called irswitch.sh also located in /etc then stops the mpc and performs the shutdown.

[code]#!/bin/bash

this is the GPIO pin receiving the shut-down signal

GPIOpin1=14
echo “$GPIOpin1” > /sys/class/gpio/export
echo “in” > /sys/class/gpio/gpio$GPIOpin1/direction
while true; do
sleep 1
power=$(cat /sys/class/gpio/gpio$GPIOpin1/value)
if [ $power != 0 ]; then
mpc stop
echo “out” > /sys/class/gpio/gpio$GPIOpin1/direction
echo “1” > /sys/class/gpio/gpio$GPIOpin1/value
sleep 3
shutdown -h now
fi
done[/code]
The GPIO14 is also set by the RemotePi Board when it receives a comand from the IR remote or it’s push button is pressed. The above script is executed and the Pi shuts down.

I’ll try to find out if the script shutdow.sh is executed and if the intended signal sequence is sent.

BR

Michael

I meanwhile solved it. There was a missing blank. The first line of the script has to be:

#! /bin/bash

and not

#!/bin/bash

Here’s what I did:

I created a script called initpwrdown.sh, saved it in /etc and made it executable by chmod +x initpwrdown.sh .

Finally I had to change line 359 in player_wrk.php located in /var/www/command/ from $cmd = 'mpc stop && poweroff'; to $cmd = '/etc/initpwrdown.sh'; .

Now the signal sequence on GPIO15 is sent when Menu>Turn off>Power off is chosen from the web UI. Afterwards RemotePi inits the power down.

Many thanks to Stepahne for pointing me in the right direction!

I attached the script as well as the modified player_wrk.php.
RemotePi_Volumio.zip (4.99 KB)