0

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):

enter image description here

Char array payload from board:

enter image description here

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

JSON is sent in request payload POST method. So, i really should encode this content using URI encoding method? Why library changing + to space character, and how prevent this solution?
ok, when encode this json, works fine, but is some method to read this data from client connection stream using original bytes?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.