I am trying to send a message from a webserver (ESP32) to a serial port. Anytime the button on the webserver is clicked, the message with the parameters is supposed to be sent. This is the snippet of the code where the JS function for the button is defined.
client.println("<script>");
client.println("function sendMessage() {");
client.println(" if (document.getElementById('radioMode1').checked) {");
client.println(" mode = "mode1";");
client.println("} else if (document.getElementById('radioMode2').checked) {");
client.println(" mode = "mode2";");
client.println("} else if (document.getElementById('radioMode3').checked) {");
client.println(" mode = "mode3";");
client.println("} else if (document.getElementById('radioMode4').checked) {");
client.println(" mode = "mode4";");
client.println("}");
client.println(" sep = ";";");
client.println("var message = mode + sep + document.getElementById('schaltzahlen').value + sep +
document.getElementById('frequenz').value;");
client.println(" var xhr = new XMLHttpRequest();");
client.println(" xhr.open(encodeURIComponent(message), true);");
client.println(" xhr.send();");
client.println("}");
Webserver with relevant parameters
The problem is that the function
xhr.open(encodeURIComponent(message), true);
encodes the ASCII symbol “;” to “%3B”. This is an example of what is being printed to the serial when the button is pressed.
mode1%3B25800%3B2.5 /true HTTP/1.1
Is there a way to avoid URI encoding? Additionally, can I get rid of ‘/true HTTP/1.1’ , so I only have a message with the relevant parameters?
I am relatively new to programming, I am sorry for the imprecise explanations. Any help is greatly appreciated.
nikolatdr is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.