]> pere.pagekite.me Git - homepage.git/blobdiff - blog/archive/2015/09/index.html
Generated.
[homepage.git] / blog / archive / 2015 / 09 / index.html
index 0d6f348a86eb409f77313ed3303ac8380116248e..305050d2a27f224240a0b996f5d20398a197522d 100644 (file)
 
     <h3>Entries from September 2015.</h3>
     
+    <div class="entry">
+      <div class="title">
+        <a href="http://people.skolelinux.org/pere/blog/The_life_and_death_of_a_laptop_battery.html">The life and death of a laptop battery</a>
+      </div>
+      <div class="date">
+        24th September 2015
+      </div>
+      <div class="body">
+        <p>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.</p>
+
+<img src="http://people.skolelinux.org/pere/blog/images/2015-09-24-laptop-battery-graph.png"/>
+
+<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
+<a href="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
+<a href="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
+<a href="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 capacity.  My
+collector shell script is quite simple and 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 parallel.
+    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 code for the Debian package
+<a href="https://github.com/petterreinholdtsen/battery-status">is now
+available on github</a>.</p>
+
+<p>The collected 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 wrote a small script to create a graph of the charge development
+over time.  This graph depicted above show the slow death of my laptop
+battery.</p>
+
+<p>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
+<a href="http://batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries">Battery
+University</a>, 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've been told that the Tesla electric cars
+<a href="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 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.</p>
+
+<p>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
+<a href="http://askubuntu.com/questions/34452/how-can-i-limit-battery-charging-to-80-capacity">one
+recipe on askubuntu for Ubuntu to limit charging on Thinkpad to
+80%</a>, but could not get it to work (kernel module refused to
+load).</p>
+
+<p>I wonder why the battery capacity was reported to be more than 100%
+at the start.  I also wonder why the "full capacity" 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.</p>
+
+<p>Update 2015-09-24: I got a tip to install the packages
+acpi-call-dkms and tlp (unfortunately missing in Debian stable)
+packages instead of the tp-smapi-dkms package I had tried to use
+initially, and use 'tlp setcharge 40 80' to change when charging start
+and stop.  I've done so now, but expect my existing battery is toast
+and need to be replaced.  The proposal is unfortunately Thinkpad
+specific.</p>
+
+      </div>
+      <div class="tags">
+        
+        
+        Tags: <a href="http://people.skolelinux.org/pere/blog/tags/debian">debian</a>, <a href="http://people.skolelinux.org/pere/blog/tags/english">english</a>.
+        
+        
+      </div>
+    </div>
+    <div class="padding"></div>
+    
     <div class="entry">
       <div class="title">
         <a href="http://people.skolelinux.org/pere/blog/Book_cover_for_the_Free_Culture_book_finally_done.html">Book cover for the Free Culture book finally done</a>
@@ -92,6 +243,44 @@ proof readers a chance to complete their work.</p>
 <h2>Archive</h2>
 <ul>
 
+<li>2017
+<ul>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2017/01/">January (4)</a></li>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2017/02/">February (2)</a></li>
+
+</ul></li>
+
+<li>2016
+<ul>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2016/01/">January (3)</a></li>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2016/02/">February (2)</a></li>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2016/03/">March (3)</a></li>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2016/04/">April (8)</a></li>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2016/05/">May (8)</a></li>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2016/06/">June (2)</a></li>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2016/07/">July (2)</a></li>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2016/08/">August (5)</a></li>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2016/09/">September (2)</a></li>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2016/10/">October (3)</a></li>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2016/11/">November (8)</a></li>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2016/12/">December (5)</a></li>
+
+</ul></li>
+
 <li>2015
 <ul>
 
@@ -111,7 +300,13 @@ proof readers a chance to complete their work.</p>
 
 <li><a href="http://people.skolelinux.org/pere/blog/archive/2015/08/">August (2)</a></li>
 
-<li><a href="http://people.skolelinux.org/pere/blog/archive/2015/09/">September (1)</a></li>
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2015/09/">September (2)</a></li>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2015/10/">October (9)</a></li>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2015/11/">November (6)</a></li>
+
+<li><a href="http://people.skolelinux.org/pere/blog/archive/2015/12/">December (3)</a></li>
 
 </ul></li>
 
@@ -313,45 +508,45 @@ proof readers a chance to complete their work.</p>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/bankid">bankid (4)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/bitcoin">bitcoin (8)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/bitcoin">bitcoin (9)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/bootsystem">bootsystem (15)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/bootsystem">bootsystem (16)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/bsa">bsa (2)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/chrpath">chrpath (2)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/debian">debian (111)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/debian">debian (145)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/debian edu">debian edu (153)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/debian edu">debian edu (158)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/digistan">digistan (10)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/dld">dld (15)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/dld">dld (16)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/docbook">docbook (17)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/docbook">docbook (23)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/drivstoffpriser">drivstoffpriser (4)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/english">english (287)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/english">english (340)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/fiksgatami">fiksgatami (23)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/fildeling">fildeling (12)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/freeculture">freeculture (19)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/freeculture">freeculture (29)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/freedombox">freedombox (9)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/frikanalen">frikanalen (16)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/frikanalen">frikanalen (18)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/h264">h264 (20)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/intervju">intervju (42)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/isenkram">isenkram (10)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/isenkram">isenkram (15)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/kart">kart (19)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/kart">kart (20)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/ldap">ldap (9)</a></li>
 
@@ -363,19 +558,21 @@ proof readers a chance to complete their work.</p>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/mesh network">mesh network (8)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/multimedia">multimedia (36)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/multimedia">multimedia (39)</a></li>
+
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/nice free software">nice free software (9)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/norsk">norsk (264)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/norsk">norsk (287)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/nuug">nuug (177)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/nuug">nuug (186)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/offentlig innsyn">offentlig innsyn (19)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/offentlig innsyn">offentlig innsyn (28)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/open311">open311 (2)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/opphavsrett">opphavsrett (53)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/opphavsrett">opphavsrett (64)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/personvern">personvern (86)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/personvern">personvern (99)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/raid">raid (1)</a></li>
 
@@ -385,27 +582,27 @@ proof readers a chance to complete their work.</p>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/rfid">rfid (3)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/robot">robot (9)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/robot">robot (10)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/rss">rss (1)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/ruter">ruter (4)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/ruter">ruter (5)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/scraperwiki">scraperwiki (2)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/sikkerhet">sikkerhet (41)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/sikkerhet">sikkerhet (52)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/sitesummary">sitesummary (4)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/skepsis">skepsis (4)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/skepsis">skepsis (5)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/standard">standard (48)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/standard">standard (50)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/stavekontroll">stavekontroll (3)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/stavekontroll">stavekontroll (5)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/stortinget">stortinget (9)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/stortinget">stortinget (11)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/surveillance">surveillance (33)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/surveillance">surveillance (47)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/sysadmin">sysadmin (2)</a></li>
 
@@ -413,11 +610,11 @@ proof readers a chance to complete their work.</p>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/valg">valg (8)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/video">video (54)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/video">video (59)</a></li>
 
  <li><a href="http://people.skolelinux.org/pere/blog/tags/vitenskap">vitenskap (4)</a></li>
 
- <li><a href="http://people.skolelinux.org/pere/blog/tags/web">web (37)</a></li>
+ <li><a href="http://people.skolelinux.org/pere/blog/tags/web">web (40)</a></li>
 
 </ul>