sending osc to arduino -> receiving something, but what?

hi guys, i need your help again:

i m trying to send an osc message from my of application to an ethernet arduino. I am able to receive input but i am not able to read out any values: i m wondering if you can help me:

of in header

  
  
#define HOST "192.168.178.130" //arduino ip  
#define RPORT 12000 //incoming  
#define SPORT 10000 //outgoing  
#define NUM_MSG_STRINGS 100  
  

in cpp

  
  
cout << "listening for osc messages on port " << RPORT << "\n";  
	receiver.setup(RPORT); //set up receiver  
	sender.setup(HOST, SPORT); //set up sender  
  
  

of sending function

  
  
void oscc::sendMessages(){  
	  
	ofxOscMessage m;  
	m.setAddress("/Eth_ArdOSC/toggle2");  
	m.addFloatArg(3.0);  
	sender.sendMessage(m);  
	}	  
  

the arduino code

  
  
  
#include <SPI.h>  
#include <Ethernet.h>  
  
#include <ArdOSC.h>  
  
OSCServer server;  
OSCClient client;  
  
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  
  
int  serverPort=10000; //OF incoming port  
int destPort=12000; //OF outcoming port  
  
float wert;  
int flag=0;  
  
void setup(){   
  
 Serial.begin(115200);   
  Serial.println("DNS and DHCP-based OSC server");  
  // start the Ethernet connection:  
  if (Ethernet.begin(mac) == 0) {  
    Serial.println("Failed to configure Ethernet using DHCP");  
    // no point in carrying on, so do nothing forevermore:  
    while(true);  
  }  
  // print your local IP address:  
  Serial.print("Arduino IP address: ");  
  for (byte thisByte = 0; thisByte < 4; thisByte++) {  
    // print the value of each byte of the IP address:  
    Serial.print(Ethernet.localIP()[thisByte], DEC);  
    Serial.print(".");   
  }  
  Serial.println();  
  Serial.println();  
    
  //start the OSCserver  
  server.begin(serverPort);  
    
  //add OSC callback function. One function is needed for every TouchOSC interface element that is to send/receive OSC commands.  
  server.addCallback("/Eth_ArdOSC/toggle2", &funcOnOff);  
}  
    
void loop(){  
    
if(server.aviableCheck()>0){  
     Serial.println("alive! ");  
      Serial.println(wert);  
    }      
}   
  
  
void funcOnOff(OSCMessage *_mes){  
  float value = _mes->getArgFloat(0);   
  //create new osc message  
  wert=value;  
  OSCMessage newMes;  
    
  //set destination ip address & port no  
  newMes.setAddress(_mes->getIpAddress(),destPort);  
  newMes.beginMessage("/Eth_ArdOSC/toggle1");  
    
  newMes.addArgFloat(value);  
  client.send(&newMes);  
}  
  
  

the serial board output (when starting the sending osc function in of by pressing a key):

  
  
?óDNS and DHCP-based OSC server  
Arduino IP address: 192.168.178.130.  
  
alive!   
0.00  
alive!   
0.00  
alive!   
0.00  
alive!   
0.00  
alive!   
0.00  
  

so it should write 3.00 not 0.00… :frowning:

Which arduino osc library are you using? If your using ardOSC, it doesn’t accept OSC bundles- only simple messages. But this can be easily fixed from the OF side. There’s a thread here which worked for me-http://forum.openframeworks.cc/t/osc-from-of-to-arduino/6563/0

It works !!!
Dude you saved my life !!!

great community, thanks a lot

hm, it would seem appropriate to report a bug against Z_OSC or ardOSC. bundles are a part of the OSC spec, after all…

edit: ah great, there is already a bug report: https://github.com/recotana/ArdOSC/issues/3

well i’m running into some problems when i send more than 2 messages from open frameworks, could this have something to do with the bundle thing.

  
  
void oscc::sendMessages(){  
	  
	ofxOscMessage m;  
	m.setAddress("/head/visual");  
	m.addIntArg(r); //first value  
	m.addIntArg(g); //second value  
        m.addIntArg(b); //third value  
 	m.addIntArg(b); //test value  
	sender.sendMessage(m);  
  

i receive the values at the arduino, pass them to red, green, blue etc. and send them back TO OF:

  
  
red = _mes->getArgInt32(0);   
green = _mes->getArgInt32(1);  
blue =_mes->getArgInt32(2);  
val = _mes->getArgInt32(3); //test value   
    
      
  //pass roll, pitch, yaw to variable for sending, as Degrees   
  oscRoll=ToDeg(roll);  
  oscPitch=ToDeg(pitch);  
  oscYaw=ToDeg(yaw);  
    
  OSCMessage newMes; //create new osc message  
    
  //set destination ip address & port no  
  newMes.setAddress(_mes->getIpAddress(),destPort);  
  newMes.beginMessage("/head/direction");  
   
  newMes.addArgFloat(oscRoll);  
  newMes.addArgFloat(oscPitch);  
  newMes.addArgFloat(oscYaw);  
    
  newMes.addArgInt32(red);  
  newMes.addArgInt32(green);  
  newMes.addArgInt32(blue);  
  newMes.addArgInt32(val);  
    
  //send osc message  
  server.stop(); //stop server while sending  
  client.send(&newMes);  
  server.begin(serverPort); //start server  
  
  

  
  
		if(m.getAddress() == "/head/direction"){  
			roll= m.getArgAsFloat(0); //get first value  
			pitch= m.getArgAsFloat(1); //get second value  
			yawDeg= m.getArgAsFloat(2); //get third value  
			yawDeg=yawDeg+180; //360 degrees for opengl  
			r_r=m.getArgAsInt32(3);  
			g_r=m.getArgAsInt32(4);  
			b_r=m.getArgAsInt32(5);  
                        test=m.getArgAsInt32(6);		  
		}  
  

b_r has the blue values but switches back to 69 all the time
test is some random number around 1204. The values are ok when i send them.

i did some further testing and it really has to do with the third (2) message i am sending from open frameworks, perhaps ardosc can’t handle more than 2 messages with the work around i was pointed to earlier. Since i am on a short deadline any help will be much appreciated. do you know some easy way to get the two color values into one message, that i can decode in the arduino? thanks, nixon

you could convert r,g,b,a into hex (i.e. 054F36FF format), and send that as a string?

good idea, how do i get it in this format? I tried something like:

  
  
string hexString=ofToString(hsb.getHex());  
  

whereby hsb is my ofColor object.
But I get only the decimal representation.

did you try ofHexToString()? http://www.openframeworks.cc/documentation/utils/ofUtils.html#ofHexToString
or maybe http://www.openframeworks.cc/documentation/utils/ofUtils.html#ofVAArgsToString

i tried ofhextostring before, but don’t seem to understand it properly.

  
  
string hexString=ofHexToString(hsb.getHex());  
  

i get : invalid conversion from int to const char

well the wrong message was somehow produced by the serial.printout function in printdata(). Now everything works perfect. Thanks for the help. Nixon