Skip to content

Premature termination JSON output #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
qistoph opened this issue Nov 9, 2019 · 6 comments
Closed

Premature termination JSON output #96

qistoph opened this issue Nov 9, 2019 · 6 comments

Comments

@qistoph
Copy link

qistoph commented Nov 9, 2019

Working with an ESP8266 (NodeMCU v3) I'm having issues with JSON output being truncated. Resulting in invalid JSON data.

I'm adding 11 things using adapter->addDevice:

  • Internal LED
  • Motion sensor
  • Temperature sensor
  • 8 ports on a relays board (with an MCP23008 controller)

Surfing to http://MY-IP/ my browser shows the error:
SyntaxError: JSON.parse: unterminated string at line 1 column 3612 of the JSON data

Not adding either the LED or motion sensor property makes the sketch return valid JSON data.
https://gist.github.com/qistoph/bfdf8601969078be9284bcf6224351bf#file-thingmcp23008-ino-L98

Below are the number of characters returned, determined with curl 'http://MY-IP/' | wc -c:

  • Neither disabled: 3860 (invalid JSON because of termination)
  • LED disabled: 4817
  • Motion disabled: 4796

If anyone has any suggestions to fix or further troubleshoot the issue, I'd love to hear from you.

@hobinjk
Copy link
Contributor

hobinjk commented Nov 9, 2019

This sounds like ArduinoJson might not be able to size up the buffer past a certain point. It's possible that my migration to ArduinoJson 6 in #95 will fix this issue but testing that out would require manually checking out that branch and making sure you upgrade your local ArduinoJson.

As a workaround, you could move some of the properties to a second thing and add both to the adapter with multiple calls to adapter->addDevice(&thingOne);

@qistoph
Copy link
Author

qistoph commented Nov 11, 2019

Thanks @hobinjk for your suggestions. I have checked out your branch and compiled my project with ArduinoJson 6.13.0.

The generated JSON was no longer broken, but only showed the first two Things in the JSON generated. Could this be an issue with your branch? Might be worth checking out for proper ArduinoJson 6 integration.

The work-around didn't work for me, unfortunately. I was actually already adding Things/Devices instead of properties. I'll rephrase my initial issue accordingly.

@mijapa
Copy link

mijapa commented Jan 1, 2020

Working with an ESP32.
After migration from 0.4.1 to 0.10.1 version of library I'm having issues with JSON output being truncated.
Below are the number of characters returned, determined with curl 'http://MY-IP/' | wc -c:
v0.4.1: 2017
v0.10.1: 822
This is my WebThing description:
https://gist.github.com/09d13f5da69dd20f1596563dde1565cb

@mrstegeman
Copy link
Contributor

@mijapa
Copy link

mijapa commented Jan 2, 2020

Thank you @mrstegeman
Changing buff size in line 274 to 4096 helped.

@mrstegeman
Copy link
Contributor

The buffer sizes are now configurable as such:

// By default, buffers are 256 bytes for small documents, 1024 for larger ones

// To use a pre-defined set of larger JSON buffers (4x larger)
#define LARGE_JSON_BUFFERS 1

// Else, you can define your own size
#define SMALL_JSON_DOCUMENT_SIZE <something>
#define LARGE_JSON_DOCUMENT_SIZE <something>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants