Hello Simple!
Tuesday January 12 2021 12:14, you wrote to All:
> 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.
You have another 2/3 possible issues :-
1. crontab will only run the script at the defined point of time so you need
to run it often OR better still as a subtask from a routine that WILL run if
the battery is low at a given point (not almost flat) to shutdown the system ,
NOTE the term shutdown by using similar to shutdown -h now and not halt which
may well not close down any processes running first and possbly cause
curruptions on your system disk / SD etc.
2. As a follow on from 1 , you need a low level process that is constantly
running say with a sleep of nn seconds that tests the battery state and if
good
sleeps or runs process similar to your bash script but not it and suggest say
a little C process as it would use less resources.
3. As a follow on from both of the above.
You should check what battery setting you have for throttled and have it set
to
at least 25% battery power if you have a lot of proceses that can be running
at
any one time and if needed a higher value.
I have a similar set of processes but linked to a APC UPS so see package
apcupsd.
Vincent
--- Mageia Linux v7.1 X64/Mbse v1.0.7.17/GoldED+/LNX 1.1.5-b20180707
* Origin: Air Applewood, The Linux Gateway to the UK & Eire (2:250/1)
|