interactive-matter / aJson

aJson is an Arduino library to enable JSON processing with Arduino. It easily enables you to decode, create, manipulate and encode JSON directly from and to data structures.
http://interactive-matter.org/2010/08/ajson-handle-json-with-arduino/
566 stars 136 forks source link

Compatibility with SD.h #17

Open gziolle opened 12 years ago

gziolle commented 12 years ago

I tried to use the aJson and SD libraries at the same time, but it doesn't. I get wrong Json objects by just including the SD.h library on my sketch

Any ideas why?

Best Regards Guilherme

interactive-matter commented 12 years ago

hmm, in theory it is no problem. Especially if you just include the header file.

BUT: json dynamically creates data on the stack - it allocates memory. And this is not the most robust feature on Arduino. Is ist possible that your Arduino just simply ran out of memory? This could look like the symptoms you are describing. You can perhaps check that with this sketch: http://www.faludi.com/2007/04/18/arduino-available-memory-test/

gziolle commented 12 years ago

I used this sketch, and I still have 214 bytes left. Should I have more?

gziolle commented 12 years ago

After some more tests, I got the conclusion that I'm running out of RAM, because it resets when the amount of bytes left gets too low. But this is kind of weird, since I'm only including the library, which by itself takes about 500 bytes of RAM. Is there any other version of the SD library, like a "SD lite" or anything like that?

Thanks in advance

gziolle commented 12 years ago

Is there a way to reduce the memory consumption from the JSON library? I just found out that I must have 512 free bytes to handle a SD card.

interactive-matter commented 12 years ago

The JSON Library needs very little memory. Perhaps 100 bytes or so. But the JSON objects take a lot of memory (depending of object structure and data size). Perhaps you can use one of the streaming interfaces to reduce the memory fotprint by not storing the input string. Sorry that I do not have better news. A streaming implementation with virtually no memory consumption is in the planning - but could take some weeks until it is ready.

gziolle commented 12 years ago

I'll try to reduce the memory footprint. I tried to use the addStringToObject() method with some variable that i casted as a char*. But it didn't work, because the values don´t appear on the object, and I only get null strings. Any ideas why?

One last thing: did you sort the memory leak on the print() method out?

Thanks in advance