From d403231821126efc1055b752e1047d9590a557be Mon Sep 17 00:00:00 2001 From: Travis Goodspeed Date: Wed, 29 Aug 2018 12:12:09 -0400 Subject: [PATCH] Final energytrace commits. #98 --- bin/batterylife.py | 42 ++++++++++++++++++++++++++++++++ firmware/Makefile | 7 +++--- firmware/energytrace-txt.gnuplot | 11 +++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100755 bin/batterylife.py create mode 100644 firmware/energytrace-txt.gnuplot diff --git a/bin/batterylife.py b/bin/batterylife.py new file mode 100755 index 0000000..9a49d15 --- /dev/null +++ b/bin/batterylife.py @@ -0,0 +1,42 @@ +#!/usr/bin/python3 + +## This is a quick little python script that takes the output of +## energytrace-util, averages the current consumption for all samples +## after ten seconds, and then predicts battery life from a 100mAH +## CR2016 battery. + +## Usage: et 60 | python3 batterylife.py + + +import sys; + +capacity=100 #mAH + +ampsum=0.0; +ampcount=0; + +#Ugly shotgun parser to ignore comments and early records. +for line in sys.stdin: + if line[0]=='#': + pass; + else: + words=line.split(); + time=float(words[0]); + amps=float(words[1]); + milliamps=amps*1000.0; + + #We only count after the first 10 seconds, as booting takes 5 seconds. + if time>10.0: + ampcount=ampcount+1; + ampsum=ampsum+amps; + +if ampcount>0: + ampavg=ampsum/(ampcount*1.0); + milliamp=ampavg*1000.0; + microamp=ampavg*1000000.0; + print("%f µA average consumption"%microamp); + hours=100/milliamp; + days=hours/24.0; + years=days/365.2425; + months=years*12.0; + print("%f months of CR2016 battery life."%months); diff --git a/firmware/Makefile b/firmware/Makefile index 82f5b4d..d7783cf 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -125,7 +125,8 @@ dump: energytrace.txt: goodwatch.hex sbwflash - et 30 > energytrace.txt - -energytrace.png: energytrace.txt energytrace.gnuplot + et 60 > energytrace.txt #This will take a minute. gnuplot energytrace.gnuplot + gnuplot energytrace-txt.gnuplot + ../bin/batterylife.py