Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Instruction Guide Power management for Audiophonics I-Sabre ES9023 V3
#1
[Note: This excellent write-up by @rikardo1979 was first posted in 2018 for moOde 4.x. As moOde has evolved, so have the instructions. For moOde 6.5.1, see @maartin's summary in his followup post downthread.]

1 / Installation of WiringPi:

You’ll need WiringPi to communicate withe the GPIO pins on the Pi.
To do so you’ll need to install gcc:

Code:
sudo apt-get install gcc

now on to wiringPi:

Code:
cd /home/pi
git clone git://git.drogon.net/wiringPi
cd wiringPi
./build


If all goes well you can now get an overview of the GPIO pins by typing 

Code:
gpio readall




2 / Creating the script for the command from the power button:
First we need to go back to /home/pi

Code:
cd /home/pi

Then we can get the script

Code:
wget https://raw.githubusercontent.com/audiophonics/Raspberry-pwr-management/master/sds.sh


3 / Add the script button at startup: Editing the startup file:
Now edit rc.local. This will make the script run at startup.

Code:
sudo nano /etc/rc.local

Add this line before "exit 0”. Don’t delete or change anything else in this file, just add the extra line.

Code:
sudo bash /home/pi/sds.sh &



4 / Creating command scripts for moOde restart and shutdown:
softshutdown recovery script:

Code:
sudo wget https://raw.githubusercontent.com/audiophonics/Raspberry-pwr-management/master/softshutdown.sh

softreboot recovery script:

Code:
sudo wget https://raw.githubusercontent.com/audiophonics/Raspberry-pwr-management/master/softreboot.sh

I don’t know if the scripts need to be executable, but I don’t think it can hurt to do so:

Code:
sudo chmod +x sds.sh
sudo chmod +x softshutdown.sh
sudo chmod +x softreboot.sh


5 / Make moOde work with the scripts.
First make a backup of the original worker.php file in case you mess things up:

Code:
cd /var/www/command
sudo cp worker.php worker.sav


We can now edit the original:

Code:
sudo nano worker.php

Search for ‘reboot’ until you find the part that reads this:
     
Code:
case 'reboot':
         sysCmd('mpc stop');
         sysCmd('systemctl stop nginx');
         sysCmd('reboot');
         break;
      case 'poweroff':
         sysCmd('mpc stop');
         sysCmd('systemctl stop nginx');
         sysCmd('poweroff');
         break;


Here we will replace the reboot and poweroff commands with the scripts that now reside in /home/pi.
Change the text so it reads:

Code:
      case 'reboot':
         sysCmd('mpc stop');
         sysCmd('systemctl stop nginx');
         sysCmd('sudo bash /home/pi/softreboot.sh');
         break;
      case 'poweroff':
         sysCmd('mpc stop');
         sysCmd('systemctl stop nginx');
         sysCmd('sudo bash /home/pi/softshutdown.sh');
         break;


Reboot the Pi and if all goes well your LED should stop blinking and you should be able to power down with the button as well as through the moOde web UI.


[video]https://youtu.be/HsJU91o_yHw[/video]
<marquee behavior="alternate" scrolldelay=150
~~~~>>>Please always follow rules and read before you post<<<~~~~

</marquee>
Reply
#2
Hi rikardo1979,

I followed your howto, thank you very much for this clear document.
a couple of points:
Bash files (if you open then, you see they start with #!/bin/bash or similar, indeed need to be executable, so the chmod +x is indeed mandatory.

As for the worker.php file: i started with a clean Moode 4.1 setup. Since Moode 4.0 it seems these reboot/poweroff script parts are in:
/var/local/commandw/restart.sh

should be even easier. ;-)
Code is now:
Code:
case 'reboot':
         mpc stop
         systemctl stop nginx
         /home/pi/softreboot.sh
         break;
      case 'poweroff':
         mpc stop
         systemctl stop nginx
         /home/pi/softshutdown.sh
         break;
Reply
#3
Would this script be for Ver 4.x only ?
Or would it be backward compatible ?

Thanks.
Reply
#4
Hi moOde fans,
 :@
Reply
#5
(06-08-2018, 08:12 PM)hifix Wrote: Would this script be for Ver 4.x only ?
Or would it be backward compatible ?

Thanks.

As far as I remember it was a bit different on previous versions
<marquee behavior="alternate" scrolldelay=150
~~~~>>>Please always follow rules and read before you post<<<~~~~

</marquee>
Reply
#6
(06-13-2018, 07:59 PM)JST1963 Wrote:
(05-01-2018, 08:41 PM)rikardo1979 Wrote: Reboot the Pi and if all goes well your LED should stop blinking and you should be able to power down with the button as well as through the moOde web UI.

Works like a charm! Thx, Rikardo!

One question though…
I assume this will be overwritten again with every new version of moOde? If so, isn't it possible to kinda automate this? Like putting it all in one script and then execute this script?

Johan

To be honest I do not know answer for this as I have not tried any updates :Smilevery time I do a fresh install of system when testing new releases to be sure there is no 'mess' left behind 

Regarding the automated install script, I am pretty sure it would be possible. Unfortunately this is beyond my knowledge. Maybe somebody clever with coding skills can do it Wink
<marquee behavior="alternate" scrolldelay=150
~~~~>>>Please always follow rules and read before you post<<<~~~~

</marquee>
Reply
#7
Hi moOde fans,
 :@
Reply
#8
I just tried the code on 4.3 and got stuck with the:
case 'reboot':
case 'poweroff':
sections.

If anyone has figured this one out, please chime in.  I'd love to get 4.3 running on my main rig.
Reply
#9
(10-03-2018, 05:41 PM)hifix Wrote: I just tried the code on 4.3 and got stuck with the:
case 'reboot':
case 'poweroff':
sections.

If anyone has figured this one out, please chime in.  I'd love to get 4.3 running on my main rig.

So where exactly is the problem? There should be no change and you should be able proceed as stated. 
I just did my update few days ago and reinstall the power management with no problem
<marquee behavior="alternate" scrolldelay=150
~~~~>>>Please always follow rules and read before you post<<<~~~~

</marquee>
Reply
#10
(10-04-2018, 02:53 AM)slartibartfast Wrote: hifix:

Rikardo's instructions are still excellent. However, at some point Tim changed the file structure (if I remember correctly in part to make it easier for us Audiophonic users to run scripts at startup/shutdown).
Step 5 in the instructions should now go like this (at least for a new ISO installation of 4.3)


Code:
cd /var/local/www/commandw/
sudo nano restart.sh

Here find the "reboot" part and change it to this:

Code:
if [[ $1 = "reboot" ]]; then
       mpc stop
       systemctl stop nginx
       /home/pi/softreboot.sh
#      reboot
fi


Same for the "poweroff" part:

Code:
if [[ $1 = "poweroff" ]]; then
       mpc stop
       systemctl stop nginx
       /home/pi/softshutdown.sh
#      poweroff
fi


I did a fresh install of 4.3 from the ISO image this morning and it works great.
Jan

Thank you.
Reply


Forum Jump: