These are some functions I use to help me search for stuff int strings. you could use these to find the start and end of what you want and dump the rest
PaulS:
You can't. You have NO control over what the server sends.
You could, of course, read and discard all the data, until the blank line arrives. When that happens, you could then store the data.
Hmmm, i undertand, but how i can do this?
zhomeslice:
These are some functions I use to help me search for stuff int strings. you could use these to find the start and end of what you want and dump the rest
int strpos(String haystack, String needle,int offset)
Here is some examples as to how the functions work while searching for the start and end of what you are looking for in the returned strings
char *Haystack = "This is a test schetch and it dimonstrates the strpos() and str_replace() funcitons.";
char *Needle = "and";
String HaystackString = "I perfer using char * for strings but you can do it this way also";
String NeedleString = "you can do it";
int pos;
String NewString;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200); // diagnostic channel
Serial.println(Haystack);
// using char *
pos = strpos(Haystack,Needle,0); // Haystack is what you are looking in, Needle is what you are looking for, offset is to start looking at a point further into the string
Serial.print("We found the first and at:"); Serial.println(pos);
pos = strpos(Haystack,Needle,pos + 1); // Lets start looking for the second instance of and by offsetting the start by one character from the first instance of and
Serial.print("We found the Second and at:"); Serial.println(pos);
// using String
pos = strpos(HaystackString,NeedleString,0); // Lets start looking for the second instance of and by offsetting the start by one character from the first instance of and
Serial.print("We found the 'you can do it' at:"); Serial.println(pos);
NewString = str_replace("this way also", "like this", HaystackString);
Serial.print("OldString:"); Serial.println(HaystackString);
Serial.print("NewString:"); Serial.println(NewString);
}
void loop() {
// put your main code here, to run repeatedly:
}
int strpos(String haystack, String needle, int offset)
{
int foundpos = -1;
for (offset; (offset <= haystack.length() - needle.length()); offset++) {
if (haystack.substring(offset, needle.length() + offset) == needle) {
foundpos = offset;
}
}
return foundpos;
}
int strpos(char * haystack, char * needle, int offset)
{
char * Pointer;
Pointer = strstr(haystack + offset, needle) + offset;
return (&Pointer[0] - &haystack[0]);
}
String str_replace(String Search, String Replace, String Subject) {
Subject.replace(Search, Replace);
return (Subject);
}
Once you get the String.x example running, and understand the logic... rewrite it without the String class (using C char handling).
Less memory, faster and far more flexible.
Since you only need to store at most 3 characters to determine if it is time to store the important data, that example, while interesting, is not necessary.
If you get a \n, save it. If not, discard it. If the next character is a \r (as it should be), you have received an end of record marker. If the next character is not a \n, the line is not blank, so you don't care about that data.
A brute force method to do this is:
Save each character read into the last element of a 4 element array, after shifting the existing last three characters up a position.
Compare the array to "\n\r\n\r". If they match, then the remaining data coming from the server is the data you want. If not, keep reading and checking.