Backup+ Lets You Backup Your App Data on Android Lollipop

Even though Android 5.0 Lollipop hasn’t yet seen its official release, quite … more

TechTalk Compiles All the Android News You Need in One App

If you’re as obsessed with mobile devices as the vast majority of our forum … more

Android App Review: Google Inbox to Improve Your Life – XDA TV

Recently, Google+ exploded with the announcement of Google Inbox, as … more

Damp the LG G3 Thermal Throttling

As our mobile devices grow thinner and more powerfulwith each passing generation, it’s inevitable … more
Post Reply

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

OP xak944

27th September 2011, 06:07 PM   |  #1  
xak944's Avatar
OP Senior Member
Flag North Carolina
Thanks Meter: 162
 
365 posts
Join Date:Joined: Jun 2010
More
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
Last edited by xak944; 27th September 2011 at 06:14 PM.
The Following 10 Users Say Thank You to xak944 For This Useful Post: [ View ]
28th September 2011, 03:13 AM   |  #2  
jerdog's Avatar
Developer Committee / OEM Relations / XDA Portal Team - Harbinger of Doom
Flag Gallifrey
Thanks Meter: 4,275
 
6,007 posts
Join Date:Joined: May 2007
More
While a nice piece of work - this is not development. It is an App. Moving to the appropriate section.
28th September 2011, 03:19 AM   |  #3  
xak944's Avatar
OP Senior Member
Flag North Carolina
Thanks Meter: 162
 
365 posts
Join Date:Joined: Jun 2010
More
Quote:
Originally Posted by jerdog

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.
28th September 2011, 03:28 AM   |  #4  
Senior Member
Thanks Meter: 203
 
1,542 posts
Join Date:Joined: Aug 2010
Quote:
Originally Posted by xak944

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?
28th September 2011, 11:22 AM   |  #5  
NeoA's Avatar
Member
Flag Bangalore
Thanks Meter: 6
 
30 posts
Join Date:Joined: Feb 2011
>> 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
The Following User Says Thank You to NeoA For This Useful Post: [ View ]
28th September 2011, 11:57 AM   |  #6  
Junior Member
Thanks Meter: 0
 
23 posts
Join Date:Joined: 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.
28th September 2011, 02:23 PM   |  #8  
Senior Member
Thanks Meter: 409
 
212 posts
Join Date:Joined: Apr 2010
Donate to Me
Very good work man keep it up
28th September 2011, 10:38 PM   |  #9  
here.david's Avatar
Senior Member
Flag Sonoma, CA
Thanks Meter: 29
 
414 posts
Join Date:Joined: Jan 2009
More
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
28th September 2011, 11:03 PM   |  #10  
BLOWNCO's Avatar
Recognized Contributor
Flag NOR CAL
Thanks Meter: 1,566
 
1,806 posts
Join Date:Joined: May 2007
Donate to Me
More
doesn't this do the same thing



https://market.android.com/details?i...=search_result

Post Reply Subscribe to Thread

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

Advanced Search
Display Modes