1

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();
VE7JRO
2,51519 gold badges27 silver badges29 bronze badges
asked Jan 2, 2019 at 17:52
4
  • google arduino parsing strings Commented Jan 2, 2019 at 17:55
  • Thanks, i have tried to implement some methods unsuccessfully. i simply do not have the experience especially since the content required varies in length. i was hoping to get an example if possible. Commented Jan 2, 2019 at 18:00
  • do you have any control over the URL format ....maybe you need to use something like 192.168.1.220?s=1&s2=4&s3=8&d=1&abcd=1234 Commented Jan 2, 2019 at 18:11
  • will this method retain the letters or does it strip to numbers? Commented Jan 2, 2019 at 18:55

2 Answers 2

1

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(); 
 }
}
answered Jan 2, 2019 at 18:35
2
  • Thank you, will apply solution and revert. Commented Jan 2, 2019 at 18:54
  • @s-b, did it help? Commented Jan 29, 2019 at 19:51
0

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);
answered Oct 31, 2019 at 6:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.