FORUMS

Galaxy S6 Weekly Shooting Challenge

Over in our forums this weekend, XDA Forum member DevonSloan has started a thread for talented … more

Which Features from Apple Watch Do You Think Android Wear Will Copy?

The Apple Watch and Android Wear are both growing platforms. Now … more

XDA Picks: Best Apps of the Week (May 15 – 22)

Apps are at the front and center of any smartphone experience, and with over a … more

Android 5.1 for the Nvidia Shield Tablet is Out!

Nvidia is quite good at delivering updates in a timely fashion. The producer of famous … more
Post Reply Subscribe to Thread Email Thread

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

27th September 2011, 06:07 PM |#1  
xak944's Avatar
OP Senior Member
Flag North Carolina
Thanks Meter: 174
 
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 & Moderator Committees / OEM Relations / XDA Portal Team - Harbinger of Doom
Flag Gallifrey
Thanks Meter: 4,723
 
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: 174
 
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: 223
 
More
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
 
More
>> 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
 
More
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
 
Donate to Me
More
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: 30
 
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
Senior Member
Flag NOR CAL
Thanks Meter: 1,566
 
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