jondallimore
Posts: 214
Joined: Thu Aug 04, 2016 11:02 pm

Battery Uptime

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?

User avatar
diogen151
Posts: 28
Joined: Mon Apr 04, 2016 8:32 am
Location: Agram

Re: Battery Uptime

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.
comments >/dev/null ;-)

W. H. Heydt
Posts: 10982
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: Battery Uptime

Sun Oct 20, 2019 10:34 pm

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.

deepo
Posts: 187
Joined: Sun Dec 30, 2018 8:36 pm

Re: Battery Uptime

Mon Oct 21, 2019 6:31 am

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

deepo
Posts: 187
Joined: Sun Dec 30, 2018 8:36 pm

Re: Battery Uptime

Mon Oct 21, 2019 6:36 am

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

User avatar
clicky
Posts: 405
Joined: Thu Oct 25, 2012 7:34 am

Re: Battery Uptime

Mon Oct 21, 2019 9:59 am

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 :)

jondallimore
Posts: 214
Joined: Thu Aug 04, 2016 11:02 pm

Re: Battery Uptime

Mon Oct 21, 2019 10:21 am

bash script with cronjob works.
running the battery down is fine, it has protection built in.
thanks

User avatar
RaTTuS
Posts: 10484
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: Battery Uptime

Mon Oct 21, 2019 10:23 am

sudo apt install uptimed
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

wildfire
Posts: 542
Joined: Sat Sep 03, 2016 10:39 am
Location: Dundee, Scotland

Re: Battery Uptime

Mon Oct 21, 2019 11:45 am

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?
E8 85 A2 64 C9 64 81 94 64 81 95 64 89 84 89 96 A3
Still NF Shirls

Return to “General discussion”