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
Dear Václav BroĹľĂk, thank you for your quick response.
master_data is the data read from the vibration sensor every second and contains a list of 500 float numbers.
I can’t shorten the 500 item list. I need the whole data. I can’t use val = ((str(item),) for item in master_data) because the code execution time is more than 1 second and again some data is lost.