Loading...
Logo
Processing Forum
Find an android-core.zip file under the Processing.app folder (it should be somewhere in the modes/android subfolder).
Unzip this file into another folder. You can call this another folder anything. Lets say "android-core-new".
You will find batch of .class files in this unziped folder - those are the core processing classes (processing.*).
Now unzip oscP5.jar file into the same folder. By doing this we are adding all the oscP5 classes to the set of processing core classes. After this step, we need to zip everything again:
zip -r ../android-core-with-osc.zip *

Now we need to rename the old android-core.zip file to something like android-core-original.zip and rename the new android-core-with-osc.zip to android-core.zip so that Processing picks up it as its core library.

That`s it.

     [echo] Running zip align on final apk...
     [echo] Debug Package: /var/folders/Ub/Ubx6N2U8EWeUCPbYJ7KSoE+++TI/-Tmp-/android1706105251410438287.pde/bin/osctest-debug.apk
OscP5 0.9.6 infos, comments, questions at http://www.sojamo.de/oscP5
### [2011/6/21 18:15:38] PROCESS @ OscP5 stopped.
### [2011/6/21 18:15:38] PROCESS @ UdpClient.openSocket udp socket initialized.
### [2011/6/21 18:15:39] PROCESS @ UdpServer.start() new Unicast DatagramSocket created @ port 5555
### [2011/6/21 18:15:39] PROCESS @ UdpServer.run() UdpServer is running @ 5555
### [2011/6/21 18:15:39] INFO @ OscP5 is running. you (127.0.0.1) are listening @ port 5555
aha!
wooooooooooooow!
aha!
aha!
yeah!
aha!
yeah!
aha!
yeah!
yeah!
yeah!
yeah!

Replies(19)

Neat, although there is an easier way:  just make a folder called "code" in your sketch folder and copy oscp5.jar into it :-)

Best,
d.

wish i would have known that sooner!
does this hold true for other libs/jars

i would love to know if toxiclibs would work this way too. we'll see i guess

This is the recommended way to add Libraries. 
Not all Libraries are Android-compatible (yet) however... 
but Toxiclibs has worked fine for me in the past...
Do I need to give permission to my OSC Android app?
Found it: CHANGE WIFI MULTICAST STATE. Works like charm! Thanks fellaz!
I wrote these couple of sketches to test connectivity. For some strange reason they work perfectly well in Processing mode but fail to connect when the client is in android mode. Frustrating since the sketch I'm working on uses lots of inputs. I've tried, poked and tested everything I could think of; sketch permissions, ip address, port numbers, parsing, etc. Still, the 'listener' does't get any data in Android mode. Any ideas?

//boadcast

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

float x;

void setup() {
  oscP5 = new OscP5(this, 11001);
  myRemoteLocation = new NetAddress("here goes your ip address", 11000); //SET YOUR IP ADDRESS!!!
}
void draw() {
  OscMessage myMessage = new OscMessage("/left");
  x=random(0, 255);
  myMessage.add(x);
  oscP5.send(myMessage, myRemoteLocation);
  println("sending"+x);
}


The listener:


import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

float v;

void setup() {
  size(300, 300);
  oscP5 = new OscP5(this, 11000);
  myRemoteLocation = new NetAddress("192.168.1.185.", 11001);// ip"192.168.1.185" with HTC Hotspot
  oscP5.plug(this, "levell", "left");
  oscP5.plug(this, "levelr", "/right");
  }
void oscEvent(OscMessage theOscMessage) {
  float value = theOscMessage.get(0).floatValue();
  v=value;
  if (theOscMessage.checkAddrPattern("/left")==true) {
    print("received "+value);
  }
}
  void draw() {
    background(v);
  }


I've also tried the plug method with similar result. 


Doesn't really help. The sketches work in Processing mode perfectly, it's only when I switch to Andorid mode when they don't.

hi, i am on osx 10.6 and the following works for me to send messages back and forth between a standard and an android sketch (running in the emulator):

1) copy the android sketch below into processing (android mode)
2) make sure the sketch permission for INTERNET is ticked
3) copy the standard sketch below into processing (standard mode)
4) start the emulator
5) use a terminal to telenet into localhost 5554 (more details see comments inside the android sketch)
6) then activate port redirection with redir add udp:12001:12001 (the redir will be lost when the emulator shuts down)
7) run your sketches
(the emulated device's own network ip 10.0.2.15 ( android network addresses) did not work for me, but the telnet does)


android sketch:

Copy code
  1. /* osc send-receive, android sketch */

  2. import oscP5.*;
  3. import netP5.*;
  4.   
  5. OscP5 oscP5;
  6. NetAddress myRemoteLocation;

  7. void setup() {
  8.   /* start listening on port 12001, incoming messages must be sent to port 12001 */
  9.   oscP5 = new OscP5(this,12001);
  10.   
  11.   /* after starting your android emulator,
  12.    * open a terminal (command line) and telnet into localhost on port 5554:
  13.    * telnet localhost 5554
  14.    * after a telnet connection has been successfully established, type:
  15.    * redir add udp:12001:12001
  16.    *
  17.    * once the emulator closes down the redirect will be obsolete
  18.    */
  19.    
  20.   /* your remote location, another sketch running in standard mode, can be 
  21.    * accessed from your emulated with ip 10.0.2.2
  22.    * the standard sketch will listen on port 12000
  23.    */ 
  24.    
  25.   myRemoteLocation = new NetAddress("10.0.2.2",12000);

  26. }

  27. float x;

  28. void draw() {
  29.   background(0);  
  30.   fill(255);
  31.   rect(x,0,100,100);  
  32. }

  33. void mousePressed() {
  34.   /* send a message to your remote location on mouse (touch) click */
  35.   
  36.   OscMessage myMessage = new OscMessage("/test");
  37.   myMessage.add(123);
  38.   oscP5.send(myMessage, myRemoteLocation); 
  39.   println("android sketch, sending to "+myRemoteLocation);
  40. }


  41. /* incoming osc message are forwarded to the oscEvent method. */
  42. void oscEvent(OscMessage theOscMessage) {
  43.   x = random(255);  
  44. }


standard sketch:


Copy code
  1. /* osc send-receive, standard sketch */

  2. import oscP5.*;
  3. import netP5.*;
  4.   
  5. OscP5 oscP5;
  6. NetAddress myRemoteLocation;

  7. void setup() {
  8.   size(400,400);
  9.   frameRate(25);
  10.   /* start oscP5, listening for incoming messages on port 12000 */
  11.   oscP5 = new OscP5(this,12000);
  12.   
  13.   /* the remote address, the address of the emulator using the telnet redir, 
  14.    * is the loopback address 127.0.0.1 
  15.    */
  16.   myRemoteLocation = new NetAddress("127.0.0.1",12001);
  17.   background(0);  
  18. }


  19. void draw() {}

  20. void mousePressed() {
  21.   OscMessage myMessage = new OscMessage("/test");
  22.   myMessage.add(123);
  23.   oscP5.send(myMessage, myRemoteLocation); 
  24.   println("standard sketch, sending to "+myRemoteLocation);
  25. }


  26. /* incoming osc message are forwarded to the oscEvent method. */
  27. void oscEvent(OscMessage theOscMessage) {
  28.   /* print the address pattern and the typetag of the received OscMessage */
  29.   print("### received an osc message.");
  30.   print(" addrpattern: "+theOscMessage.addrPattern());
  31.   println(" typetag: "+theOscMessage.typetag());
  32.   background(random(255));  
  33. }






It works perfectly with the emulator but i wonder how does it work with a phone?
the best scenario is to have both your phone and your computer on the same (local) network. To exchange data between both you need to know each others IP address and either hard code them into your program or do the configuration during runtime using e.g. a textfield for manual IP address input. 

You could also use the broadcast address of the network to which both your phone and your computer are connected to ( wikipedia.org/wiki/Broadcast_address). 

Then there is multicast which I am not sure if/how it works with a phone. There is the oscP5Multicast example that comes with oscP5. Using multicast will send out messages to a shared broadcast address. Messages are sent to all clients listening to that multicast address - messages will also be sent back to the sender.
Andreas, thanks for all the help! There is something that has never been clear to me and I hope you can clarify it. If the following example runs on the phone:

  oscP5 = new OscP5(this, "192.168.1.3", 11001); //computer's localhost ip
  myRemoteLocation = new NetAddress("192.168.1.185", 11000); //HTC phone ip

is it correct? I'm confused where do the two ip addresses go. Or is it the other way? Should the localhost be ip set in the myRemoteLocation? Either way, i've tried all combinations and I never get messages to the phone. Still, I'm not sure which ip address goes where.
I was even trying to telnet my phone with no success. I also tried the 10.0.2.2 and 127.0.0.1 ip address. They only work in one direction: phone to computer. 
lets use  192.168.1.3 for your computer's IP and  192.168.1.185 as your phone's IP address. they are both in the same local network, good. then use the following for your computer:

Copy code
  1. oscP5 = new OscP5(this, 11001); // computer starts listening on port 11001

  2. // HTC phone's address and port: messages will be sent to the following IP address and port
  3. myRemoteLocation = new NetAddress("192.168.1.185", 11000); 

and on the phone use:

Copy code
  1. oscP5 = new OscP5(this, 11000); // phone starts listening on port 11000

  2. // computer's address and port: messages will be sent to the following IP address and port
  3. myRemoteLocation = new NetAddress("192.168.1.3", 11001); 


Thanks very much! I just tried to set a different ip address for my phone (192.168.1.184) and use it with the sketches you provided. Still no incoming messages however I got the following error on the console while trying to send packets to the phone:

### [2011/8/7 17:15:7] ERROR @ UdpClient.send ioexception while sending packet.
standard sketch, sending to 192.168.1.184:12001


I've tried multicasting as well. Still no luck. Any ideas would be appreciated! 
That explains everything. Apparently the HTC Desire cannot receive any broadcast since the 2.1 update. Sucks... There's a fix on the market called HTP UDP Broadcast Fix but it requires a rooted phone... 


The OscP5 examples din't work on my phone. I couldn't send messages to my computer. The trick was to add the broadcast address instead of the phone's IP address or loopback address.

myBroadcastLocation = new NetAddress("192.168.0.255",12000);