iPhone -> OSC -> Ethernet Shield (message from touchOSC problem)

Hi,
I’m having trouble making the link between the iPhone and the Ethernet Shield.
I used the code from an example that uses the app Ardumote, but since I have the touchOSC I had to make some alterations to the code, and that is probably where the problem lies. The alterations I made correspond to the argument sent by the app. For example, in Ardumote, one of them is “PWMXXX” that works as a potentiometer in which “XXX” represents values from 0 to 255, but since I use touchOSC, instead of “PWMXXX” appears "/PWM XXX".
Note: the XXX from toushOSC are decimals: ex. 253.367823
So before, a part of the code appeared this way:
// Assuming our packBuff's contents at index values 3-5 are our PWM values, you can convert them to an int using this:

pwmVal = (packBuff[3] - '0')*100 + (packBuff[4] - '0')*10 + (packBuff[5] - '0'); //Get PWMXXX message, and use XXX to set an int between 0 and 255.

//////////////////////// Pin 6 (LED_Pin) /////////////////////////////////////

if (packBuff[0] = 'P' && packBuff[1]=='W' && packBuff[2]=='M') // Wait for "PWMXXX" and use XXX as value for PWM
{
And now it appears this way:
// Assuming our packBuff's contents at index values 3-5 are our PWM values, you can convert them to an int using this:

pwmVal = (packBuff[5] - '0')*100 + (packBuff[6] - '0')*10 + (packBuff[7] - '0'); //Get PWMXXX message, and use XXX to set an int between 0 and 255.

//////////////////////// Pin 6 (LED_Pin) /////////////////////////////////////

if (packBuff[0] = '/' && packBuff[1]=='P' && packBuff[2]=='W' && packBuff[3]=='M' && packBuff[4]==' ') // Wait for "PWMXXX" and use XXX as value for PWM
{

One of my questions is if I can declare the existent space between /PWM XXX as && packBuff[4]==' '
Another question is if this part of the code (below) has to be altered as well, since the argument has more characters…
packetSize = packetSize - 8; // subtract the 8 byte header

Regarding the communication part, wifi, everything seems ok. Actually, when I touch the app in the iPhone I see the Ethernet Shield receiving information, only it is not transmitted afterwards, in this case, to the LED.
I’m using Arduino Uno and the Ethernet Shield (Wiznet W5100), and I think there’s also no problem with the libraries…
I really think the problem is in the argument sent by the iPhone app and the way it is filtered.
Here’s the link for the original code I’m using:
http://www.samratamin.com/Ardumote_files/Ardumote_Example_IDE1_0.ino

I would appreciate any kind of help…

Thank you!

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

#include <SPI.h> // for Arduino later than ver 0018
#include <EthernetUdp.h> // UDP library from bjoern@cs.stanford.edu
#include <Ethernet.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x7C, 0x51 }; //Set your Ethernet Shield's MAC address here - make sure you replace the ZZs with your shield's values!
byte ip[] = { 192,170,1,3 }; // Set your shield's desired IP address here - check your network for configuration details
//byte gateway[] = { 192,168,1,1 }; //if you need to set a gateway IP
//byte subnet[] = { 255,255,255,0 }; // Change this to your subnet address

unsigned int localPort = 7777; // local port to listen on (set this the same as Port # on Ardumote Params Screen)

int LED_Pin = 6; //Set LED_Pin to Pin 6 - Place an LED on Pin 6 of your ethernet shield for testing this code

// buffers for receiving and sending data
char packBuff[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,

EthernetUDP Udp;

void setup() {

// start the Ethernet and UDP:
Ethernet.begin(mac,ip); // If you don't need to set your default gateway or subnet manually, use this
// Ethernet.begin(mac,ip,gateway,subnet); // Use this line instead if you've manually set all the parameters
Udp.begin(localPort); //Setup UDP socket on port defined earlier

Serial.begin(9600); //Start Serial Communications with PC

pinMode(LED_Pin,OUTPUT); //Designate pin 6 as Output Pin

}

void loop()
{

int pwmVal; // Integer that will hold our PWM values for later use

// if there's data available, read a packet
int packetSize = Udp.parsePacket(); // note that this includes the UDP header
if(packetSize)
{
packetSize = packetSize - 8; // subtract the 8 byte header
Serial.print("Packet size: ");
Serial.println(packetSize);
// read the packet into packetBuffer and get the senders IP addr and port number
Udp.read(packBuff,UDP_TX_PACKET_MAX_SIZE);
Serial.println("Message: ");
Serial.println(packBuff);

/* PWM - If we move a slider on Ardumote, it sends in a 3 digit value attached to the message of the slider.

For example, if your message is set to be "PWM" and your slider is halfway set (slider value is 127),
then your actual sent message will be received as "PWM127". Therefore, to set the Pin's PWM value, you simply
extract the last 3 digits of your message and use that as your PWM value (see below):

*/

// Assuming our packBuff's contents at index values 3-5 are our PWM values, you can convert them to an int using this:

pwmVal = (packBuff[5] - '0')*100 + (packBuff[6] - '0')*10 + (packBuff[7] - '0'); //Get PWMXXX message, and use XXX to set an int between 0 and 255.

//////////////////////// Pin 6 (LED_Pin) /////////////////////////////////////

if (packBuff[0] = '/' && packBuff[1]=='P' && packBuff[2]=='W' && packBuff[3]=='M' && packBuff[4]==' ') // Wait for "PWMXXX" and use XXX as value for PWM
{

analogWrite(LED_Pin,pwmVal); //Set LED_Pin to PWM Value

Serial.println("PWM on Pin 6"); //Write notification

}

else if (packBuff[0] = '/' && packBuff[1]=='P' && packBuff[2]=='6' && packBuff[3]==' ' && packBuff[4]=='1') // If we get the message "/P6 1", then set LED_Pin (6) HIGH
{
digitalWrite(LED_Pin,HIGH); //Turn on LED_Pin

Serial.println("LED ON"); //Write notification

}

else if (packBuff[0] = '/' && packBuff[1]=='P' && packBuff[2]=='6' && packBuff[3]==' ' && packBuff[4]=='0') // If we get the message "/P6 0", then set LED_Pin (6) LOW
{

digitalWrite(LED_Pin,LOW); //Turn off LED_Pin

Serial.println("LED OFF"); //Write notification
}

}

delay(20);
}

I came across this post while searching the forum for information relating to touchOSC, OSC, ArdOSC etc.

I have an application working with an Asynclabs WShield clone (Linksprite Cooperhead) in conjunction with Ardumote.
Ardumote is not using the OSC protocol for communications but sends simple text strings or integer values.

TouchOSC, however, is obviously an app that uses OSC and it's values are of type "float". It would serve you well to read through the OSC specification on http://opensoundcontrol.org/spec-1_0 to get a better understanding of the protocol and how to interpret it's data.

Also, there already are Arduino OSC libraries that will help you do that. Recotana's ARDosc GitHub - recotana/ArdOSC: Open Sound Control(OSC) Library for Arduino (tested Arduino 1.0-rc1 & Arduino Ethernet) is one of them.