Tuesday, March 25, 2008
[prototype06_mysql to processing to pbasic to output]
Here, we have an LED responding to Air Quality Data being streamed over the internet and filtered through MYSQL. Processing is used to stream the data.
PROCESSING
import de.bezier.sql.*;
import de.bezier.mysql.*;
import processing.serial.*;
MySQL msql;
Serial myPort;
String table = "airTest";
String[] si = new String[636];
void setup()
{
size( 100, 100 );
println(Serial.list());
myPort = new Serial(this, "COM3", 2400);
//String user = "dbo238508103";
// String pass = "Ueb6pwb8";
// name of the database to use
//
//String database = "db238508103";
msql = new MySQL( "db192.perfora.NET", "db238508103", "dbo238508103", "Ueb6pwb8", 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 )"+
")"
);
msql.query( "SELECT * FROM " + table );
int scount = 0;
while (msql.next())
{
String s = msql.getString("word");
si[scount] = s;
int n = msql.getInt("id");
println(s + " " + n);
float f = float(s);
scount = scount + 1;
}
// 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) );
}
else
{
// connection failed !
}
}
void draw()
{
int gg = 0;
int f;
while(gg < f ="int(si[gg]);">0){
delay(1000);
println("port");
println(myPort.available());
if (myPort.available() == 0) {
delay(1000);
int x = int(si[gg]);
println(x);
myPort.write(x);
println("value");
println(si[gg]);
gg = gg + 1;
// myPort.stop();
PBASIC
'{$STAMP BS2}
'{$PBASIC 2.5}
x VAR Byte
y VAR Byte
proIn VAR Byte
Main:
DO
SERIN 16, 16780, [proIn]
IF proIn>10 THEN
LOW 2
ENDIF
IF proIn<10>
HIGH 2
ENDIF
IF proIn>20 THEN
LOW 3
ENDIF
IF proIn<30>
HIGH 3
ENDIF
IF proIn<30>
LOW 4
ENDIF
IF proIn>50 THEN
HIGH 4
ENDIF
IF proIn<50>
LOW 4
ENDIF
IF proIn>70 THEN
HIGH 4
ENDIF
LOOP
END
}
myPort.clear();
delay(1000);
}
}
Labels: [cm:sd], mysql, pbasic, processing