Em relação ao processing estou napplets, mas aqui fica a parte principal do código onde são tratados os dados recebido na porta série a partir do xbee
import napplet.*;
import processing.serial.*;
Serial port;
PrintWriter dadosSMEP;
int count;
//variables to receive on serial port
float yeartime, monthtime, daytime;
float hourtime, minutetime, secondtime, oldsecondtime ;
float presvalue, oldpresvalue;
float Irms;
float apparentPower,realPower;
float kilowattHour;
float timeX; //Calculates the total time, using the time function of processing necessary to use on graphs Xaxis
//Size of the window
int plotX=1150, plotY=800;
//Dimension of each graph window
int plotgwX=575, plotgwY=312;
//plotmw means the height of the main window
int plotmwY=176;
//
color bgc=color(0, 153, 0); //backgroung color of each window
color graphc=color(#4D4D4A);//graph line color
color textc=color(255); //text color on graph label
PFont plotFont; //font used in each graph
void setup() {
size(plotX,plotY);
// Print a list of the serial ports, for debugging purposes:
println(Serial.list());
// Open whatever port is the one you're using.
port = new Serial(this,"COM14", 9600);
// don't generate a serialEvent() unless you get a newline character:
port.bufferUntil('\n');
NAppletManager nappletManager = new NAppletManager(this);
//define the initial points of each window created in our sketch
nappletManager.createNApplet("Irms", 0, 0);
nappletManager.createNApplet("RealPower", width/2, 0);
nappletManager.createNApplet("kWh", 0, plotgwY);
nappletManager.createNApplet("Presence", width/2, plotgwY);
nappletManager.createNApplet("MainWindow", 0, height-plotmwY);
plotFont = createFont("SansSerif", 20);
textFont(plotFont);
//setup the text file to be created with descrition of several parameters
dadosSMEP = createWriter("dadosSMEP.csv");
dadosSMEP.print("Date");
dadosSMEP.print(";");
dadosSMEP.print("Irms");
dadosSMEP.print(";");
dadosSMEP.print("Apparent_Power");
dadosSMEP.print(";");
dadosSMEP.print("Real_Power");
dadosSMEP.print(";");
dadosSMEP.print("kWh");
dadosSMEP.print(";");
dadosSMEP.println("Presence");
}
void draw() {
background(0, 153, 0);
timeX=60.0*minutetime+secondtime+hourtime*3600.0; //Calculates the total time, using the time function of processing
//necessary to use on graphs Xaxis
//convert the float number to integer
String intyeartime = nf(yeartime, 2,0);
String intmonthtime = nf(monthtime, 2,0);
String intdaytime = nf(daytime, 2,0);
String inthourtime = nf(hourtime, 2,0);
String intminutetime = nf(minutetime, 2,0);
String intsecondtime = nf(secondtime, 2,0);
if(secondtime != oldsecondtime){//just print if the time change using second from Arduino Time
//print the data received from Arduino on the text file
dadosSMEP.print(intyeartime+"/"+intmonthtime+"/"+intdaytime+" "+inthourtime+":"+intminutetime+":"+intsecondtime);
dadosSMEP.print(";");
dadosSMEP.print(Irms);
dadosSMEP.print(";");
dadosSMEP.print(apparentPower);
dadosSMEP.print(";");
dadosSMEP.print(realPower);
dadosSMEP.print(";");
dadosSMEP.print(kilowattHour);
dadosSMEP.print(";");
dadosSMEP.println(presvalue);
dadosSMEP.flush();
}
oldsecondtime = secondtime;
}
void mousePressed()
{
println("Coordinates: " + mouseX +"," + mouseY);
}
void serialEvent(Serial port)
{
String input = port.readStringUntil('\n');//le o que chega a porta ate ao enter para importar as variaveis do arduino
/*para isto e necessario que no sketch do arduino as variaveis sejam imprimidas com Serial.print(variavel)
e seguidas de virgula ou seja outro Serial.print(",").Sendo que a ultima variavel a registar e imprimida com
Serial.println(variavel) */
if (input != null)//se a string contiver algo
{
input = trim(input); // limpa a string de espaços vazios que não sejam necessários
// The data is split into an array of Strings with a comma or asterisk as a delimiter and converted into an array of integers.
float [] infos =float (split(input, ";")); //preenche uma matriz com as variaveis importadas sendo que as diferentes variaveis vao para locais diferentes da matriz infos [0],infos [1]...
if (infos.length >=11) //11 e o numero de variaveis que importo do arduino "ainda nao percebi bem porque e' necessario este if"
{
daytime = infos [0];
monthtime = infos [1];
yeartime = infos [2];
hourtime = infos [3];
minutetime = infos [4];
secondtime = infos [5];
Irms = infos [6];
apparentPower = infos [7];
realPower = infos [8];
kilowattHour = infos [9];
presvalue = infos [10]; //presence value
}
}
}
Espero que possa ajudar e desculpa a possível estrutura do código mas foi o meu primeiro projeto nesta área