Read specific string from list

Hi, I’m strugling how to read specific string using index number (not sure that C has the same functionality like Python).

Here is my code:

const char* ssid = "";
const char* password = "";

void setup(void)
{
...
server.on("/wifiArgs", handleWifiArgs); //Associate the handler function to the path
...
}

void handleWifiArgs() { //Handler

  String message = "";
  message += server.args();   //Get number of parameters
  message += "\n";               //Add a new line
  
  for (int i = 0; i < server.args(); i++) {
    message += server.arg(i) + "\n";  //Get the value of the parameter
  }
  Serial.println(message);
  server.send(200, "text/plain", message);   //Response to the HTTP request
}

void loop(void) {
  server.handleClient();
}

When you browse your webserver using URL like http://ipaddress/WifiArgs?ssid=abcd&pass=123456 message string returns following arguments:
2 //number of args
abcd //parameter from query
123456

My question is, how to print only abcd string, not entire list? Is it can be done using indexes like in Python or there is something different?

not sure that C has the same functionality like Python

it does not.

what do you think server.arg(i)represents in the for loop?

message += server.args();   //Get number of parameters

That is NOT what that function does.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

...R

PaulS:

message += server.args();   //Get number of parameters

That is NOT what that function does.

I’d have said that that was a pretty fair description of the args() method, but would probably have coded it in a less ambiguous way:

message += String( server.args() ) ;

Maybe you read it as the arg() method or then I am missing something.

Robin2:
It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

…R

Here we go again. Is anyone prepared to rewrite the ESP8266WebServer class or indeed the entire ESP8266 Arduino Core so that it is “String free” ?

6v6gt:
Here we go again. Is anyone prepared to rewrite the ESP8266WebServer class or indeed the entire ESP8266 Arduino Core so that it is "String free" ?

I did not see a mention of ESP8266 in the Original Post.

...R

Robin2:
I did not see a mention of ESP8266 in the Original Post.

...R

Unfortunately, he did not present his full code but these make it clear (with 99.99% certainty) that he is using the ESP8266WebServer class, naturally on an ESP8266 :

server.on()
server.args()
server.arg()
server.handleClient()

Is anyone prepared to rewrite the ESP8266WebServer class or indeed the entire ESP8266 Arduino Core so that it is "String free" ?

I am sorely tempted. It is begging for proper use of the Stream class as the I/O mechanism, not the String class. The interns that wrote this didn't know any better. :-/

-dev:

Is anyone prepared to rewrite the ESP8266WebServer class or indeed the entire ESP8266 Arduino Core so that it is "String free" ?

I am sorely tempted. It is begging for proper use of the Stream class as the I/O mechanism, not the String class. The interns that wrote this didn't know any better. :-/

I believe the author ( or "intern" as you refer to him ) of the ESP8266 Arduino Core was this person. I think he did a great job in making a powerful and low cost processor (which strongly outperforms the AVR 8 bit series in almost all respects) available to non professional programmers by integrating it in the Arduino ecosystem. That is entirely consistent with the Arduino ethos.

If you feel you can make a valuable contribution to this project, go ahead. It is all open source on Github.