// How to send OSC messages from an Arduino. // This Example is in the public domain. #include #include //uncomment this to use a software serial if you dont own a MEGA //#include //SoftwareSerial softSerial(softSerialRx,softSerialTx); WiFly wifly; OSCClient client(&wifly); //create new osc message OSCMessage global_mes; int globalIntValue=0; float globalFloatValue=1000; char* globalString="foo"; void setup() { Serial.begin(115200); //wifly.setBaud(115200); //wifly.save(); //use the convenient setup. Replace by if you use one. wifly.setupForUDP( &Serial, //the serial you want to use (this can also be a software serial) 115200, // if you use a hardware serial, I would recommend the full 115200 true, // should we try some other baudrates if the currently selected one fails? "hangar_nau3", //Your Wifi Name (SSID) "m1cr0fug4s", //Your Wifi Password "WiFly", // Device name for identification in the network "172.0.26.255", // IP Adress of the Wifly. if 0 (without quotes), it will use dhcp to get an ip 8001, // WiFly receive port "255.255.255.255", // Where to send outgoing Osc messages. "255.255.255.255" will send to all hosts in the subnet 8000, // outgoing port false // show debug information on Serial ); //wifly.printStatusInfo(); //print some debug information wifly.save(); } void loop() { //note that the destination adress is set by setting the remote host of the wifly! //three ways of sending messages... //simple but not as flexible: the convenience functions: client.sendInt(analogRead(A0),"/ard/A0Value"); client.sendFloat((float)analogRead(A1)*5.0/255.0,"/ard/A1Voltage"); //using a local message object allows to multiple additional parameters in a singel message: //loacal_mes,str is release by out of scope OSCMessage loacal_mes; loacal_mes.beginMessage("/ard/A2A3Value"); loacal_mes.addArgInt32(analogRead(A2)); loacal_mes.addArgInt32(analogRead(A3)); client.send(&loacal_mes); //using a global message object and some global variables works as well global_mes.beginMessage("/ard/status"); global_mes.addArgInt32(globalIntValue); global_mes.addArgFloat(globalFloatValue); global_mes.addArgString(globalString); client.send(&global_mes); global_mes.flush(); //object data clear globalIntValue++; globalFloatValue*=0.999; }