Friday, 13 September 2013

Allowing user to stablish IP address using oscP5 with Processing Android

Allowing user to stablish IP address using oscP5 with Processing Android

Hello fellow processing developers,
I'm using OSCP5 to link two processing sketches, one from an android
device and the other in my computer, via WiFi.
I already tried it typing my computer's IP address directly on the new
NetAddress that's on the setup() and it works just fine. However, I think
it is best to give the user the chance to change the IP address of the
computer to where the message is sent (it may change IP or change network
and then the android app would not work).
I'm using a text field for the user to enter the IP address and then using
this in a string called ipAddress that goes into the NetAddress that goes
into the myRemoteLocation.
Here's my code (this goes on the phone):
import oscP5.*;
import netP5.*;
import apwidgets.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
PWidgetContainer widgetContainer;
PEditText textField;
PButton button1;
PImage fondo;
boolean ValidIP = false;
String ipAddress = "192.168.0.107";
void setup() {
size(480,800);
smooth();
fondo = loadImage("fondoAnd.jpg");
widgetContainer = new PWidgetContainer(this);
textField = new PEditText(10,40,380,120);
button1 = new PButton(10,190,200,100,"Conectar");
widgetContainer.addWidget(textField);
widgetContainer.addWidget(button1);
oscP5 = new OscP5(this,12000);
myRemoteLocation = new NetAddress(ipAddress,12000);
}
void draw() {
if (ValidIP == true){
widgetContainer.hide();
myRemoteLocation = new NetAddress(ipAddress,12000);
background(fondo);
}
else if (ValidIP == false){
background(0);
textSize(20);
text("Ingrese un IP válido",10,30);
widgetContainer.show();
}
}
void mousePressed(){
OscMessage myMessage = new OscMessage("/test");
myMessage.add(8);
oscP5.send(myMessage, myRemoteLocation);
println("enviomensaje"); //I print this in the console to know if it
sends a message
}
void onClickWidget(PWidget widget){
if(widget == button1){
ipAddress = textField.getText();
myRemoteLocation = new NetAddress(ipAddress,12000);
ValidIP = true;
}
}

No comments:

Post a Comment