I am kind of lost at the logic. I am reading chars from HTTP server which has my data.
The data example [34.45 33.21 32.12 35.42]. So after each data there is space.
This is how I read the data. i is just a counter.
while(client.available()){
char c = client.read();
Serial.print(c);
dataArray[i] = c;
i++;
if (c == ' '){
Serial.println();
}
}
What I want is I will read the data until space comes then that will be my first variable of an float array. I am lost in loops and couldn't figure out the logic.
Put each character into an array of chars as it is received. When it is complete split the array into individual variables or elements of an array of floats using the strtok() function
Yes, I realized that, I was editing my post, but you replied so fast, so I cancelled and replied to you. I can do it without storing as well. So until space I will get as chars, convert it to float , use it for something, then delete it. This is also fine.
You can probably use: float value = client.parseFloat();
That will skip characters until it finds a number and read the number until it finds a character that isn't part of a number.
Just in case you were not aware, atof returns 0.0 if the line does not parse correctly.
May not be a problem in your case if 0.0 is not a valid input OR you can guarantee to never get any input data errors.
If you want a pre-packaged function that does test for a valid float, take a look at my SafeString library which has the unsigned char toFloat(float& fResult);
method which returns non-zero and updates the fResult ONLY if the SafeString contains a valid float with optional leading and trailing white space but nothing more.
Hi @johnwasser. This is actually really useful. However there is some gibberish data coming. I couldn't find the reason. I already read if there is any data left in the buffer via