Wednesday, October 10, 2007

MYSQL upload



This Code has been appended to our last draft of the processing script. This new addition will allow us to upload the input from the micro controller to a MYSQL database on the internet that can be shared with other computers or other micro controllers. This could potentially produce an interesting overlap between physical and virtual architectures.

import de.bezier.sql.*;
import de.bezier.mysql.*;
import processing.serial.*;

MySQL msql;
String table = "downloadTest";

Serial myPort; // The serial port

int[] num;
int counter;

void setup() {

frameRate(900);
size(200, 200);
background(51);
stroke(55);
noFill();
smooth();
println(Serial.list());





msql = new MySQL( "SQL06.FREEMYSQL.NET", "ecovis", "fb", "h2", this );

if ( msql.connect() )
{
// create a table with an id and a word
//
msql.execute( "CREATE TABLE IF NOT EXISTS " + table + " ("+
"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"+
"word VARCHAR( 255 )"+
")"
);





counter = 0;

myPort = new Serial(this, Serial.list()[1], 2400);

}

else
{
// connection failed !
}

}

void draw() {
while (myPort.available() > 0) {
String inBuffer = myPort.readString();


if (inBuffer != null) {
print(inBuffer);
print("\n");
}
int conv = int(inBuffer);
msql.execute( "INSERT INTO " + table + " (word) VALUES (\"8\")" );
if (conv == 8){
fill(255);

counter = counter + 1;
}
if (conv == 9){
fill(111);
msql.execute( "INSERT INTO " + table + " (word) VALUES (\"9\")" );
counter = counter + 1;
}
if (conv == 1){
fill(111,0,255);
msql.execute( "INSERT INTO " + table + " (word) VALUES (\"1\")" );
counter = counter + 1;
}
if (conv == 2){
fill(255,0,255);
msql.execute( "INSERT INTO " + table + " (word) VALUES (\"2\")" );
counter = counter + 1;
}
triangle(30, 75, 58, 20, 86, 75);
}

//read back

msql.query( "SELECT * FROM " + table );

while (msql.next())
{
String s = msql.getString("word");
int n = msql.getInt("id");
println(s + " " + n);
}

// need to find out how many rows there are in table?
//
msql.query( "SELECT COUNT(*) FROM " + table );
msql.next();
println( "number of rows: " + msql.getInt(1) );



}

Labels:


Comments: Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?