I am sending strings to an Esp8266 via web browser.
The below code returns the following in serial monitor if I send in browser:
Send from browser to esp8266 - http://192.168.1.220/s1s2s3s4s5d1
Receive in Arduino Serial monitor - GET /s1s2s3s4s5d2 HTTP/1.1
How do i read only the contents s1s2s3s4s5d1 ? This content can vary in length, numbers could be double digits but alphabets will remain in between.
Please note I am still a novice.
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
2 Answers 2
I have this
if (client.connected()) {
if (client.available() && client.find(' ')) { // GET /fn HTTP/1.1
char fn[20];
int l = client.readBytesUntil(' ', fn, sizeof(fn));
fn[l] = 0;
while (client.read() != -1);
Serial.println(fn);
client.stop();
}
}
-
Thank you, will apply solution and revert.S B– S B2019年01月02日 18:54:12 +00:00Commented Jan 2, 2019 at 18:54
-
you can try something like this
int first_space = request.indexOf(' '); // location of the first space
int second_space = request.indexOf(' ', first_space); // the next space after first
String query_arg = request.substring(first_space,second_space);
arduino parsing strings