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


Basil Gunn
 

Some links for the previous post:

nixtracker source with picture of radio/rpi setup before final install.
https://github.com/n7nix/nixtracker

nixtracker install script with graceful shutdown example in updown_log.sh
https://github.com/nwdigitalradio/n7nix/tree/master/tracker

nixtracker thread on groups.io
https://nw-digital-radio.groups.io/g/udrc/topic/70085931#4384


Basil Gunn <basil@pacabunga.com> writes:

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


K3VIN
 

On Fri, Feb 5, 2021 at 11:25 AM, Basil Gunn wrote:
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.
Old post, but at what voltage does the hat shutdown everything down?

Kevin, K3VIN


Basil Gunn
 

at what voltage does the hat shutdown everything down?
In the N7NIX repo there is a script for the RPi/DRAWS setup that runs in
my truck.

https://github.com/nwdigitalradio/n7nix/blob/master/tracker/updown_log.sh

That script runs once a minute from a cron job and reads the A/D
converter on DRAWS connected to 12V. If the voltage is less than 13V I
know my truck is not running and the battery is not being charged. At
that point I do an APRS beacon, wait for 20 seconds and then do an RPi
shutdown.

shutdown -h now

The beacon includes the value of the 12V A/D converter and the GPS
satellite count.

I use a powerwerx ITS-12
https://powerwerx.com/automotive-dc-timer-lvd-battery-guard
set to 1 which will disconnect power 2 minutes after the truck has been
shut off.

I have a picture of my setup here:
https://github.com/n7nix/nixtracker/blob/master/README.md

K3VIN <ka8yiu@mail.com> writes:

On Fri, Feb 5, 2021 at 11:25 AM, Basil Gunn wrote:


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.
Old post, but at what voltage does the hat shutdown everything down?

Kevin, K3VIN