Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.raspberry-pi > #25843

Re: Battery Powered Project

From Martin Gregorie <martin@mydomain.invalid>
Newsgroups comp.sys.raspberry-pi
Subject Re: Battery Powered Project
Date 2021-01-13 15:12 +0000
Organization A noiseless patient Spider
Message-ID <rtn2l1$hbh$2@dont-email.me> (permalink)
References <rtk3qv$1112$1@gioia.aioe.org> <rtkjd5$p68$1@dont-email.me> <rtmu74$ule$1@dont-email.me>

Show all headers | View raw


On Wed, 13 Jan 2021 13:56:52 +0000, The Natural Philosopher wrote:

> On 12/01/2021 16:40, Pancho wrote:
>> On 12/01/2021 12:14, Simple Simon wrote:
>>> I am working on a battery powered car and want the Pi to shut down
>>> automatically if the battery starts to go flat to try to prevent SD
>>> card corruption. I am a beginner to bash scripts! I will run this via
>>> crontab...
>>>
>>> #!/bin/bash powerstatus=$(vcgencmd get_throttled)
>>> if [ $powerstatus="throttled=0x1" ]
>>> then echo Under Voltage Detected - Shutting Down sudo halt else echo
>>> Voltage Normal fi
>>>
>>> Obviously it is not working!! Could someone correct and explain for me
>>> please.
>> 
>> Not being much help, but...
>> 
>> I'm aware of Under Voltage problems from entries in journalctl. It
>> seems to me that listening for events logged to journalctl would be a
>> pretty common thing to do. So common that there should be some standard
>> way of doing it. Some kind of standard Observer pattern on jounalctl.
>> Does anyone know of one?
>
One way to get a rapid notification of entries written to a log is the 
use 'tail' in a script. 

Running "sudo tail -f /var/log/messages" from a console shows you each 
message as it is written to /var/log/messages, so a script started a boot 
time to run with sufficient privilege to read those log entries could 
easily use tail to read messages as they are written and filter out the 
ones of interest with grep or awk and use them to , for instance force a 
clean shutdown on low battery, something like

#!/bin/bash
tail -f /var/log/messages | awk <<ENDPROG
/Under voltage/ {  shutdown -h NOW }
ENDPROG

In this example tail is reading the logfile and  piping messages into awk, 
which as running an awk script from a 'here document', i.e. the awk 
script is all the lines from the line after <<ENDPROG and before the 
'ENDPROG line. 

As messages are written to the logfile, tail reads and passes them to awk, 
which shuts the Pi down if it gets passed a line containing 'Under 
voltage' and ignores all other lines. Onve the script is written and 
tested, put it in /usr/local/bin

tail and awk (aka gawk) is a standard Linux utility that IIRC is 
installed by default as part of the Raspbian toolset. Its manpage is also 
its manual and describes the awk language - there's also an O'Reilly 
book, "sed & awk" that contains the awk language specification plus a 
tutorial with examples of doing quite complex things with it, such as 
building a sorted list of all the words in a document.

The stuff I've shown above is pretty much the standard way of running a 
process in the background iunder any flavour of Linux.

> Well that's just another problem with systemd.
>
Systemd isn't the issue here because the example script I've shown will 
run equally well under systemd or the old SysV init.

The only difference is in setting things up so the script gets launched 
at boot time. 

- Under systemd you'd define a service to manage it. 

- Under sysV init you'd write a control script, put that in /etc/init.d
  and then hack around with with the contents of the /etc/rc?.d
  directories to specify the runlevels at which its started and those at
  which its not.


-- 
--  
Martin    | martin at
Gregorie  | gregorie dot org

Back to comp.sys.raspberry-pi | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Battery Powered Project Simple Simon <please.dontspa@me.com> - 2021-01-12 12:14 +0000
  Re: Battery Powered Project Chris Green <cl@isbd.net> - 2021-01-12 12:40 +0000
    Re: Battery Powered Project Simple Simon <please.dontspa@me.com> - 2021-01-12 12:50 +0000
      Re: Battery Powered Project "A. Dumas" <alexandre@dumas.fr.invalid> - 2021-01-12 15:15 +0100
      Re: Battery Powered Project Theo <theom+news@chiark.greenend.org.uk> - 2021-01-12 21:43 +0000
        Re: Battery Powered Project Jan Panteltje <pNaOnStPeAlMtje@yahoo.com> - 2021-01-13 09:40 +0000
        Re: Battery Powered Project Jim H <invalid@invalid.invalid> - 2021-01-13 18:02 +0000
        Re: Battery Powered Project Joe <joe@jretrading.com> - 2021-01-13 22:04 +0000
          Re: Battery Powered Project Theo <theom+news@chiark.greenend.org.uk> - 2021-01-13 23:37 +0000
            Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-14 00:43 +0000
            Re: Battery Powered Project The Natural Philosopher <tnp@invalid.invalid> - 2021-01-14 03:59 +0000
            Re: Battery Powered Project Ahem A Rivet's Shot <steveo@eircom.net> - 2021-01-14 10:18 +0000
              Re: Battery Powered Project The Natural Philosopher <tnp@invalid.invalid> - 2021-01-14 11:04 +0000
                Re: Battery Powered Project Ahem A Rivet's Shot <steveo@eircom.net> - 2021-01-14 11:46 +0000
                Re: Battery Powered Project The Natural Philosopher <tnp@invalid.invalid> - 2021-01-14 12:21 +0000
                Re: Battery Powered Project Ahem A Rivet's Shot <steveo@eircom.net> - 2021-01-14 12:38 +0000
                Re: Battery Powered Project David Higton <dave@davehigton.me.uk> - 2021-01-14 14:17 +0000
                Re: Battery Powered Project The Natural Philosopher <tnp@invalid.invalid> - 2021-01-14 14:28 +0000
                Re: Battery Powered Project David Higton <dave@davehigton.me.uk> - 2021-01-16 20:09 +0000
                Re: Battery Powered Project The Natural Philosopher <tnp@invalid.invalid> - 2021-01-17 07:19 +0000
                Re: Battery Powered Project David Higton <dave@davehigton.me.uk> - 2021-01-17 15:57 +0000
                Re: Battery Powered Project The Natural Philosopher <tnp@invalid.invalid> - 2021-01-18 07:05 +0000
                Re: Battery Powered Project David Higton <dave@davehigton.me.uk> - 2021-01-18 14:14 +0000
                Re: Battery Powered Project John Aldridge <jpsa@cantab.net> - 2021-01-17 17:52 +0000
              Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-14 12:56 +0000
              Re: Battery Powered Project Theo <theom+news@chiark.greenend.org.uk> - 2021-01-14 13:46 +0000
                Re: Battery Powered Project The Natural Philosopher <tnp@invalid.invalid> - 2021-01-14 14:26 +0000
          Re: Battery Powered Project The Natural Philosopher <tnp@invalid.invalid> - 2021-01-14 03:46 +0000
            Re: Battery Powered Project Folderol <general@musically.me.uk> - 2021-01-14 09:23 +0000
              Re: Battery Powered Project The Natural Philosopher <tnp@invalid.invalid> - 2021-01-14 11:04 +0000
                Re: Battery Powered Project Folderol <general@musically.me.uk> - 2021-01-14 17:48 +0000
            Re: Battery Powered Project Jim H <invalid@invalid.invalid> - 2021-01-18 17:07 +0000
              Re: Battery Powered Project Joe <joe@jretrading.com> - 2021-01-18 20:33 +0000
                Re: Battery Powered Project Jim H <invalid@invalid.invalid> - 2021-01-21 20:36 +0000
  Battery Powered Project nospam.Vincent.Coen@f1.n250.z2.binkp.net (Vincent Coen) - 2021-01-12 14:35 +1300
  Re: Battery Powered Project Pancho <Pancho.Dontmaileme@outlook.com> - 2021-01-12 16:40 +0000
    Re: Battery Powered Project The Natural Philosopher <tnp@invalid.invalid> - 2021-01-13 13:56 +0000
      Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-13 15:12 +0000
        Re: Battery Powered Project Pancho <Pancho.Dontmaileme@outlook.com> - 2021-01-16 12:24 +0000
          Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-16 17:53 +0000
            Re: Battery Powered Project Pancho <Pancho.Dontmaileme@outlook.com> - 2021-01-16 20:39 +0000
              Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-16 22:33 +0000
                Re: Battery Powered Project Pancho <Pancho.Dontmaileme@outlook.com> - 2021-01-16 23:30 +0000
                Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-16 23:52 +0000
                Re: Battery Powered Project Pancho <Pancho.Dontmaileme@outlook.com> - 2021-01-17 10:39 +0000
                Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-17 14:32 +0000
                Re: Battery Powered Project Pancho <Pancho.Dontmaileme@outlook.com> - 2021-01-18 13:20 +0000
                Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-18 13:41 +0000
                Re: Battery Powered Project Pancho <Pancho.Dontmaileme@outlook.com> - 2021-01-18 14:02 +0000
                Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-18 15:15 +0000
                Re: Battery Powered Project Pancho <Pancho.Dontmaileme@outlook.com> - 2021-01-19 13:46 +0000
                Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-19 15:24 +0000
                Re: Battery Powered Project Pancho <Pancho.Dontmaileme@outlook.com> - 2021-01-19 15:34 +0000
                Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-19 16:21 +0000
                Re: Battery Powered Project Pancho <Pancho.Dontmaileme@outlook.com> - 2021-01-19 17:18 +0000
                Re: Battery Powered Project Richard Kettlewell <invalid@invalid.invalid> - 2021-01-19 19:31 +0000
                Re: Battery Powered Project Pancho <Pancho.Dontmaileme@outlook.com> - 2021-01-20 10:12 +0000
                Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-19 22:15 +0000
                Re: Battery Powered Project Pancho <Pancho.Dontmaileme@outlook.com> - 2021-01-20 10:03 +0000
                Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-20 10:49 +0000
                Re: Battery Powered Project Chris Elvidge <chris@mshome.net> - 2021-01-20 11:29 +0000
                Re: Battery Powered Project A. Dumas <alexandre@dumas.fr.invalid> - 2021-01-20 12:18 +0000
                Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-20 13:02 +0000
                Re: Battery Powered Project Pancho <Pancho.Dontmaileme@outlook.com> - 2021-01-20 15:49 +0000
                Re: Battery Powered Project Richard Kettlewell <invalid@invalid.invalid> - 2021-01-20 16:54 +0000
                Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-20 17:19 +0000
                Re: Battery Powered Project Pancho <Pancho.Dontmaileme@outlook.com> - 2021-01-21 10:24 +0000
                Re: Battery Powered Project A. Dumas <alexandre@dumas.fr.invalid> - 2021-01-20 12:18 +0000
                Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-20 13:18 +0000
                Re: Battery Powered Project Chris Elvidge <chris@mshome.net> - 2021-01-20 14:14 +0000
                Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-20 14:51 +0000
                Re: Battery Powered Project A. Dumas <alexandre@dumas.fr.invalid> - 2021-01-20 14:45 +0000
                Re: Battery Powered Project A. Dumas <alexandre@dumas.fr.invalid> - 2021-01-20 14:44 +0000
                Re: Battery Powered Project Richard Kettlewell <invalid@invalid.invalid> - 2021-01-20 15:07 +0000
                Re: Battery Powered Project "A. Dumas" <alexandre@dumas.fr.invalid> - 2021-01-20 16:38 +0100
                Re: Battery Powered Project Chris Elvidge <chris@mshome.net> - 2021-01-20 15:45 +0000
                Re: Battery Powered Project druck <news@druck.org.uk> - 2021-01-21 10:07 +0000
                Re: Battery Powered Project "A. Dumas" <alexandre@dumas.fr.invalid> - 2021-01-21 12:30 +0100
                Re: Battery Powered Project druck <news@druck.org.uk> - 2021-01-21 13:09 +0000
                Re: Battery Powered Project Anssi Saari <as@sci.fi> - 2021-01-22 10:08 +0200
                Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-22 10:29 +0000
                Re: Battery Powered Project Chris Green <cl@isbd.net> - 2021-01-22 10:25 +0000
                Re: Battery Powered Project Kees Nuyt <k.nuyt@nospam.demon.nl> - 2021-01-19 17:03 +0100
                Re: Battery Powered Project A. Dumas <alexandre@dumas.fr.invalid> - 2021-01-17 01:09 +0000
            Re: Battery Powered Project Chris Elvidge <chris@mshome.net> - 2021-01-17 11:48 +0000
              Re: Battery Powered Project Pancho <Pancho.Dontmaileme@outlook.com> - 2021-01-17 12:11 +0000
              Re: Battery Powered Project Martin Gregorie <martin@mydomain.invalid> - 2021-01-17 14:43 +0000
            Re: Battery Powered Project Chris Elvidge <chris@mshome.net> - 2021-01-17 11:52 +0000
              Re: Battery Powered Project Andy Burns <usenet@andyburns.uk> - 2021-01-17 13:53 +0000

csiph-web