]> pere.pagekite.me Git - homepage.git/commitdiff
Prepare for a new post.
authorPetter Reinholdtsen <pere@hungry.com>
Thu, 24 Sep 2015 10:51:18 +0000 (12:51 +0200)
committerPetter Reinholdtsen <pere@hungry.com>
Thu, 24 Sep 2015 10:51:18 +0000 (12:51 +0200)
blog/data/2015-09-24-laptop-battery.txt [new file with mode: 0644]
blog/images/2015-09-24-laptop-battery-graph.png [new file with mode: 0644]

diff --git a/blog/data/2015-09-24-laptop-battery.txt b/blog/data/2015-09-24-laptop-battery.txt
new file mode 100644 (file)
index 0000000..9630b18
--- /dev/null
@@ -0,0 +1,108 @@
+Title: The Life and death of a laptop battery
+Tags: english
+Date: 2015-09-24 20:00
+
+<p>When I get a new laptop, the battery life time of the lap top at
+the start is OK.  But this do not last.  I got a feeling that within a
+year, the life time is just a fraction of what it used to be, and it
+slowly become painful to use the laptop without power connected to it.
+Because of this, when I got a new Thinkpad X230 laptop almost two
+years ago, I decided to monitor its state to have more hard facts when
+the battery started to fail.</p>
+
+<p>First I tried to find a sensible Debian package to record the
+battery status, assuming that this must be a problem already handled
+by someone else.  I found
+<ahref="https://tracker.debian.org/pkg/battery-stats">battery-stats</a>,
+which collects statistics from the battery, but it was completely
+broken.  I sent a few suggestions to the maintainer, but decided to
+write my own collector as a shell script while I waited for feedback
+from him.  Via
+<ahref="http://www.ifweassume.com/2013/08/the-de-evolution-of-my-laptop-battery.html">a
+blog post about the battery development on a MacBook Air</a> I also
+discovered
+<ahref="https://github.com/jradavenport/batlog.git">batlog</a>, not
+available in Debian.</p>
+
+<p>I started my collector 2013-07-15, and it has been collecting
+battery stats ever since. Now my
+/var/log/hjemmenett-battery-status.log file contain around 115,000
+measurements, from the time the battery was working great until now,
+when it is unable to charge above 7% of original capasity.  My
+colletor shell script look like this:</p>
+
+<pre>
+#!/bin/sh
+# Inspired by
+# http://www.ifweassume.com/2013/08/the-de-evolution-of-my-laptop-battery.html
+# See also
+# http://blog.sleeplessbeastie.eu/2013/01/02/debian-how-to-monitor-battery-capacity/
+logfile=/var/log/hjemmenett-battery-status.log
+
+files="manufacturer model_name technology serial_number \
+    energy_full energy_full_design energy_now cycle_count status"
+
+if [ ! -e "$logfile" ] ; then
+    (
+       printf "timestamp,"
+       for f in $files; do
+           printf "%s," $f
+       done
+       echo
+    ) > "$logfile"
+fi
+
+log_battery() {
+    # Print complete message in one echo call, to avoid race condition
+    # when several log processes run in parallell.
+    msg=$(printf "%s," $(date +%s); \
+       for f in $files; do \
+           printf "%s," $(cat $f); \
+       done)
+    echo "$msg"
+}
+
+cd /sys/class/power_supply
+
+for bat in BAT*; do
+    (cd $bat && log_battery >> "$logfile")
+done
+</pre>
+
+<p>The script is called when the power management system detect a
+change in the power status (power plug in or out), and when going into
+and out of hibernation and suspend.  In addition, it collect a value
+every 10 minutes.  This make it possible for me know when the battery
+is discharging, charging and how the maximum charge change over
+time.  The log file look like this:</p>
+
+<pre>
+timestamp,manufacturer,model_name,technology,serial_number,energy_full,energy_full_design,energy_now,cycle_count,status,
+1376591133,LGC,45N1025,Li-ion,974,62800000,62160000,39050000,0,Discharging,
+[...]
+1443090528,LGC,45N1025,Li-ion,974,4900000,62160000,4900000,0,Full,
+1443090601,LGC,45N1025,Li-ion,974,4900000,62160000,4900000,0,Full,
+</pre>
+
+<p>I even wrote a small script to create a graph of the charge
+development over time.  This show the slow death of my Lenovo Thinkpad
+X230 laptop battery:</p>
+
+<img src="images/2015-09-24-laptop-battery-graph.png"/>
+
+<p>But why is this happening?  Why are my laptop batteries dying,
+while the batteries of space probes and satellites keep working year
+after year.  If we are to believe
+<ahref="http://batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries">Battery
+University</a>, the fix is to not charge the Lithium-ion batteries to
+100% all the time, but to stay below 90% of full charge most of the
+time.  I've been told that the Tesla electric cars
+<ahref="http://my.teslamotors.com/de_CH/forum/forums/battery-charge-limit">limit
+the charge of their batteries to 80%</a>, with the option to charge to
+100% when preparing for a longer trip (not that I would want a Tesla,
+but that is another story), which I guess is the option we should have
+for laptops on Linux too.</p>
+
+<p>Is there a way with Linux to tell the battery to stop charging at
+80%, unless requested to charge to 100% once in preparation for a
+longer trip?</p>
diff --git a/blog/images/2015-09-24-laptop-battery-graph.png b/blog/images/2015-09-24-laptop-battery-graph.png
new file mode 100644 (file)
index 0000000..9c45e4d
Binary files /dev/null and b/blog/images/2015-09-24-laptop-battery-graph.png differ