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 wellbyte 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.