I am trying to indexof() the address of my webserver that is changed by checkboxes on the webpage.
For example: if I press checkbox 1, either GET /c1/1 or GET /c1/0 (depending on the state of the boxwhen pressed) is added to the address. When I print cON to the serial monitor when x=1, it displays "GET /c1/1" but the if statement does not get satisfied.
However, when I modify the code and substitute "GET /c1/1" in for cON or "GET /c1/0" for cOFF, the if statement is able to be satisfied.
for (int x = 1; x <= 10; x++) {
String cON = "\"GET /c" + String(x) + "/1\"";
String cOFF = "\"GET /c" + String(x) + "/0\"";
Serial.println(cON);
Serial.println(cOFF);
if (header.indexOf(cON) >= 0) {
Serial.println(cON);
Serial.println(cOFF);
A_c[x] = 1;
} else if (header.indexOf(cOFF) >= 0) {
Serial.println(cON);
Serial.println(cOFF);
A_c[x] = 0;
}
}
If anyone has any insight into why I am able to validate the if statement when it reads:
if (header.indexOf("GET /c1/1") >= 0)
but am not able to validate it when it reads:
String cON = "\"GET /c1/1\""
if (header.indexOf(cON) >= 0)
I really appreciate any help.
Thanks,
James