Ok mate, but keep in mind the source of this problem can be in: corrupted system image, weak power adapter for your Lime2 board (there are lot of power adapters dropping voltage under load below "safe" values and only few good ones on the market), microSD or SD card has been removed after transferring system image too early (these card are slow and it still takes time to write all data even system say 100% written) or card reader is plugged in internal or external hub which is underpowered and causes data corruption during transfers.
hi all,
if someone need, I adapted for nagios the script to monitor battery cubietruck.
The script is pnp4nagios friendly.
#!/bin/bash
######################################################################################
#
# Battery info
#
/usr/sbin/i2cset -y -f 0 0x34 0x82 0xC3
# read power OPERATING MODE register @01h
POWER_OP_MODE=$(/usr/sbin/i2cget -y -f 0 0x34 0x01)
BAT_EXIST=$(($(($POWER_OP_MODE&0x20))/32)) # divide by 32 is like shifting rigth 5 times
CHARG_IND=$(($(($POWER_OP_MODE&0x40))/64)) # divide by 64 is like shifting rigth 6 times
########################################################################################
#read battery voltage 79h, 78h 0 mV -> 000h, 1.1 mV/bit FFFh -> 4.5045 V
BAT_VOLT_LSB=$(/usr/sbin/i2cget -y -f 0 0x34 0x79)
BAT_VOLT_MSB=$(/usr/sbin/i2cget -y -f 0 0x34 0x78)
BAT_BIN=$(( $(($BAT_VOLT_MSB << 4)) | $(($(($BAT_VOLT_LSB & 0xF0)) >> 4)) ))
BAT_VOLT=$(echo "($BAT_BIN*1.1)"|bc)
# store maximum battery voltage to compare to
if [ -f "/etc/default/battery" ]; then
source "/etc/default/battery"
else
echo "MAX=$BAT_VOLT" > /etc/default/battery
echo "MIN=3484" >> /etc/default/battery
fi
# integer is enough, cut down the decimals
MAX=${MAX%.*}
BAT_VOLT=${BAT_VOLT%.*}
# mainline kernel shows battery existence even if not exists. this is walkaround
if [ "$BAT_VOLT" -ge "3200" ]; then
# if we have new max value, alter defaults
if [ "$BAT_VOLT" -gt "$MAX" ]; then
MAX=$BAT_VOLT
sed -e 's/MAX=.*/MAX='$BAT_VOLT'/g' -i /etc/default/battery
fi
# if we have new min value, alter defaults
if [ "$BAT_VOLT" -lt "$MIN" ]; then
MIN=$BAT_VOLT
sed -e 's/MIN=.*/MIN='$BAT_VOLT'/g' -i /etc/default/battery
fi
# calculate percentage
percent=$(echo "($BAT_VOLT-$MIN)*100/($MAX-$MIN)"|bc)
fi
# define output format
output="Load : $percent% | Load_Batt=$percent;80;35;3.4;4.2;"
# if load% in range 80-10 ok
if [ "$percent" -ge 80 -a "$percent" -le 100 ]; then
echo "OK- $output"
exit 0
# if load % in range 40-79 warning
elif [ "$percent" -ge 40 -a "$percent" -le 79 ]; then
echo "WARNING - $output"
exit 1
# if load % in range 0-39 critical
elif [ "$percent" -ge 0 -a "$percent" -le 39 ]; then
echo "CRITICAL - $output"
exit 2
# if check non riceve data
else echo "UNKNOW"
exit 3
fi
if run script for non admin user need add permission to /usr/sbin/iscget
ex:
chmod 777 /usr/sbin/iscget
and change default permission for /dev/i2c-0
ex:
sudo nano /lib/udev/rules.d/60-i2c-tools.rules
KERNEL=="i2c-0" , GROUP="i2c", MODE="0660"
to
KERNEL=="i2c-0" , GROUP="i2c", MODE="0666"
and reboot