{"id":467,"date":"2016-07-28T14:10:33","date_gmt":"2016-07-28T13:10:33","guid":{"rendered":"http:\/\/snakenet.eu\/blog\/?p=467"},"modified":"2016-07-28T22:56:11","modified_gmt":"2016-07-28T21:56:11","slug":"chip-extinction-automatique-en-cas-de-batterie-faible","status":"publish","type":"post","link":"https:\/\/snakenet.eu\/blog\/chip-extinction-automatique-en-cas-de-batterie-faible\/467\/","title":{"rendered":"CHIP &#8211; extinction automatique en cas de batterie faible"},"content":{"rendered":"<p>#!\/bin\/sh<br \/>\n# Fortement inspir\u00e9 de battery.sh<br \/>\n# a mettre dans \/etc\/init.d\/monitorBattery.sh<br \/>\n# a configurer dans crontab :<br \/>\n# * * * * * \/etc\/init.d\/monitorBattery.sh &gt; \/var\/log\/monitorBattery.log<\/p>\n<p>#!\/bin\/sh<br \/>\n\/usr\/sbin\/i2cset -y -f 0 0x34 0x82 0xC3<\/p>\n<p>POWER_OP_MODE=$(\/usr\/sbin\/i2cget -y -f 0 0x34 0x01)<\/p>\n<p>BAT_EXIST=$(($(($POWER_OP_MODE&amp;0x20))\/32))  # divide by 32 is like shifting rigth 5 times<br \/>\n# echo \u00ab\u00a0BAT_EXIST=\u00a0\u00bb$BAT_EXIST<\/p>\n<p>BAT_VOLT_MSB=$(\/usr\/sbin\/i2cget -y -f 0 0x34 0x78)<br \/>\nBAT_VOLT_LSB=$(\/usr\/sbin\/i2cget -y -f 0 0x34 0x79)<\/p>\n<p>#echo $BAT_VOLT_MSB $BAT_VOLT_LSB<br \/>\nBAT_BIN=$(( $(($BAT_VOLT_MSB &lt;&lt; 4)) | $(($(($BAT_VOLT_LSB &amp; 0x0F)) )) ))<\/p>\n<p>BAT_VOLT=$(echo \u00ab\u00a0($BAT_BIN*1.1)\u00a0\u00bb|bc)<br \/>\n# echo \u00ab\u00a0Battery voltage = \u00ab\u00a0$BAT_VOLT\u00a0\u00bbmV\u00a0\u00bb<\/p>\n<p>BAT_IDISCHG_MSB=$(\/usr\/sbin\/i2cget -y -f 0 0x34 0x7C)<br \/>\nBAT_IDISCHG_LSB=$(\/usr\/sbin\/i2cget -y -f 0 0x34 0x7D)<\/p>\n<p>BAT_IDISCHG_BIN=$(( $(($BAT_IDISCHG_MSB &lt;&lt; 5)) | $(($(($BAT_IDISCHG_LSB &amp; 0x1F)) )) ))<\/p>\n<p>BAT_IDISCHG=$(echo \u00ab\u00a0($BAT_IDISCHG_BIN*0.5)\u00a0\u00bb|bc)<br \/>\n# echo \u00ab\u00a0Battery discharge current = \u00ab\u00a0$BAT_IDISCHG\u00a0\u00bbmA\u00a0\u00bb<\/p>\n<p>if [ $BAT_EXIST -eq 1 ]<br \/>\nthen<br \/>\necho \u00ab\u00a0il y a une batterie\u00a0\u00bb<br \/>\nif (( $(bc &lt;&lt;&lt; \u00ab\u00a0$BAT_IDISCHG &gt; 50\u00a0\u00bb) ))<br \/>\nthen<br \/>\necho \u00ab\u00a0la batterie se decharge&#8230; J&rsquo;ai plus de courant\u00a0\u00bb<br \/>\nif (( $(bc &lt;&lt;&lt; \u00ab\u00a0$BAT_VOLT &lt; 3500\u00a0\u00bb) ))     then       echo \u00ab\u00a0La batterie est faible, moins de 3,5 volt\u00a0\u00bb       echo \u00a0\u00bb Battery depleted.. Shutting down : $BAT_VOLT mV\u00a0\u00bb `uptime -p`  &gt;&gt; \/var\/log\/monitorBattery.trc<br \/>\necho \u00ab\u00a0extinction\u00a0\u00bb<br \/>\ninit 0<br \/>\nelse<br \/>\necho \u00ab\u00a0Battery voltage = \u00ab\u00a0$BAT_VOLT\u00a0\u00bbmV\u00a0\u00bb<br \/>\necho \u00ab\u00a0Ca va, on continue, ca tient&#8230;\u00a0\u00bb<br \/>\necho \u00a0\u00bb On battery : $BAT_VOLT mV\u00a0\u00bb `uptime -p` &gt;&gt; \/var\/log\/monitorBattery.trc<br \/>\nuptime -p<br \/>\nfi<br \/>\nfi<br \/>\nfi<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#!\/bin\/sh # Fortement inspir\u00e9 de battery.sh # a mettre dans \/etc\/init.d\/monitorBattery.sh # a configurer dans crontab : # * * * * * \/etc\/init.d\/monitorBattery.sh &gt; \/var\/log\/monitorBattery.log #!\/bin\/sh \/usr\/sbin\/i2cset -y -f 0 0x34 0x82 0xC3 POWER_OP_MODE=$(\/usr\/sbin\/i2cget -y -f 0 0x34 0x01) BAT_EXIST=$(($(($POWER_OP_MODE&amp;0x20))\/32)) # divide by 32 is like shifting rigth 5 times # echo \u00ab\u00a0BAT_EXIST=\u00a0\u00bb$BAT_EXIST BAT_VOLT_MSB=$(\/usr\/sbin\/i2cget [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-467","post","type-post","status-publish","format-standard","hentry","category-non-classe"],"_links":{"self":[{"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/posts\/467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/comments?post=467"}],"version-history":[{"count":8,"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/posts\/467\/revisions"}],"predecessor-version":[{"id":475,"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/posts\/467\/revisions\/475"}],"wp:attachment":[{"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/media?parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/categories?post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/snakenet.eu\/blog\/wp-json\/wp\/v2\/tags?post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}