question

kurtinge avatar image
kurtinge asked

Gracefully shutdown of Venus OS running on Raspberry Pi

Hi, guys !
I've been running the Venus OS on my Raspberry Pi for a couple of months now and it is really running smooth and ok - had some problems with discovery of a device, but it was caused by an defect cable. So here's the question?

Anyone who have opinions on how healthy it is to unplug this OS without running a graceful shutdown or halt? I do not know exactly how Venus OS handles memory cache, temp files, etc. There is no menu option that says anything about shutdown, only reboot, so I normally either just unplug it or do a cumbersome thing of logging in to ssh from my mobile.
Maybe the development department could put a shutdown option as well as the already existing reboot?

Venus OSRaspberry Pimodifications
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

5 Answers
dirkmuc avatar image
dirkmuc answered ·

Hi,

I never had any issue just cutting power. The Victron devices have the same code basis and they are running for years now without any issue to my knowledge.

Cheers

Dirk

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Kevin Windrem avatar image
Kevin Windrem answered ·

The Raspberry Pi community sites all sorts of issues with unclean shutdowns. Unix OS checks the file system and fixes most corruption on boot. But there are issues with flash memory that could spread a corrupt file to the entire card rendering it unusable. Some suggest the card can be permanently damaged.

However, I have several PIs running Debian and one running Venus that I routinely just turn off and have not run into a problem. I do carry a spare SD card with a backup of the one in my Venus Pi with me just in case.

I added a "halt" button to one of my designs but this doesn't address unclean shutdowns when power fails. To do this, you'd need to sense loss of power and store enough energy locally to carry the Pi through a clean shutdown (around 5-10 seconds). That would be a huge capacitor (1 FARAD) or require a small battery.

There are a number of RPI "backup"or "UPS" hats that will keep the PI running on batteries. Some (like the link below) provide a low battery signal to the PI that can be used for clean shutdown.

https://www.amazon.com/Uninterruptible-Raspberry-Battery-Protection-Circuits/dp/B08G1WRX6C/ref=sr_1_10?dchild=1&keywords=raspberry+pi+ups&qid=1610558718&sr=8-10

Here's one DYI solution I found:

http://spritesmods.com/?art=rpi_arcade&page=5



3 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

rmaddy avatar image rmaddy commented ·

Can you provide some details on how you added a halt command? I couldn't figure out how to call the Unix command `halt` or `shutdown` from a qml file. And I didn't see anything in your GuiMods. Thanks.

0 Likes 0 ·
Kevin Windrem avatar image Kevin Windrem rmaddy commented ·

The comment about the "halt button" in my previous post was for a different project (not Venus). It was written in C and a routine polls one of the GPIO pins. When it has detected the button has been down for 5 seconds I do a system call to halt.

I don' t know how you'd do a similar thing in Venus OS.

What I do for a clean shutdown with Venus is to trigger a reboot then watch the red led on the PI. It'll wink out when it begins the actual reboot. I then pull the power off the PI. Not elegant but it does appear to work.

0 Likes 0 ·
rmaddy avatar image rmaddy Kevin Windrem commented ·

That's how I've been "cleanly" shutting down my RPi too.

For reboot PageSettingsGeneral.qml has a call to vePlatform.reboot(). I tried calling vePlatform.halt() and shutdown() but neither worked. I was hoping to find the list of APIs supported by that vePlatform or a way to add to it. But I don't think that code is on GitHub.

0 Likes 0 ·
deadrabbit avatar image
deadrabbit answered ·

Hi,


i am new to Venus OS. I'm running Venus OS on a Raspberry 3b+.


I disconnect during winter season the battery from my van via a main switch.


Therefore i want to shut down the Rpi gracefully.


I found, that this can be done with

dtoverlay=gpio-shutdown

in /u-boot/config.txt.


But it is not working. Did someone know, if this is implemented in VenusOS?


BW

5 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

deadrabbit avatar image deadrabbit commented ·

Hi,


i was able to get a little bit further installing a shutdown button.

What i've done:

1. Add an additional GPIO pin to /etc/venus/gpio.list

# Digital input 6   Pin 24 / GPIO 8
8 in digital_input_6

I've chosen GPIO 8, because there is a internal pullup activated. Internal pullups are also available for other GPIOs, but i was not able to find out, how to activate them.

2. Create a shutdown script which is polling on /sys/class/gpio/value

#!/bin/bash
# monitor GPIO pin X for shutdown signal
# export GPIO pin X and set to input with pull-up

GPIOPIN=8

# echo "$GPIOPIN" > /sys/class/gpio/export
# echo "in" > /sys/class/gpio/gpio$GPIOPIN/direction

# wait for pin to go low
while [ true ] ; do
if [ "$(cat /sys/class/gpio/gpio$GPIOPIN/value)" == '0' ] ; then
echo "Raspberry Pi Shutting Down!"
shutdown -h now
exit 0
fi
sleep 1
done

Make the script executable with chmod +x gpioshutdown.sh and run it.


If i connect GPIO 8 (PIN 24) to GND, the RPI is shutting down.


Now i'm struggling to get the script run on every startup. Any hints are welcome.


BW


0 Likes 0 ·
Show more comments
Kevin Windrem avatar image
Kevin Windrem answered ·

I was able to create a shutdown mechanism for Venus OS.

https://github.com/kwindrem/ShutdownMonitor

This should work on any GX device platform but is intended to give Raspberry PI users a clean shutdown as suggested in several RPI forums. I have not noticed any ill effects from simply removing power so it's a personal choice.

I have tested this on a Raspberry PI 4 and on a Cerbo. The PI stays shut down but Cerbo reboots itself after a few minutes!!!

The relay to digital input kludge I described above is no longer needed. If you have installed this kludge, you should uninstall RpiGpioSetup, update it to the latest version then reinstall it before installing ShutdownMonitor. SetupHelper is also required in order to install ShutdownMonitor.

https://github.com/kwindrem/SetupHelper

1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

powerace avatar image powerace commented ·

Hi @Kevin Windrem


I've tried to install above ShutdownMonitor on my RPI 3B+ running Venus v2.73 using the manual option from the SetupHelper menu. Unfortunately the menu option to shutdown the RPI under General>Shutdown does not appear (not even after reboot). 2.jpg

Am i doing something wrong here? The following versions of your software have been installed:1.jpg

I've copied some lines from the log in attached file in case that helps to find what the issue can be.

Further more thanks for all of your nice work for this community!log.txt

0 Likes 0 ·
2.jpg (42.4 KiB)
1.jpg (39.7 KiB)
log.txt (3.5 KiB)
Kevin Windrem avatar image
Kevin Windrem answered ·

I attempted an install via SetupHelper/setup and the p option and it worked on my RPI 4 system running v2.73. Worked fine. Logs don't indicate an issue.

Try running /data/ShutdownMonitor/setup. This bypasses the packageInstaller from SetupHelper.

1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

powerace avatar image powerace commented ·
That was the solution Kevin! The option to shutdown the RPI is visible in the menu now, will check if it really works later when i have physical access to my Pi ;-)
0 Likes 0 ·

Related Resources

Victron Venus OS Open Source intro page

Venus OS GitHub (please do not post to this)

Additional resources still need to be added for this topic

Raspberry Pi running Victron’s Venus firmware - Blog Post

Venus OS Large image: Signal K and Node-RED - Install

raspberrypi install venus image


Experiments, Modifications and Adaptions. Mods (Modifications) can be made to Victron Software by the Community. Please use the modifications space for enthusiasts who want to push what is possible, without official Victron Support.