Moode Forum
enable gpio output when boot is complete - Printable Version

+- Moode Forum (https://moodeaudio.org/forum)
+-- Forum: moOde audio player (https://moodeaudio.org/forum/forumdisplay.php?fid=3)
+--- Forum: FAQ and Guides (https://moodeaudio.org/forum/forumdisplay.php?fid=9)
+--- Thread: enable gpio output when boot is complete (/showthread.php?tid=3322)

Pages: 1 2


enable gpio output when boot is complete - Wallyboy - 12-31-2020

Hi folks;  Does anyone have an idea on how I might enable a GPI pin when boot up is complete.  I can setup a service to enable the pin but I am not sure how to have the action taken only after the boot up process has finished.

Thanks


RE: enable gpio output when boot is complete - taichauchau - 09-09-2021

hi, I also need this function since my external power control circuit detects gpio HIGH when boot succes and goes LOW for shuting down.


RE: enable gpio output when boot is complete - Tim Curtis - 09-09-2021

Run the commands below. If they all return "1" then high likelihood that moOde has successfully completed its boot sequence and all is well.

Code:
pi@rp1:~ $ moodeutl -q "select value from cfg_system where param='wrkready'"
1
pi@rp1:~ $ pgrep -c watchdog.sh
1
pi@rp1:~ $ pgrep -c mpd
1



RE: enable gpio output when boot is complete - adrii - 09-09-2021

Hi Wallyboy

I use the following in a (longer) shell script to pause until the Moode boot has completed (it doesn't check that MPD has started)


Code:
  ...
  # wait for worker to start to ensure start flag is set to 0
   until ps -C worker.php > /dev/null; do
      sleep 2
   done
   sleep 1     # extra time allow to set flag
   until test $(moodeutl -q "select value from cfg_system where param='wrkready'") = "1"; do
      sleep 4
   done
...

If you are using a systemd service file then you can wait for a script to complete using an ExecStartPre line 

Adrian.


RE: enable gpio output when boot is complete - Wallyboy - 01-05-2024

(09-09-2021, 12:17 PM)adrii Wrote: Hi Wallyboy

I use the following in a (longer) shell script to pause until the Moode boot has completed (it doesn't check that MPD has started)


Code:
  ...
  # wait for worker to start to ensure start flag is set to 0
   until ps -C worker.php > /dev/null; do
      sleep 2
   done
   sleep 1     # extra time allow to set flag
   until test $(moodeutl -q "select value from cfg_system where param='wrkready'") = "1"; do
      sleep 4
   done
...

If you are using a systemd service file then you can wait for a script to complete using an ExecStartPre line 

Adrian.
Hi folks, I'm back to this after a hiatus.  I need some help from you coding experts (I am a novice at best).  I understand the boot detection part, but I'm having a problem setting the GPIO pin in an sh script.  Should I be using python?. I can set a GPIO pin in python, but I don't see how to execute moodutl within a python script.  Any help or direction would be much appreciated. 

Kent


RE: enable gpio output when boot is complete - Tim Curtis - 01-05-2024

(01-05-2024, 05:07 PM)Wallyboy Wrote:
(09-09-2021, 12:17 PM)adrii Wrote: Hi Wallyboy

I use the following in a (longer) shell script to pause until the Moode boot has completed (it doesn't check that MPD has started)


Code:
  ...
  # wait for worker to start to ensure start flag is set to 0
   until ps -C worker.php > /dev/null; do
      sleep 2
   done
   sleep 1     # extra time allow to set flag
   until test $(moodeutl -q "select value from cfg_system where param='wrkready'") = "1"; do
      sleep 4
   done
...

If you are using a systemd service file then you can wait for a script to complete using an ExecStartPre line 

Adrian.
Hi folks, I'm back to this after a hiatus.  I need some help from you coding experts (I am a novice at best).  I understand the boot detection part, but I'm having a problem setting the GPIO pin in an sh script.  Should I be using python?. I can set a GPIO pin in python, but I don't see how to execute moodutl within a python script.  Any help or direction would be much appreciated. 

Kent

https://raspberrypi-aa.github.io/session2/bash.html


RE: enable gpio output when boot is complete - Wallyboy - 01-07-2024

(01-05-2024, 10:47 PM)Tim Curtis Wrote:
(01-05-2024, 05:07 PM)Wallyboy Wrote:
(09-09-2021, 12:17 PM)adrii Wrote: Hi Wallyboy

I use the following in a (longer) shell script to pause until the Moode boot has completed (it doesn't check that MPD has started)


Code:
  ...
  # wait for worker to start to ensure start flag is set to 0
   until ps -C worker.php > /dev/null; do
      sleep 2
   done
   sleep 1     # extra time allow to set flag
   until test $(moodeutl -q "select value from cfg_system where param='wrkready'") = "1"; do
      sleep 4
   done
...

If you are using a systemd service file then you can wait for a script to complete using an ExecStartPre line 

Adrian.
Hi folks, I'm back to this after a hiatus.  I need some help from you coding experts (I am a novice at best).  I understand the boot detection part, but I'm having a problem setting the GPIO pin in an sh script.  Should I be using python?. I can set a GPIO pin in python, but I don't see how to execute moodutl within a python script.  Any help or direction would be much appreciated. 

Kent

https://raspberrypi-aa.github.io/session2/bash.html

Hi Tim.  Thankyou for the reply.  I tried writing a short script following the directions in the link.  I got an unsuccessful result as you can see in the code window.  I'm lost.  Any suggestions?
Code:
#!/bin/bash

echo" 18" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio18/direction
echo "1" > /sys/class/gpio/gpio18/value

Code:
Result:...

./boot_indicator.sh
./boot_indicator.sh: line 3: echo 18: command not found
./boot_indicator.sh: line 4: /sys/class/gpio/gpio18/direction: No such file or directory
./boot_indicator.sh: line 5: /sys/class/gpio/gpio18/value: No such file or directory



RE: enable gpio output when boot is complete - Tim Curtis - 01-07-2024

change

echo" 18" to
echo "18"


RE: enable gpio output when boot is complete - Wallyboy - 01-07-2024

(01-07-2024, 08:10 PM)Wallyboy Wrote:
(01-05-2024, 10:47 PM)Tim Curtis Wrote:
(01-05-2024, 05:07 PM)Wallyboy Wrote:
(09-09-2021, 12:17 PM)adrii Wrote: Hi Wallyboy

I use the following in a (longer) shell script to pause until the Moode boot has completed (it doesn't check that MPD has started)


Code:
  ...
  # wait for worker to start to ensure start flag is set to 0
   until ps -C worker.php > /dev/null; do
      sleep 2
   done
   sleep 1     # extra time allow to set flag
   until test $(moodeutl -q "select value from cfg_system where param='wrkready'") = "1"; do
      sleep 4
   done
...

If you are using a systemd service file then you can wait for a script to complete using an ExecStartPre line 

Adrian.
Hi folks, I'm back to this after a hiatus.  I need some help from you coding experts (I am a novice at best).  I understand the boot detection part, but I'm having a problem setting the GPIO pin in an sh script.  Should I be using python?. I can set a GPIO pin in python, but I don't see how to execute moodutl within a python script.  Any help or direction would be much appreciated. 

Kent

https://raspberrypi-aa.github.io/session2/bash.html

Hi Tim.  Thankyou for the reply.  I tried writing a short script following the directions in the link.  I got an unsuccessful result as you can see in the code window.  I'm lost.  Any suggestions?
Code:
#!/bin/bash

echo" 18" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio18/direction
echo "1" > /sys/class/gpio/gpio18/value

Code:
Result:...

./boot_indicator.sh
./boot_indicator.sh: line 3: echo 18: command not found
./boot_indicator.sh: line 4: /sys/class/gpio/gpio18/direction: No such file or directory
./boot_indicator.sh: line 5: /sys/class/gpio/gpio18/value: No such file or directory
Thanks Tim, I should have caught that.  Now I get permission denied on lines 4 and 5.  I assume it's because I'm not running the commands as root.  Can I run them as root within a script file?  Not sure how to do that.

Thanks


RE: enable gpio output when boot is complete - Nutul - 01-07-2024

(01-07-2024, 09:09 PM)Wallyboy Wrote: Can I run them as root within a script file?  Not sure how to do that.
Just prepend sudo to the command; although that rings a bell... about the "echo" thing...
Maybe it's better you include the three commands in a shell script, and then invoke the script with:

sudo ./yourscript.sh

although I am not sure if that would wait for the password... maybe making "root" the script owner, and then setting its sticky flag would have better chances of running.