5,600,612 Members 33,396 Now Online
XDA Developers Android and Mobile Development Forum

[SHELL SCRIPT] Battery logging (discharge, capacity, etc)

Tip us?
 
xak944
Old
(Last edited by xak944; 27th September 2011 at 06:14 PM.)
#1  
xak944's Avatar
Senior Member - OP
Thanks Meter 159
Posts: 365
Join Date: Jun 2010
Location: North Carolina
Lightbulb [SHELL SCRIPT] Battery logging (discharge, capacity, etc)

After seeing apps like Android Battery Monitor, I wanted something I could run in a shell (adb) that would give me similar statistics, namely the battery discharge rate. I couldn't find any such tools or scripts, so I wrote one. Hopefully it will be useful to someone else, too.

The file paths are hard coded, and will likely only work on the Samsung Epic 4G Touch, however it could probably be easily adapted to other devices as well. It also probably requires busybox, since it uses some basic shell programs.

The script will output statistics every second, like this:
Code:
[DATE]|[TIME]|[DISCHARGE]|[CHARGE%]|[CHARGEMV]|[BATTTEMP]
2011/09/27|13:03:18|+0mA|92%|4101mV|31C
2011/09/27|13:03:19|+0mA|92%|4101mV|31C
2011/09/27|13:03:20|+0mA|92%|4101mV|31C
2011/09/27|13:03:21|-83mA|92%|4018mV|32C
2011/09/27|13:03:22|+0mA|92%|4018mV|32C
2011/09/27|13:03:23|+0mA|92%|4018mV|32C
2011/09/27|13:03:24|+0mA|92%|4018mV|32C
2011/09/27|13:03:25|+0mA|92%|4018mV|32C
2011/09/27|13:03:26|+0mA|92%|4018mV|32C
2011/09/27|13:03:27|+0mA|92%|4018mV|32C
2011/09/27|13:03:28|+0mA|92%|4018mV|32C
2011/09/27|13:03:29|+0mA|92%|4018mV|32C
2011/09/27|13:03:30|+45mA|92%|4063mV|32C
Here's the script:
Code:
INTERVAL=1

CAPACITYVOLTAGE=0
while true; do
  PREVVOLTAGE=$CAPACITYVOLTAGE
  DATETIME=$(date +'%Y/%m/%d|%H:%M:%S')
  CAPACITYVOLTAGE="$(( $(cat /sys/devices/platform/sec-battery/power_supply/battery/voltage_now) / 1000 ))"
  CAPACITYPERCENT="$(cat /sys/devices/platform/sec-battery/power_supply/battery/capacity)"
  DISCHARGE="+$(( $CAPACITYVOLTAGE - $PREVVOLTAGE ))"
  TEMP="$(( $(cat /sys/devices/platform/sec-battery/power_supply/battery/batt_temp) / 10 ))"


  echo "${DATETIME}|$(echo ${DISCHARGE}|sed -e 's/^+-/-/')mA|${CAPACITYPERCENT}%|${CAPACITYVOLTAGE}mV|${TEMP}C"

  sleep ${INTERVAL}
done
Samsung Galaxy Note II (SGH-T889) + JellyBeer (CM10.1)
T-Mobile Prepaid and/or AT&T Postpaid "TWO-YEAR CONTRACTS ARE EVIL!"

History: Palm III → Palm IIIxe → Palm Vx → Handspring Visor Prism → Sony CLI NR-70V → Palm TX → iPhone 3G+jb → iPhone 3GS+jb → HTC Evo 4G+CM7 → Samsung Galaxy S2+CM10

If I've helped you, then please DON'T press the thanks button for those who begs for it. It's very annoying.
The Following 10 Users Say Thank You to xak944 For This Useful Post: [ Click to Expand ]
 
jerdog
Old
#2  
jerdog's Avatar
Developer Committee / OEM Relations / XDA News Writer - Harbinger of Doom
Thanks Meter 3898
Posts: 5,604
Join Date: May 2007
Location: Gallifrey; Likes: Family,XDA,Android; Dislikes:Self-Entitled Twits
While a nice piece of work - this is not development. It is an App. Moving to the appropriate section.


 

Quote:
Notify your physician if after exposure to XDA n00bs you experience any of the following symptoms: rapid or irregular heartbeat, chest pain, shortness of breath, leg cramps, headache, nervousness, irritability, sleeplessness, tremors, change in appetite, weight gain or loss, vomiting, diarrhea, excessive sweating, heat intolerance, fever, changes in menstrual periods, hives or skin rash, or any other unusual medical event.

BTC: 131x7i37dEsDmQpy1T1tz34Mc8wtRUHuoa
 
xak944
Old
#3  
xak944's Avatar
Senior Member - OP
Thanks Meter 159
Posts: 365
Join Date: Jun 2010
Location: North Carolina
Quote:
Originally Posted by jerdog View Post
While a nice piece of work - this is not development. It is an App. Moving to the appropriate section.
Well, I was hoping to get some feedback and make some improvements before calling it an app, but that works.
Samsung Galaxy Note II (SGH-T889) + JellyBeer (CM10.1)
T-Mobile Prepaid and/or AT&T Postpaid "TWO-YEAR CONTRACTS ARE EVIL!"

History: Palm III → Palm IIIxe → Palm Vx → Handspring Visor Prism → Sony CLI NR-70V → Palm TX → iPhone 3G+jb → iPhone 3GS+jb → HTC Evo 4G+CM7 → Samsung Galaxy S2+CM10

If I've helped you, then please DON'T press the thanks button for those who begs for it. It's very annoying.
 
nabbed
Old
#4  
Senior Member
Thanks Meter 195
Posts: 1,481
Join Date: Aug 2010
Quote:
Originally Posted by xak944 View Post
After seeing apps like Android Battery Monitor, I wanted something I could run in a shell (adb) that would give me similar statistics, namely the battery discharge rate. I couldn't find any such tools or scripts, so I wrote one. Hopefully it will be useful to someone else, too.

The file paths are hard coded, and will likely only work on the Samsung Epic 4G Touch, however it could probably be easily adapted to other devices as well. It also probably requires busybox, since it uses some basic shell programs.

The script will output statistics every second, like this:
Code:
[DATE]|[TIME]|[DISCHARGE]|[CHARGE%]|[CHARGEMV]|[BATTTEMP]
2011/09/27|13:03:18|+0mA|92%|4101mV|31C
2011/09/27|13:03:19|+0mA|92%|4101mV|31C
2011/09/27|13:03:20|+0mA|92%|4101mV|31C
2011/09/27|13:03:21|-83mA|92%|4018mV|32C
2011/09/27|13:03:22|+0mA|92%|4018mV|32C
2011/09/27|13:03:23|+0mA|92%|4018mV|32C
2011/09/27|13:03:24|+0mA|92%|4018mV|32C
2011/09/27|13:03:25|+0mA|92%|4018mV|32C
2011/09/27|13:03:26|+0mA|92%|4018mV|32C
2011/09/27|13:03:27|+0mA|92%|4018mV|32C
2011/09/27|13:03:28|+0mA|92%|4018mV|32C
2011/09/27|13:03:29|+0mA|92%|4018mV|32C
2011/09/27|13:03:30|+45mA|92%|4063mV|32C
Here's the script:
Code:
INTERVAL=1

CAPACITYVOLTAGE=0
while true; do
  PREVVOLTAGE=$CAPACITYVOLTAGE
  DATETIME=$(date +'%Y/%m/%d|%H:%M:%S')
  CAPACITYVOLTAGE="$(( $(cat /sys/devices/platform/sec-battery/power_supply/battery/voltage_now) / 1000 ))"
  CAPACITYPERCENT="$(cat /sys/devices/platform/sec-battery/power_supply/battery/capacity)"
  DISCHARGE="+$(( $CAPACITYVOLTAGE - $PREVVOLTAGE ))"
  TEMP="$(( $(cat /sys/devices/platform/sec-battery/power_supply/battery/batt_temp) / 10 ))"


  echo "${DATETIME}|$(echo ${DISCHARGE}|sed -e 's/^+-/-/')mA|${CAPACITYPERCENT}%|${CAPACITYVOLTAGE}mV|${TEMP}C"

  sleep ${INTERVAL}
done
1) How does one install the script?
2) How does one uninstall it?
3) How much does the script affect battery performance?
4) How stable is the script?
5) What makes this script better than other similar apps in the market?
 
NeoA
Old
#5  
NeoA's Avatar
Member
Thanks Meter 6
Posts: 30
Join Date: Feb 2011
Location: Bangalore
>> 1) How does one install the script?
You don't. Just move it to an appropriate location on your phone via adb push command, change permissions to make executable & run it. It does not involve any formal installation/removal.

>> 3) How much does the script affect battery performance?
Neglible. even if you launched from a terminal emulator on-board your phone & not while it was connected via the USB to your computer

>> 4) How stable is the script?
Fairly since its quite simple. He is only reading those ascii files available on any typical linux based system & printing to console after some post-processing
Samsung Galaxy S3: stock Jelly Bean
Kindle Fire HDX 7 - rooted, SafeStrap
The Following User Says Thank You to NeoA For This Useful Post: [ Click to Expand ]
 
Futurian
Old
#6  
Junior Member
Thanks Meter 0
Posts: 21
Join Date: Jan 2007
Been interested in looking at what I can get my rooted device to do via Terminal/SSH, this is a great start Had to edit it a bit for my desire Z, however working a treat.. The script can lag a little if I use it via SSH with the screen off, however to be expected I suppose. A little Caffeine and it completely works as expected.

Code:
INTERVAL=1

CAPACITYVOLTAGE=0
while true; do
  PREVVOLTAGE=$CAPACITYVOLTAGE
  DATETIME=$(date +'%Y/%m/%d|%H:%M:%S')
  CAPACITYVOLTAGE="$(cat /sys/devices/platform/rs30100001:00000000/power_supply/battery/batt_vol)"
  CAPACITYPERCENT="$(cat /sys/devices/platform/rs30100001:00000000/power_supply/battery/capacity)"
  DISCHARGE="+$(( $CAPACITYVOLTAGE - $PREVVOLTAGE ))"
  TEMP="$(( $(cat /sys/devices/platform/rs30100001:00000000/power_supply/battery/batt_temp) / 10 ))"

  echo "${DATETIME}|$(echo ${DISCHARGE}|sed -e 's/^+-/-/')mA|${CAPACITYPERCENT}%|${CAPACITYVOLTAGE}mV|${TEMP}C"

  sleep ${INTERVAL}
done
I'm off to try and create something similar for the GPS.. No idea how feasible as yet, but appreciate the inspiration.
 
AdamOutler
Old
#7  
AdamOutler's Avatar
Recognized Developer
Thanks Meter 9429
Posts: 5,124
Join Date: Feb 2011
Location: Louisiana

 
DONATE TO ME
Nice job on this script.
Flash with Odin on Windows, Linux and Mac. Use JOdin3, Available in a web browser or offline
Check out my developer pages. Add me to your circles on Google Plus.
 
Jez2cool
Old
#8  
Senior Member
Thanks Meter 409
Posts: 212
Join Date: Apr 2010

 
DONATE TO ME
Very good work man keep it up
Buy Me a RedBull

HIT THE THANKS BUTTON
Visit ACS's new home at http://www.acsyndicate.net, and follow us on Twitter at @ACSyndicate!
 
here.david
Old
#9  
here.david's Avatar
Senior Member
Thanks Meter 29
Posts: 403
Join Date: Jan 2009
Location: Sonoma, CA
Default I had to edit it a bit for my Vibrant (Miui 9.23)

make file (I called mine "adb_batt.sh" placed it on my sdcard
I used Gscrip lite to run it (or terminal)
"sh ./mnt/sdcard/adb_batt.sh"
==================================

INTERVAL=1

CAPACITYVOLTAGE=0
while true; do
PREVVOLTAGE=$CAPACITYVOLTAGE
DATETIME=$(date +'%Y/%m/%d|%H:%M:%S')
CAPACITYVOLTAGE="$(( $(cat sys/devices/platform/i2c-gpio.6/i2c-6/6-0066/max8998-charger/power_supply/battery/voltage_now) / 1000 ))"
CAPACITYPERCENT="$(cat sys/devices/platform/i2c-gpio.6/i2c-6/6-0066/max8998-charger/power_supply/battery/capacity
)"
DISCHARGE="+$(( $CAPACITYVOLTAGE - $PREVVOLTAGE ))"
TEMP="$(( $(cat sys/devices/platform/i2c-gpio.6/i2c-6/6-0066/max8998-charger/power_supply/battery/batt_temp_check) / 10 ))"


echo "${DATETIME}|$(echo ${DISCHARGE}|sed -e 's/^+-/-/')mA|${CAPACITYPERCENT}%|${CAPACITYVOLTAGE}mV|${TE MP}C"

sleep ${INTERVAL}
done

Note 3 (March 2014)
Optimus G Pro E980 (Jul 2013)


T-Mobile Vibrant (Jul 2010)
Odin/Mini Kies are your Friends

THRIVE (Aug 2011)
T-mobile G1 (OCT 2008)
Use current Ubuntu on i7 960 & Win7 in VM for Odin

If I have helped you in any way, please click "Thanks" button at bottom right
 
BLOWNCO
Old
#10  
BLOWNCO's Avatar
Recognized Contributor
Thanks Meter 1539
Posts: 1,764
Join Date: May 2007
Location: NOR CAL

 
DONATE TO ME
doesn't this do the same thing



https://market.android.com/details?i...=search_result
BLOWNCO.COM
wallpapers/roms/mods/and more


Tags
adb, battery discharge, log, shell
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


TRENDING IN THEMER...