]> pere.pagekite.me Git - homepage.git/blobdiff - blog/archive/2015/09/09.rss
Generated.
[homepage.git] / blog / archive / 2015 / 09 / 09.rss
index f7636daaa6ccbb909d752bbc9a3100746af27d9d..4d3f6ab26eb122cbbbf61ef35b9514f9a3e68434 100644 (file)
@@ -6,6 +6,137 @@
                 <link>http://people.skolelinux.org/pere/blog/</link>
 
        
+       <item>
+               <title>The life and death of a laptop battery</title>
+               <link>http://people.skolelinux.org/pere/blog/The_life_and_death_of_a_laptop_battery.html</link>        
+               <guid isPermaLink="true">http://people.skolelinux.org/pere/blog/The_life_and_death_of_a_laptop_battery.html</guid>
+                <pubDate>Thu, 24 Sep 2015 16:00:00 +0200</pubDate>
+               <description>&lt;p&gt;When I get a new laptop, the battery life time at the start is OK.
+But this do not last.  The last few laptops gave me 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
+all the time.  Because of this, when I got a new Thinkpad X230 laptop
+about two years ago, I decided to monitor its battery state to have
+more hard facts when the battery started to fail.&lt;/p&gt;
+
+&lt;img src=&quot;http://people.skolelinux.org/pere/blog/images/2015-09-24-laptop-battery-graph.png&quot;/&gt;
+
+&lt;p&gt;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
+&lt;a href=&quot;https://tracker.debian.org/pkg/battery-stats&quot;&gt;battery-stats&lt;/a&gt;,
+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
+&lt;a href=&quot;http://www.ifweassume.com/2013/08/the-de-evolution-of-my-laptop-battery.html&quot;&gt;a
+blog post about the battery development on a MacBook Air&lt;/a&gt; I also
+discovered
+&lt;a href=&quot;https://github.com/jradavenport/batlog.git&quot;&gt;batlog&lt;/a&gt;, not
+available in Debian.&lt;/p&gt;
+
+&lt;p&gt;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 is quite simple and look like this:&lt;/p&gt;
+
+&lt;pre&gt;
+#!/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=&quot;manufacturer model_name technology serial_number \
+    energy_full energy_full_design energy_now cycle_count status&quot;
+
+if [ ! -e &quot;$logfile&quot; ] ; then
+    (
+       printf &quot;timestamp,&quot;
+       for f in $files; do
+           printf &quot;%s,&quot; $f
+       done
+       echo
+    ) &gt; &quot;$logfile&quot;
+fi
+
+log_battery() {
+    # Print complete message in one echo call, to avoid race condition
+    # when several log processes run in parallell.
+    msg=$(printf &quot;%s,&quot; $(date +%s); \
+       for f in $files; do \
+           printf &quot;%s,&quot; $(cat $f); \
+       done)
+    echo &quot;$msg&quot;
+}
+
+cd /sys/class/power_supply
+
+for bat in BAT*; do
+    (cd $bat &amp;&amp; log_battery &gt;&gt; &quot;$logfile&quot;)
+done
+&lt;/pre&gt;
+
+&lt;p&gt;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 code for the Debian package
+&lt;a href=&quot;https://github.com/petterreinholdtsen/battery-status&quot;&gt;is now
+available on github&lt;/a&gt;.&lt;/p&gt;
+
+&lt;p&gt;The collected log file look like this:&lt;/p&gt;
+
+&lt;pre&gt;
+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,
+&lt;/pre&gt;
+
+&lt;p&gt;I wrote a small script to create a graph of the charge development
+over time.  This graph depicted above show the slow death of mylaptop
+battery.&lt;/p&gt;
+
+&lt;p&gt;But why is this happening?  Why are my laptop batteries always
+dying in a year or two, while the batteries of space probes and
+satellites keep working year after year.  If we are to believe
+&lt;a href=&quot;http://batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries&quot;&gt;Battery
+University&lt;/a&gt;, the cause is me charging the battery whenever I have a
+chance, and 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&#39;ve been told that the Tesla electric cars
+&lt;a href=&quot;http://my.teslamotors.com/de_CH/forum/forums/battery-charge-limit&quot;&gt;limit
+the charge of their batteries to 80%&lt;/a&gt;, with the option to charge to
+100% when preparing for a longer trip (not that I would want a car
+like Tesla where rights to privacy is abandoned, but that is another
+story), which I guess is the option we should have for laptops on
+Linux too.&lt;/p&gt;
+
+&lt;p&gt;Is there a good and generic 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?  I found
+&lt;a href=&quot;http://askubuntu.com/questions/34452/how-can-i-limit-battery-charging-to-80-capacity&quot;&gt;one
+recipe on askubuntu for Ubuntu to limit charging on Thinkpad to
+80%&lt;/a&gt;, but could not get it to work (kernel module refused to
+load).&lt;/p&gt;
+
+&lt;p&gt;I wonder why the battery capacity was reported to be more than 100%
+at the start.  I also wonder why the &quot;full capacity&quot; increases some
+times, and if it is possible to repeat the process to get the battery
+back to design capacity.  And I wonder if the discharge and charge
+speed change over time, or if this stay the same.  I did not yet try
+to write a tool to calculate the derivative values of the battery
+level, but suspect some interesting insights might be learned from
+those.&lt;/p&gt;
+</description>
+       </item>
+       
        <item>
                <title>Book cover for the Free Culture book finally done</title>
                <link>http://people.skolelinux.org/pere/blog/Book_cover_for_the_Free_Culture_book_finally_done.html</link>