Is the power source exposed to the OS?
#5
Hi Seal,

Yes there is a very easy way. Just create a small script and use the following (sysfs) items:

Current battery power level in percentage 0-100% full
/sys/class/power_supply/battery/capacity

Indicating if we are operation on battery or power supply (Kernel AC power looks a bit strange, but it does mean the DC input)
0 = Battery, 1 = DC input (main power)
/sys/class/power_supply/ac/present

Use `shutdown 0` in your script to shutdown.

With the information above you should be able to create a small bash script checking the battery level in
order to do a safety fast shutdown. Or use a countdown (for example. 120 seconds) and wait for power
to come back so bufferring small power outages. Dont forget to put the jumper on battery and if your script
works well you should be able to handle power restores (during shutdown delay , complete shutdowns
and auto boot up when power restores.

And if you want a lot more information just take a look at the sysfs items in:
/sys/class/axppower/
You can get all sorts of information, like battery temperature, charge current, etc.


Messages In This Thread
Is the power source exposed to the OS? - by seal - 07-19-2019, 05:43 PM
RE: Is the power source exposed to the OS? - by pkfpeters - 07-20-2019, 12:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  power usage for Pine64 LTS + Screen Little_Johnny 1 2,974 02-17-2021, 07:19 PM
Last Post: Little_Johnny

Forum Jump:


Users browsing this thread: 2 Guest(s)