Hello everyone,
Whilst developing a WiFi enabled LED strip I have run into a strange error. This LED strip used to work correctly but now after uploading the code again on a new PC to update the WiFi credentials the code does not run correctly anymore.
I have verified that POST requests are coming in correctly but they are not handled well by the hasArg() method used by the webserver to parse the incoming data.
For the interested, the requests are sent via Javascript as follows and have been verified to be sent via Inspect Element and Serial Prints:
xhr.open('POST', '/send');
xhr.send(`mode=${slider.value}`);
When sending the string: mode=4, the server.hasArg("mode") function returns 0 as if the mode argument wasn't there and server.arg("mode") returns nothing.
The code to check these arguments is implemented as follows:
if(server.hasArg("mode")){
Mode = server.arg("mode").toInt();
For debugging purposes I added these serial prints:
Serial.println(server.hasArg("mode"));
Serial.println(server.arg("plain"));
Serial.println(server.argName(0));
Serial.println(server.argName(1));
Serial.println(server.args());
On sending the string mode=4 these serial prints return:
0
mode=4
plain
1
which confirms my hypothesis that the arguments of the POST request aren't parsed correctly using the ESP8266Webserver library's functions. By the way, parsing multiple arguments such as mode=1&r=10&b=20&g=100 does not work either and is seen as one argument.
I have tried reinstalling the esp8266 boards library and reverting back to older versions without success.
If anyone has any idea on what could cause the argument functions not to work correctly given this input I would love to hear it.
Thanks in advance!