Thursday 24 December 2009

phone battery check over bluetooth

bash script to check the battery level via bluetooth (assumes you have bind-ed the devices in rfcomm.conf already)

#cut here =======================
#!/bin/bash
Z=$( C='';until [ "$C" == "connected" ];do C=`rfcomm show 1|cut -d ' ' -f 5`;\
done;echo "at+cbc">/dev/rfcomm1 )&

ZZ=$((while read line
do
echo $line
if [ "$line" == "OK" ]; then
break
fi
done < /dev/rfcomm1 )|grep CBC|cut -d ',' -f 2 )

echo "Battery Level = $ZZ %"

#=================================

will put this in cron with some level checks around it to turn the charger off and on.

No comments: