
#!/bin/sh
# File	: get_bmp180_data.sh
# By	: MaartenDeBoer.nl, 160226
# Subject	: Script to log regular the temp in an CSV-file
#(0.2)	: Add -f's & DATAFILE-name
PGM="`basename $0|cut -d\. -f1`"
VER="0.2"

DATADIR="${HOME}/data"
HOSTNAME="`hostname |cut -d\. -f1`" 
# Graphite: domotica.<group>|nl.<hostname>.<device>|bmp180|rpi.<item>-<value>|temperature-c|pressure-mbar
# Filename: domotica-<group>|nl-<hostname>-<device>|bmp180|rpi.csv
DATAFILE="${DATADIR}/domotica-nl-${HOSTNAME}-rpi_`date +%Y-%m-%d`.csv"

# If DATADIR does not exist, create this dir
if [ ! -d ${DATADIR} ]; then
  mkdir -p ${DATADIR}
fi

# If file does not exist, create by adding header
if [ ! -f ${DATAFILE} ]; then
   echo "# Date time;temperature-c;;" > ${DATAFILE}
fi

echo "`date +%Y-%m-%d' '%H:%M:%S`;`sudo /opt/vc/bin/vcgencmd measure_temp|cut -d\= -f2|sed \"s/'C//\"`; "|tee -a ${DATAFILE}

exit 0

