Z-OSC Library and Seeeduino Ethernet Shield Communication Issues

So I cant seem to get my Arduino on an Ethernet Shield to communicate with my iPhone running TouchOSC

This is my code, derived from a few different links i found.

#include <Z_OSC.h>

#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>

#include <SPI.h>

byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte myIp[] = { 192, 168, 1, 178 }; // Specify your arduino IP here
int serverPort = 8000; // and listening port as well

byte destIp[] = { 192, 168, 1, 5 }; // Your iPad/Android IP here
int destPort = 9000;

float ledOne;// delcare a variable for reading values

// create servo object to control a servo, remember to attach them in setup()
int ledPin = 9;

Z_OSCClient client;
Z_OSCServer server;
Z_OSCMessage *rcvMes;
Z_OSCMessage message;

void setup() {
pinMode (ledPin, OUTPUT);
Serial.begin(19200);
Ethernet.begin(myMac ,myIp);
server.sockOpen(serverPort);
digitalWrite (ledPin, HIGH);
delay (1000);
digitalWrite (ledPin, LOW);
Serial.println("BEGIN");
}

void loop(){
if(server.available()){
message.setAddress(destIp,destPort);
rcvMes=server.getMessage();

if( !strcmp( rcvMes->getZ_OSCAddress() , "/Lighting/toggle1" ) ) {
ledOne = rcvMes->getFloat(0);

if (ledOne > 0.5) {
digitalWrite(ledPin, HIGH);
message.setZ_OSCMessage( "/Lighting/label1" ,"s" , "ON" );
client.send(&message);
Serial.println("ON");
}

else if(ledOne < 0.5) {
digitalWrite(ledPin, LOW);
message.setZ_OSCMessage( "/Lighting/label1" ,"s" , "OFF" );
client.send(&message);
Serial.println("OFF");
}

}

}

}

I have the Arduino hardwired to my router, and powered via USB from my computer, and I have the TouchOSC settings with the host as the Arduino IP address and my phones IP in the code, yet I push the button and the LED does not light up on my Arduino. Im not really sure why as the OSC commands in the Editor are set correctly, and I cant seem to really find any good documentation on the Z-OSC library and the other OSC libraries seem complicated, so if anyone can provide me with a little help, that would be wonderful.

I did manage to get the TouchOSC app to work when the Arduino was communicating via Processing on my laptop, but I want the Arduino to be standalone, and eventually integrate the TouchOSC and Arduino with a relay shield into a form of Home Automation.

Anyways any thoughts would be appreciated.

      if( !strcmp( rcvMes->getZ_OSCAddress() ,  "/Lighting/toggle1" ) ) {
        ledOne = rcvMes->getFloat(0);

Why would be sending on or off as a float?

You have some Serial.print() statements in the code, but you showed no serial output. Feel free to add more Serial.print() statements, and to share the output.

PaulS:

      if( !strcmp( rcvMes->getZ_OSCAddress() ,  "/Lighting/toggle1" ) ) {

ledOne = rcvMes->getFloat(0);



Why would be sending on or off as a float?

You have some Serial.print() statements in the code, but you showed no serial output. Feel free to add more Serial.print() statements, and to share the output.

Im not really sure i understand the first part. The OSC Message should be sending a 1 or 0, then depending on that, the arduino will write HIGH or LOW then print ON or OFF to the serial bus

The OSC Message should be sending a 1 or 0,

That's my assumption, too. So, why are you assuming that getFloat() is the correct function to read the value? I'd expect that the value would be an int, and that getFloat() would be the wrong function to use.

I see. well I will probably come back to this thread as i cant even get the basic webserver sketch to work on this setup.

The first thing to know about TouchOSC is that it only sends and receives float values.

In general, however I would not work with the Z-OSC library.
I'd recommend using Oscuino, which is the Arduino OSC library created and actively maintained by the inventors of the OCS protocol at CNMAT : GitHub - CNMAT/OSC: OSC: Arduino and Teensy implementation of OSC encoding

I am not at my computer at the moment but can post some code later how to get that to work with TouchOSC.

Edit: I just checked the Seed Studio website. It appears that they have a Ethernet Shield V1 that hosts the Wiznet W5100 Ethernet chip and a V2 that hosts the W5200 Ethernet shield. Which one do you have ?
Both work, but the W5200 is much more performant. It depends on what you want to do if that's an issue. Based on my experience with both chips for TouchOSC it won't make a difference.

I use TouchOSC to remote control my lighting systems (see sig)

so, i got the shield working with a library provided by seeed. then i used a piece of edited code someone made here - W5200 ETHERNET SHIELD compatibily problems - Networking, Protocols, and Devices - Arduino Forum

so now i can ping the IP of the arduino. I also using the ArdOSC library I was able to at least see TouchOSC sending activity to the arduino, however the arduino still refuses to light up the LED.

I will try the OSCuino library as well.

more updates. i succcesfully have communication from the arduino to OSC. however i still cant get that damn LED to light up.

so i downloaded the OSCuino library and its the best function ive gotten from the arduino yet. I am constantly receiving OSC to the phone telling me the state of the LED, however I cannot turn the LED on or off. Also, while messing with the LED the negative leg was connected to GND and i touched the positive leg and it lit up....could this be an issue?

Also i have the W5200 model of wiznet.

here is my basic OSCuino code.

// MESSAGE PROTOCOL OBJECT
#include <OscUDP.h>


// hardware libraries to access use the shield
#include <SPI.h>        
#include <Ethernet.h>
#include <EthernetUdp.h>


// arduino needs us to start ethernet, then start UDP
// http://arduino.cc/en/Reference/EthernetBegin


// Enter a MAC address and IP address for your SHIELD.
// The IP address will be dependent on your local network
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// listeningIP ==  SHIELD initialization IP
IPAddress listeningIP(192,168,1,177); // you need to set this

// listening -- port
unsigned int listeningPort = 10000;      // local port to listen on


// speaking 
// set up our destination NODE
NetAddress destination;
IPAddress destinationIP( 192,168,1,5 ); 
int destinationPort = 12000;

#define W5200_CS  10
#define SDCARD_CS 4

// setup a UDP object
EthernetUDP UDP;

// OUR OSC MESSAGE OBJECT
OscUDP etherOSC;  

// timer variable
long timer;



void setup() {
  
  // some local debug -- we can see this in serial port
  Serial.begin(9600);
  pinMode(SDCARD_CS,OUTPUT);
  digitalWrite(SDCARD_CS,HIGH);//Deselect the SD card
  // start ethernet on the shield
  Ethernet.begin(mac,listeningIP);
  
  // print Arduino's IP
  Serial.println(Ethernet.localIP());
  
  // start UDP object, listening on port listeningPort
  UDP.begin(listeningPort);
  
  // set up our communication protocol
  // pass the UDP object to OSC
  etherOSC.begin(UDP);
  
  // define our destination location
  destination.set(destinationIP, destinationPort);
  
  // local hardware setup 
  pinMode(9, OUTPUT); // note can't use 13 for UDP becasue of shield
  Serial.println("starting");
  
}

void loop() {
  // send a message every 100 ms
  
  // avoid using delay() since it just blocks everything  
  // so here is a simple timer that controls how often we send
  long now = millis();
  if (now-timer > 100) {
    // build a message, start with address pattern
    OscMessage msg("/arduinoEthernetSays");
    
    // add a data point (can add many)
    msg.add(digitalRead(2)); // <-- this could be any data -- its our LED state 
    
    // actually do the sending
    etherOSC.send(msg, destination);
    
    // reset the timer
    timer = now;
    
    // local debug -- you can get rid of this
    Serial.println("send one");
  } // end if
  
  
  // important! non-blocking listen routine
  etherOSC.listen();  // if there is data waiting, this will trigger OSC EVENT

}


void oscEvent(OscMessage &m) { // *note the & before msg
  // receive a message 
  Serial.println("got a message");
  // in arduino, we plug events in the EVENT method
  m.plug("/led", myFunction); 
  
}


void myFunction(OscMessage &m) {  // *note the & before msg
  // getting to the message data 
  Serial.println("led");
  
  // getType takes position as a parameter
  int value = m.getInt(0); 
  if (value == 0) digitalWrite(9, LOW);
  if (value == 1) digitalWrite(9, HIGH);
  
}

I've posted a Sketch and sample TouchOSC layout on my GitHub repo:

I will post a step-by-step tutorial later on my blog (trippylighting.com). This will also include an updated sketch on how to get this working using Apple Bonjour (ZeroConf networking).