Howdy,
i have made up a module that uses an Arduino + WiShield to act as an ADHOC wifi AP. All is good I can send data from the iphone and output it over serial to my PC.
I need to monitor the data that comes in, and place it into 3 values: X,Y,Z - I suck at programming and am a noob at arrays, I need some help!
Here is my code that gets the data, and outputs it over serial. I think I need to 1st look at the data coming in, and spilt into 4 values delimited by a space and then I can do what I need to do with these values - then output.
The data comes in like this:
accel 0.056 -0.072 -1.047
This is the code I have running. I am detecting the carriage return as the terminator (int cr = 10;).
void loop()
{
if(!client.connected()) {
server.available(&client);
}
else {
if (Serial.available() > 0)
{
client.print((char)Serial.read());
last_serial=millis();
}
else
{
if ( millis()-last_serial > 10 )
client.sendnow();
}
while(client.available()) {
char c = (char)client.read();
if (c == cr){
Serial.println("");
Serial.println("-----------------------------");
}
else{
Serial.print(c);
}
}
}
}
Any ideas on how i can turn accel 0.056 -0.072 -1.047 into:
0.056
-0.072
-1.047
Many thanks 
Have a look at the String class. I believe it has some member functions you can use to parse that.
Hi,
Ok I have this working, it is converting the output from the connected socket into 3 vars - ace but I need to use integers so I can map the values?
I have tried atoi etc but I can't seem to get anything to work...
Any ideas?
Cheers.
int cr = 10;
int space = 32;
int l = 108;
String valx;
String valy;
String valz;
int valcounter = 0;
void loop()
{
if(!client.connected()) {
server.available(&client);
}
else {
while(client.available()) {
char c = (char)client.read();
int i = 0;
if (c == cr){
Serial.print("X:");
Serial.println(valx);
Serial.print("Y:");
Serial.println(valy);
Serial.print("Z:");
Serial.println(valz);
valx = "";
valy = "";
valz = "";
valcounter = 0;
}
else if (c == space){
valcounter ++;
}
else if (c == l){
valcounter = 0;
}
else{
if (valcounter == 1)
{
valx.concat(c);
}
if (valcounter == 2)
{
valy.concat(c);
}
if (valcounter == 3)
{
valz.concat(c);
}
}
}
}
}
Okay, I give up, where did you call atoi() ??? That would be the correct function to use.
I removed it because it causes a
error: cannot convert 'String' to 'const char*' for argument '1' to 'int atoi(const char*)'
It was here:
char c = (char)client.read();
int i = 0;
if (c == cr){
int valx_1 = atoi(valx);
Serial.print("X:");
Serial.println(valx_1);
I am probably doing this the wrong way from the start, but I honestly can't figure out another way to split the stream into 3 values 
Any method that works is fine, but the thing I was suggestion in the earlier post was to put the characters into a String object. Then, you can use the methods indexof() and substring(). The method indexof(" ") will return the index of the first space char. Then you can use substring() to extract it. You go on like that.
Once you have it by any method, atoi() should convery it to an int for you:
int i = atoi("123");
Then you can use substring() to extract it.
As a String object that can not be passed to the atoi() function. That is the same problem that OP is trying to address.
The String object (and it is apparent that you are using an older version) has a method to extract the char array that it manages. For the newer version of the String object, that function is called toCharArray(). OP, you'll need to look in the library header file to figure out what that method is for your version.
Once you have extracted the character array, you can pass it to atoi().