I'm trying to send JSON to an Arduino module with a ESP8266. I have a simple web server, which waiting for JSON with SSID and password where device must connect.
ESP8266WebServer server(80);
server.on("/config", HTTP_POST, configHandle);
server.begin();
void handleConfig() {
String payload = server.arg("plain");
//convert JSON to char[]
//parse using jsmn lib
}
What if password contains non ASCII characters? How can I handle request content to put this arguments to method:
WiFi.begin(ssid, pass);
Edit:
Example: If I send JSON like:
{"pass": "test+test"}
Then, when I print this payload I don't get a +
sign (but this is ASCII sign)
Request (wireshark):
Char array payload from board:
The ESP8266WebServer
library is decoding +
into a space character.
You need to URL encode the JSON string, before sending it.
In vanilla JavaScript you need to use encodeURIComponent
.
Don't use encodeURI
, because it doesn't encode +
.
Whatever you use, make sure the +
character is encoded into %2b
.
This will also save you from potential problems, involving ?
, &
and =
inside your JSON.