Go Down

Topic: TouchOSC via Ardosc/Bonjour (Read 4 times) previous topic - next topic

Headroom

If adding Bonjour functionality is still of interest I'll post it. Otherwise I tend not to reply to my own posts ;-)

gavspav

Hey thanks for posting this. It works. Especially once I've remembered to change the ip address in touch osc  :smiley-red:

I'm just back into it after the holiday break and to be honest can't remember what I am doing or why.

Now I've got your example working I'll start to build on it.

I guess I should get a teensy as memory issues are already hobbling me. I'd like to be able to store a few 'images' in memory for my 20 x 10 matrix.I did have a teensy before but snapped the usb port off it. Hate those mini usb ports!

So I guess in all honesty I haven't reached the bonjour stage yet. What I was thinking of was having ios and android devices being able to connect to the led matrix and interact collaboratively with the display. Maybe I'll do that this afternoon.

Thanks for the help. I'll report back!

Headroom

I am glad to hear that it worked for you!

The reason I have not not yet posted the Bonjour part is that I've been grinding my teeth on getting it to work on a WIZ820IO Ethernet Module, which employs the newer W5200 chip from Wiznet. I currently use a Teesny++2 with a  WIZ812MJ Ethernet Module. The Teensy++2 is available here http://www.pjrc.com/teensy/index.html and you can also find the adapter board for the WIZ812MJ there.

I have been able to get DHCP/ArdOSC/Bonjour working on the WIZ820IO as well, but for some reason there is a very noticeable lag when using ArdOSC. I am still investigating what the reason for it is. However,it works flawlessly - withaut any lag - with the WIZ812MJ.

I'e been working a slightly more complete code sample and will post it within the next few days.

justcansin

#8
Jan 03, 2013, 12:35 pm Last Edit: Jan 03, 2013, 12:39 pm by justcansin Reason: 1
good info to me, thanks for posting this. It works. Especially once I've remembered to change the ip address in touch os

Headroom

#9
Jan 04, 2013, 04:14 am Last Edit: Jan 04, 2013, 04:16 am by Headroom Reason: 1
So here is a little more complete code sample to also get the Bonjour part to work.

Code: [Select]

//DHCP/Bonjour-based OSC server test code
//for use with IDE 1.0.x
//for use with W5100 or W5200 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetBonjour.h>
#include <ArdOSC.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

//create instances of OSC server and client objects.
OSCServer server;
OSCClient client;

int serverPort  = 8000; //TouchOSC (incoming port)
int destPort = 9000;    //TouchOSC (outgoing port)
int ledPin =  6;        //pin 13 on Arduino Uno. Pin 6 on a Teensy++2
int flag=0;


void setup(){
 Serial.begin(115200);
 Serial.println("DHCP-Bonjour-based OSC server test 12/28/12");
 // 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();
 
// Initialize the Bonjour/MDNS library. You can now reach or ping this
// Arduino via the host name "arduino.local", provided that your operating
// system is Bonjour-enabled (such as MacOS X).
// Always call this before any other method!
 
   if (EthernetBonjour.begin("arduino")){
      Serial.println("Setting Bonjour Name successful");
   }
   else{    
     Serial.println("Bonjour Name could not be set");
   }
 
// Now let's register the service we're offering (a web service) via Bonjour!
// To do so, we call the addServiceRecord() method. The first argument is the
// name of our service instance and its type, separated by a dot. In this
// case, the service type is _osc. There are many other service types, use
// google to look up some common ones, but you can also invent your own
// service type, like _mycoolservice - As long as your clients know what to
// look for, you're good to go.
// The second argument is the port on which the service is running. This could be
// port 80 here, the standard HTTP port.
// The last argument is the protocol type of the service, either TCP or UDP.
// Of course, our OSC service is a UDPservice.
// With the service registered, it will show up in the Bonjour Browser on a Mac or
// in the Connections settings in TouchOSC

 if(
   EthernetBonjour.addServiceRecord("Arduino OSC Server._osc",
   8000,
   MDNSServiceUDP)){
   Serial.println("Bonjour Service Record added successfully");
  }
  else{    
     Serial.println("Bonjour Service could not be added");
  }  
 
 //Start the OSC server
 server.begin(serverPort);
 
 //Add callback functions for TouchOSC control element
 //One callback function is needed for each independent TouchOSC control element.
 server.addCallback("/OnOff/toggle1", &funcOnOff);
 server.addCallback("/Fader/Value", &funcValue);
}

void loop(){
 
// This actually runs the Bonjour module. YOU HAVE TO CALL THIS PERIODICALLY,
// OR NOTHING WILL WORK! Preferably, call it once per loop().
EthernetBonjour.run();

if(server.aviableCheck()>0){
    Serial.println("alive! ");
   }    
}


void funcOnOff(OSCMessage *_mes){
 float value = _mes->getArgFloat(0);
 
 //create new osc message
 OSCMessage newMes;
 
 //set destination ip address & port no
 newMes.setAddress(_mes->getIpAddress(),destPort);
 newMes.beginMessage("/OnOff/toggle1");
 
 if(flag==1){
   flag=0;
   Serial.println(value);
   digitalWrite(ledPin, LOW);
 }
 else{
   flag=1;
   Serial.println(value);
   digitalWrite(ledPin, HIGH);
 }
 newMes.addArgFloat(flag);
   
 //send osc message back to controll object in TouchOSC
 //Local feedback is turned off in the TouchOSC interface.
 //The button is turned on in TouchOSC interface whe the conrol receives this message.
 client.send(&newMes);
 
}

void funcValue(OSCMessage *_mes){

 long value = (int) _mes->getArgFloat(0);

 Serial.print("Value = : ");
 Serial.println(value);

  //create new osc message
 OSCMessage newMes;

 //set destination ip address & port no
 newMes.setAddress(_mes->getIpAddress(),destPort);
 newMes.beginMessage("/Fader/Value");
 newMes.addArgFloat(value);

 //send osc message
 client.send(&newMes);
}]//DHCP/Bonjour-based OSC server test code
//for use with IDE 1.0.x
//for use with W5100 or W5200 based ethernet shields

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetBonjour.h>
#include <ArdOSC.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

//create instances of OSC server and client objects.
OSCServer server;
OSCClient client;

int serverPort  = 8000; //TouchOSC (incoming port)
int destPort = 9000;    //TouchOSC (outgoing port)
int ledPin =  6;        //pin 13 on Arduino Uno. Pin 6 on a Teensy++2
int flag=0;


void setup(){
 Serial.begin(115200);
 Serial.println("DHCP-Bonjour-based OSC server test 12/28/12");
 // 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();
 
// Initialize the Bonjour/MDNS library. You can now reach or ping this
// Arduino via the host name "arduino.local", provided that your operating
// system is Bonjour-enabled (such as MacOS X).
// Always call this before any other method!
 
   if (EthernetBonjour.begin("arduino")){
      Serial.println("Setting Bonjour Name successful");
   }
   else{    
     Serial.println("Bonjour Name could not be set");
   }
 
// Now let's register the service we're offering (a web service) via Bonjour!
// To do so, we call the addServiceRecord() method. The first argument is the
// name of our service instance and its type, separated by a dot. In this
// case, the service type is _osc. There are many other service types, use
// google to look up some common ones, but you can also invent your own
// service type, like _mycoolservice - As long as your clients know what to
// look for, you're good to go.
// The second argument is the port on which the service is running. This could be
// port 80 here, the standard HTTP port.
// The last argument is the protocol type of the service, either TCP or UDP.
// Of course, our OSC service is a UDPservice.
// With the service registered, it will show up in the Bonjour Browser on a Mac or
// in the Connections settings in TouchOSC

 if(
   EthernetBonjour.addServiceRecord("Arduino OSC Server._osc",
   8000,
   MDNSServiceUDP)){
   Serial.println("Bonjour Service Record added successfully");
  }
  else{    
     Serial.println("Bonjour Service could not be added");
  }  
 
 //Start the OSC server
 server.begin(serverPort);
 
 //Add callback functions for TouchOSC control element
 //One callback function is needed for each independent TouchOSC control element.
 server.addCallback("/OnOff/toggle1", &funcOnOff);
 server.addCallback("/Fader/Value", &funcValue);
}

void loop(){
 
// This actually runs the Bonjour module. YOU HAVE TO CALL THIS PERIODICALLY,
// OR NOTHING WILL WORK! Preferably, call it once per loop().
EthernetBonjour.run();

if(server.aviableCheck()>0){
    Serial.println("alive! ");
   }    
}


void funcOnOff(OSCMessage *_mes){
 float value = _mes->getArgFloat(0);
 
 //create new osc message
 OSCMessage newMes;
 
 //set destination ip address & port no
 newMes.setAddress(_mes->getIpAddress(),destPort);
 newMes.beginMessage("/OnOff/toggle1");
 
 if(flag==1){
   flag=0;
   Serial.println(value);
   digitalWrite(ledPin, LOW);
 }
 else{
   flag=1;
   Serial.println(value);
   digitalWrite(ledPin, HIGH);
 }
 newMes.addArgFloat(flag);
   
 //send osc message back to controll object in TouchOSC
 //Local feedback is turned off in the TouchOSC interface.
 //The button is turned on in TouchOSC interface whe the conrol receives this message.
 client.send(&newMes);
 
}

void funcValue(OSCMessage *_mes){

 long value = (int) _mes->getArgFloat(0);

 Serial.print("Value = : ");
 Serial.println(value);

  //create new osc message
 OSCMessage newMes;

 //set destination ip address & port no
 newMes.setAddress(_mes->getIpAddress(),destPort);
 newMes.beginMessage("/Fader/Value");
 newMes.addArgFloat(value);

 //send osc message
 client.send(&newMes);
}




Go Up