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 ·
Show more comments
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 ·
Kevin Windrem avatar image Kevin Windrem deadrabbit commented ·

Excellent work.

You can easily make this a "service". Services are started during the boot process, restart if they quit and optionally provide a log file.

A service is created by placing a directory in /service that contains a run script, a log directory with it's own run script. The easiest way to make your own service is to copy one of the existing service directories and change the lines in the run file to execute your shutdown script.

Anything you write to the console (like echo commands that aren't redirected) will be written to the log file.

Note that as of v2.80, /service is an overlay from /opt/victronenergy/service, so you want to place your new service in that location, not /service. Anything you put in /service will not survive a reboot.

Also not that any mods you make to the service directory won't survive a firmware update so you need to reinstall it after reboot. Alternatively, you can add code to /data/rc.local to reinstall you mods. This code should avoid reinstalling with each reboot.

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

By default the first 8 GPIO pins are pull ups and the remaining are pull downs. This can be changed with a Device Tree Overlay. See:

https://github.com/kwindrem/RpiGpioSetup

GPIO 8 is used by SPI which could interfere with additions like a CANbus or serial hat. It would be better to pick a pin not used by Venus (which you have done) but also not assigned to other functions (SPI, UART, PCM): GPIO 12, GPIO 13, GPIO 16, GPIO 25. These are pull-downs by default and my overlay would need to be modified to make them pull-ups.

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

Based on the work by @deadrabbit, I added the script and a shutdown command to the Settings / General menu. It's a bit of a kludge but does seem to work.

It's now an optional part of:

https://github.com/kwindrem/RpiGpioSetup

This mod creates a psudo digital input and a psudo relay output. These then get jumped together on the RPI GPIO header (pins 36 and 38). The input and output do not appear in the Venus menus and can not otherwise be controlled.

0 Likes 0 ·
deadrabbit avatar image deadrabbit Kevin Windrem commented ·
Hi Kevin,


thanks a lot for your implementation! I'm with you, it is a little bit kludge. I will see, if it is possible to work with a interrupt.


What you have done is really great! Thanks a lot again!


BW


0 Likes 0 ·
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.