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.

Reading

The Pirates! in an Adventure with Scientists by Gideon Defoe

Friday 18 December 2009

Bifferboard bluetooth RTC kludge

The Bifferboard is a tiny linux computer with low power consumption (1 Watt). It has ethernet and USB ports and some GPIO. It has been shown to run a choice of Linux distributions, I'm using Slackware. All this would make it ideal for Home Automation purposes but for the fact it doesn't have an onboard Real Time Clock (and it keeps really bad time), sure you can sync it off NTP, but then you need to leave your Internet up - a DSL modem and a router using ~20 Watts kind of spoils the low power aspect. I'd like to get a I2C RTC like the DS1307 and give that a try , I2C is supported
but I don't have that to hand right now. In the mean time I've kludged up a solution using a disused Nokia phone and a Bluetooth dongle. Following bifferos' Bluetooth instructions and also loading the openobex ,obexftp and dbus packages with slapt-get makes the phone accessible.
The following shell script is called by cron every second.(the btaddr of the phone can be found with a "hcitool scan").

#=cut here =========================
export PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/
export TZ=EET-10EETDT,M10.1.0,M4.1.0/03:00:00Z
#change to tmpfs
cd /dev/shm
#get the time from the phone via bluetooth
obexftp -b btaddr_of_phone -g /telecom/rtc.txt
#reformat for date command
Z=$(cat rtc.txt)
TIMEDATE=$(echo $Z|cut --output-delimiter=: -c 10-11,12-13,14-15;\
echo $Z|cut -c 1-8)
#echo $TIMEDATE
date -s "$TIMEDATE"

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

A lcd4linux compatible java app to use the phones screen via /dev/rfcomm0 is probably worth looking at as well, since the phone is there anyway.

Saturday 12 December 2009