HOW TO gracefully shutdown an RPi with DRAWS
From: Alex Archer - KC0RELYes the DRAWS hat has everything required to do a graceful RPi shutdown.
It has an A/D converter that measures the 12V source voltage.
Periodically reading that voltage with cron you can detect when your
vehicle is turned off going from alternator to battery. There is an
example on how to do that in this script n7nix/tracker/updown_log.sh.
You read the output of 12V with the sensors command and
peel off the number you are interested in.
From a console run the "sensors" command to see the output you are
dealing with. From the updown_log.sh script the following line extracts
the 12V value.
voltage=$(sensors | grep -i "+12V:" | cut -d':' -f2 | sed -e 's/^[ \t]*//' | cut -d' ' -f1)
To do a compare in bash I want the voltage as an integer so I get rid of
the plus sign & decimal point
I use the volt_int value to detect when I need to gracefully shut down the RPi
if (( volt_int < 1300 )) ; then
sudo /sbin/shutdown -h now
Instead of an APO3 I use a Powerwerx ITS-12. For the APRS app I use a
fork of Dan Smith's dantracker which runs in a browser. In my vehicle
I run a hostap on the RPi and connect over WiFi so that I can use my
phone or tablet as a display.
There is a nixtracker thread here:
I've been using this setup for over a year in my truck.
From: "Alex Archer" <email@example.com>