[BezierSQLib] Send the value of a variable to a MySQL database
in
Contributed Library Questions
•
9 months ago
Hello.
I'm a Processing newbie and I've made some code to get the values from a LM35 temperature sensor connected to an Arduino UNO board.
I want these values to be sent to a MySQL database, and I'm using the SQL library to do so.
That's the code I'm using:
- import processing.serial.*;
import cc.arduino.*;
import de.bezier.data.sql.*;
Arduino arduino;
MySQL database;
int sensorTemp = 2;
float sensorValue = 0;
void setup()
{
arduino = new Arduino(this, Arduino.list()[0]);
arduino.pinMode(sensorTemp, Arduino.INPUT);
String user = "root";
String pass = "";
String database = "data-arduino";
database = new MySQL(this, "localhost", database , user , pass);
}
void draw()
{
sensorValue = (5.0 * arduino.analogRead(sensorTemp) * 100.0) / 1024.0; // read the value and make the conversion
println(sensorValue);
if ( database.connect() )
{
database.execute("INSERT INTO `data-arduino`.`temperature` (`TEMPERATURE`) VALUES ('sensorValue');");
}
else
{
println("Error in the connection :-( ");
}
delay(300000); // Wait 5 minutes
}
The problem is that with this code, I send the name of the variable (sensorValue) to the MySQL database, but what I want to send to the MySQL database is the value of the variable, not the name.
What do I have to do to send the value of the variable and not the name of it to a MySQL database?
Thank you.
(And sorry for my English)
1