Receive OSC using OscP5 library, Android Mode 4.0-beta2

edited October 2017 in Android Mode

Hey, how is it going?

Im trying to receive osc on my mobile, using OscP5 library and android mode 4.0-beta2. Codes:

Android app

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress endereco;

float x = 1.0;
float y = 2.0;
float z = 3.0;

void setup() {
  fullScreen();
  orientation(LANDSCAPE);
  textSize(100);
  oscP5 = new OscP5(this, 9000);
  endereco = new NetAddress("localhost", 10000); // not sure if i even need to import netP5
}

void draw() {
  background(0);
  fill(255);
  text("x = " + x, 20, 200);
  text("y = " + y, 20, 400);
  text("z = " + z, 20, 600);
}

void oscEvent(OscMessage mensagem) {
  // tests if any message is being received at all
  fill(255);
  rect(50, 30, 100, 100);

  if (mensagem.checkAddrPattern("/x")) x = mensagem.get(0).floatValue();
  else if (mensagem.checkAddrPattern("/y")) y = mensagem.get(0).floatValue();
  else if (mensagem.checkAddrPattern("/z")) z = mensagem.get(0).floatValue();
}

Java code running on my laptop

import oscP5.*;
import netP5.*;

OscP5 osc;
NetAddress endereco;

float x = 0;
float y = 0;
float z = 0;

OscMessage mx = new OscMessage("/x");
OscMessage my = new OscMessage("/y");
OscMessage mz = new OscMessage("/z");

void setup() {
  osc = new OscP5(this, 12000);
  endereco = new NetAddress("192.168.25.2", 9000);

}

void draw() {
}

void keyPressed() {
  if (key == 'q') {
    x += 10.4;
    mx.add(x);
    osc.send(mx, endereco);
    mx.clearArguments();
  } else if (key == 'w') {
    x -= 10.5;
    mx.add(x);
    osc.send(mx, endereco);
    mx.clearArguments();
  } else if (key == 'a') {
    y += 10.4;
    my.add(y);
    osc.send(my, endereco);
    my.clearArguments();
  } else if (key == 's') {
    y -= 10.5;
    my.add(y);
    osc.send(my, endereco);
    my.clearArguments();
  } else if (key == 'z') {
    z += 10.4;
    mz.add(z);
    osc.send(mz, endereco);
    mz.clearArguments();
  } else if (key == 'x') {
    z -= 10.5;
    mz.add(z);
    osc.send(mz, endereco);
    mz.clearArguments();
  }
}

They are both connected to the same Wifi network, im pretty sure the IP address is correct, but it just does not receive the message sent, the INTERNET permission is checked for the app. What can I be missing?

Using Processing 3.2.1, Android Mode 4.0-beta2, Android 6.0 (API 23), Zenphone 2 Laser Android 5.0.2.

All best Thanks in advance

Answers

  • edited September 2016 Answer ✓

    well, ive changed doors from 9000 to 7000 and it worked.. thanks for the attention =) how do i mark this as solved?

  • By "doors" you mean "port", correct? Port 7000. Thanks for sharing your solution.

  • yes, port =)

  • Hey! I'm having a similar problem. I'm trying to SEND a message from my android tablet, and receive on my computer. I was able to get this code to work on two computers, so wondering if this has something to do with the port number or android mode?

    Here is the code on my tablet:

        import oscP5.*;
        import netP5.*;
    
        int squareColor = 200;
    
        Buttons button1;
        Buttons button2;
    
        OscP5 oscP5;
        NetAddress myRemoteLocation;
    
        void setup() {
          size(600,800);
          frameRate(25);
          /* start oscP5, listening for incoming messages at port 12000 */
          oscP5 = new OscP5(this,7000);
    
    
    
          myRemoteLocation = new NetAddress("192.168.1.179",12000);
    
    
          button1 = new Buttons();
          button1.x = 100;
          button1.y = 100;
          button1.w = 100;
          button1.h = 100;
    
          button2 = new Buttons();
          button2.x = 250;
          button2.y = 100;
          button2.w = 100;
          button2.h = 100;
    
        }
    
    
        void draw() {
          background(0);  
          rectMode(CENTER);
    
          fill(squareColor, 0, 0);
    
         button1.display("hello");
    
         button2.display("fractured");
    
        }
    
        void mousePressed() {
           button1.clicked("hello");
           button2.clicked("testing");
    
        }
    
        void clicked(String wordMessage){
          float d = dist(x, y, mouseX, mouseY);
          if (d < 50) { 
           boxBackground = 255;
           OscMessage myMessage = new OscMessage(wordMessage);
           oscP5.send(myMessage, myRemoteLocation);
           println(myMessage);
          }
    

    Here is the code on my computer:

        import oscP5.*; 
        import netP5.*;
    
        int circleColor = 200;
    
        OscP5 oscP5;
        NetAddress myRemoteLocation;
    
        void setup() {
          size(400,400);
          frameRate(25);
          oscP5 = new OscP5(this,12000);
    
          myRemoteLocation = new NetAddress("192.168.1.128",12000);
        }
    
    
        void draw() {
          background(0);  
          rectMode(CENTER);
    
          fill(circleColor, 0, 0);
          ellipse(width/2, height/2, 100, 100);
    
    
    
        }
    
    
        void oscEvent(OscMessage theOscMessage) {
    
          print("### received an osc message.");
          //print(" addrpattern: "+theOscMessage.addrPattern());
          println(" typetag: "+theOscMessage.typetag());
    
          if(theOscMessage.checkAddrPattern("poopin")==true) {
            println("it worked!");
    
          } else if (theOscMessage.checkAddrPattern("hello")==true) {
           println("yay, it worked!");
          }
    
        }
    
  • Change line 16 in your tablet code from 7000 to 12000. Does it solve your problem?

    Kf

  • same problem here, changin the port doesnt work, the sketch was working in android mode 3.0 but since i update it to 4.0 Osc fail. Does anyone have a solution?

  • Hey @Sesmusician , I'm having same problem here... Sending OSC from android device to laptop is working great, but the other way around fails. I'm getting BindException EADDRINUSE (address already in use) I've tried several different port numbers but it always fails...

    Has anybody found a solution?

    (with android mode 4.0)

  • edited December 2017

    Did you turn on the internet permission? For me that fixed it.

Sign In or Register to comment.