Comments (4)
UPDATE.
I figured out the reason, and it seems on the (huge) memory usage. I'm using a 32-bit board and the buffer must be sized way longer than expected.
By running this snippet (notice the buffer size!)...
//
// Step 1: Reserve memory space
//
StaticJsonBuffer<1024> jsonBuffer;
//
// Step 2: Build object tree in memory
//
JsonObject& root = jsonBuffer.createObject();
root["sensor"] = "gps";
root["time"] = 1351824120;
JsonArray& data = root.createNestedArray("data");
//data.add(48.756080, 6); // 6 is the number of decimals to print
//data.add(2.302038, 6); // if not specified, 2 digits are printed
for (int i=0; i<100; i++)
{
JsonObject& jsens = data.createNestedObject();
jsens.add("name", "tizio");
jsens.add("value", i);
}
//
// Step 3: Generate the JSON string
//
root.printTo(Serial);
...the result is the following (290 chars):
{"sensor":"gps","time":1351824120,"data":[{"name":"tizio","value":0},{"name":"tizio","value":1},{"name":"tizio","value":2},{"name":"tizio","value":3},{"name":"tizio","value":4},{"name":"tizio","value":5},{"name":"tizio","value":6},{"name":"tizio","value":7},{"name":"tizio","value":8},{}]}
I simply underestimated the actual usage of ram.
from arduinojson.
Yes, memory usage is almost 4 times bigger in 32-bit than in 8-bit.
To write platform independent code, I recommend using the following macros:
JSON_ARRAY_SIZE(N)
which returns the size of an array ofN
elementsJSON_OBJECT_SIZE(N)
which returns the size of an object ofN
key-value pairs
In your second last example, it could be:
JSON_OBJECT_SIZE(3)+JSON_ARRAY_SIZE(100)+100*JSON_OBJECT_SIZE(2)
Also, if you're not working in an embedded environment, you can switch to DynamicJsonBuffer
which will automatically grow.
from arduinojson.
I'll bear in mind, thank you very much for the help.
Oh, you were mentioned:
https://highfieldtales.wordpress.com/2014/12/29/azure-veneziano-linkit-one/
from arduinojson.
Hey hey.
Congratulations for your project 👍
from arduinojson.
Related Issues (20)
- ArduinoJson 7 assumptions about memory in modern processors HOT 3
- JsonArray.size contains always 0 after successful deserialization HOT 6
- Get maximum JSON string length HOT 2
- Thingsboard serialize json data issue HOT 4
- Unsupported fields in `library.properties` HOT 2
- Create JsonObject subclass HOT 7
- Base64 image string to json HOT 3
- Add ability to serialize just the keys or just the values. This would be very useful when both json and csv are needed. HOT 2
- #include <bits/error_constants.h> : exit status 1 HOT 1
- JsonVariant with .to<JsonArray>(); HOT 1
- How to manage big json using HTTPClient ? HOT 12
- ArduinoJson prefer Safari? Maybe this is not a bug! HOT 6
- IP Address Issue HOT 1
- switching from DynamicJsonDocument to JsonDocument HOT 5
- Example request for WiFiNINA HOT 4
- JsonDocument in queue HOT 4
- Is there a way to cache a JsonObject between function calls? HOT 5
- compilation error HOT 3
- How to deserialize large arrays without running out of RAM? HOT 8
- Going crazy trying to check if a key exists! HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduinojson.