Hi
I want to read the data of a sensor and transfer it to MySQL local host with "mysql.connector". The problem is that it reads the data as a list containing 500 data (that is, it reads 500 to 500, not one by one). This is my code:
master_data = master_task.read(number_of_samples_per_channel=500)
sql = "INSERT INTO vib_data2 (data) VALUES (%s)"
val = list(master_data, )
mycursor.executemany(sql, val)
mydb.commit()
I got this error:
"Could not process parameters: float(-0.15846696725827258), it must be of type list, tuple or dict"
I can fix the problem with this code:
for i in master_data:
sql = "INSERT INTO vib_data2 (data) VALUES (%s)"
val = (str(I),)
mycursor.execute(sql, val)
mydb.commit()
But the code execution time is very long (more than one second) and thus some of the data is lost.
Thank you for helping to correct the code
I want to read the data of a sensor and transfer it to MySQL local host with "mysql.connector". The problem is that it reads the data as a list containing 500 data (that is, it reads 500 to 500, not one by one). This is my code:
master_data = master_task.read(number_of_samples_per_channel=500)
sql = "INSERT INTO vib_data2 (data) VALUES (%s)"
val = list(master_data, )
mycursor.executemany(sql, val)
mydb.commit()
I got this error:
"Could not process parameters: float(-0.15846696725827258), it must be of type list, tuple or dict"
I can fix the problem with this code:
for i in master_data:
sql = "INSERT INTO vib_data2 (data) VALUES (%s)"
val = (str(I),)
mycursor.execute(sql, val)
mydb.commit()
But the code execution time is very long (more than one second) and thus some of the data is lost.
Thank you for helping to correct the code