Been trying to fix this. The barometer data on the Adruino looks like this:
1008.94 1008.95 1008.94
Which I'm happy with. These get "read" every 10 second for now.
The problem is with my python script. I can read and write all the data to my mySQLdb. But the the data is not always good. It will go like something like:
1008.94 108.95 108.94 1008.96
The "lost zero" or other value always appears on the Adruino's serial monitor.
How can I get the python script to read the whole xxxx.xx line? Just thought even at times of low pressure xxx.xx.
Here is my python code:
import MySQLdb
import serial
import time
ser = serial.Serial('/dev/ttyACM0', 9600)
db = MySQLdb.connect("localhost", "root", "pword","weather")
cursor = db.cursor()
while 1:
# print ("Waiting for data...")
# print("")
x = ser.readline()
clock = (time.strftime("%H:%M:%S"))
print x
# print ("Collecting data...")
x = x
# print ("Inserting to database...")
# print ("")
sql = ("""INSERT INTO WeatherP (pres, Time) VALUES (%s, %s)""", (x, clock,))
cursor.execute(*sql)
db.commit()
#
Thank you. Tinus