Page 1 of 1

Battery Uptime

Posted: Sun Oct 20, 2019 8:55 pm
by jondallimore
Hello,

I'm testing a battery with a pi 3 - intention is to run it flat and see how long it will power the pi for.

Is there an easy way to see uptime on the pi AFTER the battery dies and I plug it into the mains again?

Re: Battery Uptime

Posted: Sun Oct 20, 2019 9:11 pm
by diogen151
Create a .sh procedure that will append (>>) output of "date" command to a previously created .txt file.
Also, create a crontab entry calling that .sh procedure every 10 minutes or less.
First and last entry into .txt file should be measured time period.
After rebooting you have less than 10 minutes to check file to avoid appending false entry.

Re: Battery Uptime

Posted: Sun Oct 20, 2019 10:34 pm
by W. H. Heydt
diogen151 wrote:
Sun Oct 20, 2019 9:11 pm
Create a .sh procedure that will append (>>) output of "date" command to a previously created .txt file.
Also, create a crontab entry calling that .sh procedure every 10 minutes or less.
First and last entry into .txt file should be measured time period.
After rebooting you have less than 10 minutes to check file to avoid appending false entry.
Add a sync command after every file write to be sure that the data goes to storage and doesn't sit around in memory where it will be lost when the power drops.

Re: Battery Uptime

Posted: Mon Oct 21, 2019 6:31 am
by deepo
diogen151 wrote:
Sun Oct 20, 2019 9:11 pm
Create a .sh procedure that will append (>>) output of "date" command to a previously created .txt file.
Also, create a crontab entry calling that .sh procedure every 10 minutes or less.
First and last entry into .txt file should be measured time period.
After rebooting you have less than 10 minutes to check file to avoid appending false entry.
I'd suggest adding output of uptime command along with output from date command, otherwise you may have trouble finding where a reboot has taken place.
If you set this to run every 10 minutes then you could squeeze in a few reboots in those 10 minutes and not be able to see that it happened.

/Mogens

Re: Battery Uptime

Posted: Mon Oct 21, 2019 6:36 am
by deepo
uptime.sh

Code: Select all

#!/bin/bash
echo $(date) - $(uptime) >> uptime.log
You may have to add a full path to where the log is to be.
Don't select a place that gets wiped at boot.

uptime.log

Code: Select all

Mon Oct 21 06:32:38 UTC 2019 - 06:32:38 up 9 days, 23:47, 1 user, load average: 1.05, 1.03, 1.05
I don't have a Raspberry Pi here, but you can get help on creating crontab entries here:
https://crontab-generator.org/

/Mogens

Re: Battery Uptime

Posted: Mon Oct 21, 2019 9:59 am
by clicky
jondallimore wrote:
Sun Oct 20, 2019 8:55 pm
Hello,

I'm testing a battery with a pi 3 - intention is to run it flat and see how long it will power the pi for.

Is there an easy way to see uptime on the pi AFTER the battery dies and I plug it into the mains again?
Running battery flat is usually a bad idea (for the battery). Maybe you should get something like https://www.adafruit.com/product/4226 and when you detect (save!) low voltage on the battery side do clean shutdown. Anyway - that's just an idea :)

Re: Battery Uptime

Posted: Mon Oct 21, 2019 10:21 am
by jondallimore
bash script with cronjob works.
running the battery down is fine, it has protection built in.
thanks

Re: Battery Uptime

Posted: Mon Oct 21, 2019 10:23 am
by RaTTuS
sudo apt install uptimed

Re: Battery Uptime

Posted: Mon Oct 21, 2019 11:45 am
by wildfire
jondallimore wrote:
Mon Oct 21, 2019 10:21 am
running the battery down is fine, it has protection built in.
But does your storage device?