#!/bin/bash

# will store data in a file named yyyymmdd (current year, month and day)
# and automatically create a new file for each day.
# readings will be timestamped in the format 'hh:mm.ss, reading'
# (hours, minutes, seconds, reading from instrument)
# dacq log will record start and stop times and stderr from sjinn

# echo every 300sec 5min a reading ...

while :
do

datestamp=`date "+%Y.%m.%d"`
timestamp=`date "+%H:%M.%S"`

data=$(sjinn -d /dev/ttyS0 -b9600 -s "P*" -r56 -n -w1)
data=$(echo -n $data|awk '{print $1", "$3", "$4}')

# echo $datestamp $timestamp, $data

echo $datestamp $timestamp, $data>>$datestamp

echo "Temperatuur op" $datestamp $timestamp, $data > /usr/local/templog/temperatuur

sleep 2
# convert logdata to PNG
./csv2png $datestamp /var/www/grafiek.png 500 200 YmdHMS
# wait (time min 1s for reading)
sleep 55
done