Closed pin010 closed 4 months ago
Hi @pin010,
Expected output
update_settings len=188
Actual output
update_settings len=124
IncompleteInput
seems perfectly appropriate since the end of the document is missing.
I don't think the problem comes from ArduinoJson but from AsyncWebServer.
Please try to reproduce the issue without ArduinoJson and open an issue at AsyncWebServer. It could be related to chunked transfer encoding.
Best regards, Benoit
Hi Benoit, you gave me excellent advice, I made the suggested change, the result is indisputable. ArduinoJson performs great. I have to look on ESPAsyncWebServer for the problem. Best regards, Pin010
result with Chrome: fragmented update_settings mSec=112343 len=124 index=0 total=336 update_settings mSec=112351 len=212 index=124 total=336
result with Safari: whole update_settings mSec=155982 len=336 index=0 total=336
Thank you
Cool. Let me know how you solve the issue.
Hi, this way, I don't know if it's the best way, but it works.
server.on(
"/update_settings", HTTP_POST, [](AsyncWebServerRequest *request) {}, NULL,
[](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total)
{
if (total > BUFFER_SIZE)
{
request->send(400, "total Oversize");
}
else
{
for (size_t i = 0; i < len; i++)
{
buffer[bufferIndex++] = data[i];
}
if (bufferIndex >= total)
{
bufferIndex = 0;
JsonDocument doc;
DeserializationError error = deserializeJson(doc, buffer);
if (error)
{
Serial.println(error.c_str());
request->send(400, error.c_str());
return;
}
else if (doc.containsKey("settingsID"))
{
// do something
}
doc.clear();
}
request->send(200);
}
});
Best regards, Pin010
So, if I understand correctly, you accumulate the data in a global buffer and call deserializeJson()
when the request is complete.
That's exactly how it is! I've been poking around espasyncwebserver and I found this solution which all in all works.... Greetings
Describe the bug
I discovered a small problem when forwarding a json document larger than about 160 bytes from a Chrome or Edge browser to a server located in an ESP8266 with bblanchon/ArduinoJson@^7.0.3 libraries
Troubleshooter report
Here is the report generated by the ArduinoJson Troubleshooter:
deserializeJson()
returnsInvalidInput
Environment
Here is the environment that I used:
Reproduction
Please see https://github.com/pin010/ArdJsonVsChrom
Compiler output
If relevant, include the complete compiler output (i.e. not just the line that contains the error.)
Program output
If relevant, include the repro program output.
Expected output:
Actual output: