Help with ofxOsc - Trying to receive OSC data from andOSC (Android)

Hello everyone,

this is my first post and I guess there will be more, since I’ve just started learning OF.

I’m trying to understand how ofxOsc works. I’ve looked at the receiver example (oscReceiveExample), but do not really understand it and did not manage to have it reading data from andOSC.

andOSC is quite a simple android application which allows you setting an IP and a Port where to send the data. Then it starts sending the following:

  • Touch coordinates: -msg:/touch (two float values)
  • Accelerometer: - msg:/acc (three float values)
  • Orientation:- msg:/ori (three integer values)

I was able to set this up in PureData and it works so I’m sure the PC is receiving the data properly.

Could anyone post or point me to a commented code which would actually read and cout these three parameters?

I would also greatly appreciate if anyone could point me to any other commented examples and/or documentation for a newbee to learn ofxOSC.

I’m using OF v07003 with code:blocks running on W7.

Thanks in advance.

Hi

Did you check the official example?
This is not the code you specifically need but it is commented and listens for OSC messages
https://github.com/openframeworks/openFrameworks/tree/master/examples/addons/oscReceiveExample/src

Hi Underdoeg and thank you for trying,

yes, I had a look at the example, but I’m probably not smart enough :frowning: and need even more comments.

I thought that, same as in pure data, I “only” had to change “/mouse/position” (see below as copied from the oscReceiveExample testApp.cpp) by “/touch”. This is the OSC message andOSC sends out with the coordinates of the point touched on the phone´s screen. However it does not seem to go through the “if” statement (I tried cout some text inside the if). I’m wondering whether the “/mouse” refers to the sending device, rather than the variable being sent. The thing is that in Pure Data it works immediately and it only needs the port and the “/touch” information.

  
	  
// check for mouse moved message  
if(m.getAddress() == "/mouse/position"){  
// both the arguments are int32's  
mouseX = m.getArgAsInt32(0);  
mouseY = m.getArgAsInt32(1);  
  

However what I really want is to learn how to work with ofxOsc. So any help/suggestion will be greatly appreciated.

Gaspar

you are correct that you would need to change the message address received to match the one being sent by your android app (so “/mouse/position” to “/touch”). the “/mouse/position” is just a longer address making it more specific and does not refer to any device. it could have been just “/position” for example as long as both sender and receiver used the same.

one thing to try is printing out the address of the messages being received in your app:

  
  
while(receiver.hasWaitingMessages()){  
	ofxOscMessage m;  
	receiver.getNextMessage(&m);  
	string msg_string = m.getAddress();  
	cout << msg_string << endl;  
}  
  

if you don’t see any incoming messages, perhaps the problem is with the port or ip address.

Muchas Gracias Chris,

:-[
it finally was a FIREWALL issue. But it was your code which made me confident to look at it.

As communication was open for Pure Data I thought it would go through. Also the firewall was set to tell me if a programm was being blocked, but it dit not. As soon as I turned the firewall off, data begun to flow.

THANKs again.

yep, i’ve certainly had firewall issues before as well :slight_smile:
great to hear you solved it!