Python: Writing data from python to mysql on rasb pi
|Added at||2017-01-01 08:01|
I am new to python as well as to coding on Raspberry Pi. I am reading data from a sensor and trying to store it in MySQL. I managed to set up MySQL and create a table and used INSERT INTO command manually to test if data is being pushed and properly and it seems to be working fine. I have set two columns in the table both FLOAT.
My issue is when I write the python program to do the same it only stores numerical value instead of the value in a variable which actually contains live sensor data. For example if I wrote in python:
In the MySQL it would show:
As you can see the value 12 is stored but the value in the variable temperature is showing as NULL. I tried to printed the value in the temperature variable to see the data and it shows just fine so I'm sure the variable temperature has proper values. I really don't understand why my python script wont send the data of a variable to MySQL.
Also rather than typing 12 for the first column, I tried to create a variable I=I+1 so it would increment every time the loop ran, I get the same NULL value in both columns then. Here is the full code:
Any help would be truly appreciated!