Johnny010:
I find python useful for this...here is my code. Takes a string via Serial, splits it by comma and then stores values in a mySQL database, this is on a Raspberry Pi, but should work regardless on any platform:
import serial
import datetime
import time
import MySQLdb
#Get the data from serial//
port = serial.Serial("/dev/ttyAMA0",baudrate = 9600, timeout = 10.0)
#connect to mySQL DB rawdata
db = MySQLdb.connect('localhost',"user","password","rawdata")
curs=db.cursor()
counter=0
#Do this always
while True:
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
#read the serial data in buffer (35 characters worth)
rcv = port.readline(100)
counter+=1
#split the original string in to parts
if counter>30:
try: #Take the data and delimit it in to seperate arrays for each determinant.
delimited_data = rcv.strip().split(',')
#check to see if there is any issue with the LUX sensor:
try:
val = float(delimited_data[4])
except:
#make it so the data is read and the last LUX column made equal to zero
#print("Error in the delim data.")
curs.execute("INSERT INTO GHCdata (H1,H2,T1,T2,LUX) VALUES(%s,%s,%s,%s,0)", (delimited_data[0],delimited_data[1],delimited_data[2],delimited_data[3]))
db.commit()
counter=0;
#If there are no issues with LUX sensor overload: Put the data in to the mysql table.
curs.execute("INSERT INTO GHCdata (H1,H2,T1,T2,LUX) VALUES (%s,%s,%s,%s,%s)",(delimited_data[0],delimited_data[1],delimited_data[2],delimited_data[3],delimited_data[4]))
db.commit()
#print "Added data to mySQL"
counter=0;
#if there were any other errors (faulty whatever) then say there is an error and add it to a log file.
except:
#print("ERROR")
f=open('data.txt','a')
f.write("\n"+"Error - got :"+ ",".join(delimited_data)+" at "+ datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
counter=0;
Thanks man for sharing your code i hope that it will be useful for more pro users than me! Or to me in the future!