I was using a sensor that connect to arduino and using ser.readline() to print reading from sensor and success. But when I want to send the reading value using ser.readline to mysql. It only pass the device name and current time and the value of the reading that show in mysql is '0'. Here my coding.
db = MySQLdb.connect("192.168.0.103", "fyp", "123456", "system")
ser = serial.Serial('/dev/ttyACM0', 9600)
api = ser.readline()
current_time = datetime.datetime.now()
sql = "INSERT INTO reading (series_no, time, api) VALUES ('test1', current_time, api)"
data = (current_time, api)
You are not parameterizing the query correctly. Several things to fix:
%s, no quotes around
sql = "INSERT INTO reading (series_no, time, api) VALUES ('test1', %s, %s)" data = (current_time, api) cur.execute(sql, data) db.commit()