HOW TO gracefully shutdown an RPi with DRAWS


Basil Gunn
 

From: Alex Archer - KC0REL

Does the hat allow the pi to be gracefully shutdown when attached to a
mobile setup directly wired to the battery when it detects a voltage
drop from alternator voltage to battery voltage only?
Yes 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

volt_int=$(echo "${voltage//[^0-9]/}")

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
fi

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:
https://nw-digital-radio.groups.io/g/udrc/topic/70085931#4456

I've been using this setup for over a year in my truck.

/Basil n7nix

From: "Alex Archer" <alex@aactrain.com>
Subject: DRAWS hat question
Date: February 4, 2021 at 3:24:59 PM PST

Does the hat allow the pi to be gracefully shutdown when attached to a
mobile setup directly wired to the battery when it detects a voltage
drop from alternator voltage to battery voltage only?

My mobile setup currently has everything running through an
APRSworld.com APO3 that automatically cuts power to everything
downstream of it 10 minutes after seeing the drop from alternator to
battery voltage. I'd like to have the ability to gracefully shut down
the pi, after say 9 minutes (thus before power is cut off by the APO
device), and the additional capabilities your hat provides interests
me, especially the ability to control 2 radios.

-- Alex Archer -
KC0REL alex@aactrain.com

Join udrc@nw-digital-radio.groups.io to automatically receive all group messages.