my JSON web server works fine until responses are larger than 500 byters or so...

santi

New member
Hi All-

I have been working on a REST server that moves JSON back and forth and it works well except when responses get above a certain size. See the attached sketch. If you use shortJson the server works fine. longJson gets a reset connection on my browser. Using Chrome.

char longJson[] =
"{\"x\":{\"position\":\"3\",\"speed\":\"\",\"length\":\"175.88\",\"lengthInTics\":\"227847\",\"lowLimit\":\"3.00\",\"highLimit\":\"172.88\",\"direction\":\"\",\"zero\":......

char shortJson[] =
"{\"x\":{\"position\":\"3\",\"speed\":\"\",\"length\":\"175.88\",\"lengthInTics\":\"227847\",\"lowLimit\":\"3.00\",\"highLimit\":\"172.88\",\"direction\":\"\",\.......

//DeserializationError error = deserializeJson(doc, shortJson);
DeserializationError error = deserializeJson(doc, longJson);

Thanks in advance for any help!

-Santi

View attachment jsontest.ino
 
SOLVED need to chop into chunks

chopping the json into 400 byte chunks fixes the problem

``` // Write JSON document

char output[4000];
serializeJsonPretty(doc, output);
unsigned int chunkSize = 400;

String out(output);
unsigned int start = 0;
while(start + chunkSize < out.length()){
client.print(out.substring(start,start + chunkSize));
start += chunkSize;
}
client.println(out.substring(start));
```
 
Back
Top