#!/usr/bin/python

'''
Original data collection script by Ben Kenney - July 2012
This program reads data coming from the serial port and saves that data to a text file. It expects data in the following format with a comma (,) as a separator:
"value1,value2"
It assumes that the Arduino shows up in /dev/ttyACM0 on the Raspberry Pi which should happen if you're using Debian.
'''

import serial
from time import strftime
from datetime import datetime, time

ser = serial.Serial('/dev/ttyACM0',9600)

startTime = datetime.now()
try:
    while 1:
        line=ser.readline().rstrip()
#        temp,outsidetemp=line.split(",")
#	we have more data. 
#	I don't know what they are yet...
	read1,read2,read3=line.split(",");
        now = datetime.now()
        elapsedTime = now-startTime
        elapsedSeconds = (elapsedTime.microseconds+(elapsedTime.days*24*3600+elapsedTime.seconds)*10**6)/10**6
#this is the original
#
 #       f=open('/home/pi/sensors/sensordata/temperaturedata.csv','a')
#
        f=open('./temperaturedata.csv','a')
        print >>f,("%s,%s,%s,%s,%s"%(now.strftime("%Y-%m-%d %H:%M:%S"),elapsedSeconds,read1,read2,read3))
	f.close()
except KeyboardInterrupt:
	print "\ndone"
