Nespi+ case - turn off fan by using emulationstation software shutdown?
-
Sorry for third posting....
You've always to press the power button to make a complete shutdown afaik :(
But you can modify the switch to make it work like the reset button. Just remove the small metal-sheet, this will convert the latching switch to a momentary one. -
@cyperghost Hi Cyperghost. Thank you for responding. I also want to personally thank you for the great work on your shutdown script. It works perfectly, as do the behaviors of my buttons on my case. When I press my power button, it shuts down nicely, and then terminates power to the fan. It does everything just like it should. Everyone with a Nespi+ case owes you lunch! I don't think my question relates to any of your code, necessarily. But, in response to your questions:
Yes, I have installed raspi-gpio (version 0.2.0.171123) and placed your script in system-shutdown. (along with the script "shutdown_fan")
My question was really "Is it possible to completely terminate power to both the Pi and the fan without pressing the button power, but rather only by using the Quit-Shutdown System option from within EmulationStation".
When I execute shutdown from the EmulationStation menu, Power is turned off for the Pi, but the fan keeps running. The "shutdown_fan" script in systemd doesn't seem to do anything with this type of shutdown.
As you said, @meleu is no longer working on the general shutdown anymore, so I may just be out of luck. I could probably figure out a way to do it if I could only create a way to shut the fan down with a command line script, but it's a little out of scope of my understanding at this point.
I thought that your shutdown_fan script in "/lib/systemd/system-shutdown" would do the trick and turn the fan off with "[[ $1 == "poweroff" ]] && raspi-gpio set 4 op pn dl" but that doesn't seem to work, and executing this script from a command line produces the error: ./shutdown_fan: 12 ./shutdown_fan: [[: not found".
And running "raspi-gpio set 4 op pn dl" from the command line seems to execute, but the fan still remains on.
And I apologize in advance if this cannot be done, or I've made a mistake somewhere. I'm still an intermediate user learning new stuff everyday. Any ideas?
-
@theretroprince said in Nespi+ case - turn off fan by using emulationstation software shutdown?:
My question was really "Is it possible to completely terminate power to both the Pi and the fan without pressing the button power, but rather only by using the Quit-Shutdown System option from within EmulationStation".
Yes it is possible but you have to modify the script and you have to modify the switch. If you press the power switch and keep it in on position, then a kind of "electric relais" (MOSFET) is activated, too (this is GPIO pin 4). So for proper shutdown you set power switch to off position and then in last shutdown sequence the shutdown_fan script is called and sets GPIO 4 to 0 . Thus deactivates the MOSFET and completly cuts of power and the fan shuts also down.
Otherwise: you make a shutdown via menu only. This is the same procedure as writing
sudo poweroff
in terminal. This will also call GPIO 4 and set it to 0 but the power switch remains in ON position and this will fail to cut off power.So what to do? Use the same procedure as I made in line 504 for the PIMORONI ON OFF SHIM. I check in what state the switch is. it would get called
power=$(raspi-gpio get $GPIO_powerswitch | grep -c "level=1 fsel=0 func=INPUT")
If it's a momentary the power=0, if it's a latching then power=1. Then I make the loopuntil [[ $power == $switchtype ]]
but you have to modify the switch for this, that it works like the reset switch.
PS: Never tested this, so it's pure suggestionI thought that your shutdown_fan script in "/lib/systemd/system-shutdown" would do the trick and turn the fan off with "[[ $1 == "poweroff" ]] && raspi-gpio set 4 op pn dl" but that doesn't seem to work, and executing this script from a command line produces the error: ./shutdown_fan: 12 ./shutdown_fan: [[: not found".
No this won't work. The systemd service parses arguments to any script. If you just call the script there is no
$1
argument so the code[[ == "poweroff" ]] is an error. You should call the script with
sudo /lib/systemd/system-shutdown/shutdown_fan poweroff` then it will work.Everyone with a Nespi+ case owes you lunch!
I love good food ;)
-
@cyperghost Ohhhh, thanks for bearing with me. I'm just beginning to understand. Your first option is probably not what I'm looking for, but you're educating me!
For the second option (sudo /lib/systemd/system-shutdown/shutdown_fan poweroff), if I pass the "poweroff" variable to the script, shouldn't that still disable fan power even without the modifications to the power button?
I tried to run it: "sudo /lib/systemd/system-shutdown/shutdown_fan poweroff", but it still outputs an "error 12: [[: not found".
Or would the button modification still be required to complete the argument?
-
@theretroprince said in Nespi+ case - turn off fan by using emulationstation software shutdown?:
shouldn't that still disable fan power even without the modifications to the power button?
No. The commands should shut the whole current down. You can't select for fan only.
-
@cyperghost That would be perfectly fine if it shut the whole system down. But I wonder why my script is not working? Any ideas?
-
Well you can try following
First you disable the multi_switch script with
pkill -f multi_switch.sh
Then release power button - the system should not powerdown because you've disabled trigger script
Then runraspi-gpio set 4 op pn dl
- this should cause a sudden power offPlease update your script! I used bashism for shell script
[ "$1" = "poweroff" ] && raspi-gpio set 4 op pn dl
is correct -
hey, I saw some pings! 🏓
I came here for a quick visit and maybe I won't find the time to catch up...
is there something I can do to help?
help me to help you guys! 😅 -
@meleu Hi Meleu! Thanks for replying.
I was just looking at possibilities for shutdown options with a Nespi+ case, and Cyperghost was educating me on his scripts and their interaction with this specific case.
What I was looking into was the ability to maintain the functionality of the power button on the Nespi+ with the scripts. (Safe shutdown, cut case power/ turn off fan), but also have the ability to perform the same functionality through the "Quit - Shutdown" option within EmulationStation.
Quit-Shutdown through ES shuts the system down, but does not disable the Nespi+ case power, specifically the fan. I was thinking that having both options would be nice, so you could still have the power button on the Case use a safe shutdown/cut power, but also be able to do the same through EmulationStation, similar to how you could turn off a current-gen console via the controller. (Without having to get my lazy behind off the couch! :-) I'm not sure we found a solution, but I got some learnin' nonetheless! And I really appreciate it!
-
@theretroprince oh, now I got what you want. And I'm afraid it's not possible :(
I can't think on something more "shutdownish" thensudo powerof
(which is what happens when you shutdown system via emulationstation menu). -
@meleu It is not possible because the power switch is always in "on" position. So the GPIO for cutting power is triggered correctly but the power switch has to be pressed always manually (as long it is a latching one ... you can modify this one to be a momentary switch)
@theretroprince can make a proof of concept I have written here. This should work ;)
-
Thank you @meleu and @cyperghost
I may end up ordering another Nespi+ case to attempt the button modification. If I do, I'll certainly come back and provide an update!
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.