Replies: 3 comments 24 replies
-
Sounds like an interesting idea! There is going to be a trade-off since too many files and the filing system overhead becomes excessive. In general terms, partitioning the data structure into a few separate JSON files might work best. Merging those together doesn't necessarily require them to be hierarchical. Can you provide an example configuration (suitable sanitised, of course)? It would be helpful to aid discussion; we should consider your specific use case before attempting to generalise a solution. NB. Differentiating between array and object nodes is kind of implicit since each leaf (JSON file) would either contain |
Beta Was this translation helpful? Give feedback.
-
Templating works well here since each entry is for a simple
A flat directory structure is fairly easy to handle like this since it requires only one or two file handles to be open at once. As soon as you start nesting directories it becomes much more complex. A more general problem here is synchronisation of settings if related values are distributed across multiple files.
I think this would end up being a lot more complicated than simply breaking the configuration into logical chunks. Each chunk would be stored in a separate file and would be accessed using ArduinoJson as usual. Serialising those files to a web client can be done using a custom stream class which just serves up each file in turn. The A more optimised example can be found in the It also has the I think a more generalised class would be useful to allow chunked serialisation and de-serialisation of large JSON files, so happy to work on this with you? |
Beta Was this translation helpful? Give feedback.
-
I've started a library based on this discussion at https://github.com/mikee47/ConfigDB/tree/develop. There's a working sample based on your dataset so have a play and we can perhaps work towards something useful? |
Beta Was this translation helpful? Give feedback.
-
my (inherited) application uses a rather large global config struct that is only growing. This struct is represented on storage as well as on the API level by a json object, there's two sets of code to construct the object (one for storage, one for the API) and two sets to deserialize it again.
My idea to save both code and, more importantly, RAM, would be to map the json object to a directory structure on storage, files matching leaf objects in the json object, directories representing objects containing other objects.
Now, in digging into Sming classes and samples, I was intrigued by the DirectoryTemplate and the ability to use a small template to list a directory as json as seen in Basic_Storage.
I was wondering: how difficult could it be to build on this templating to at least be able to stream a directory structure as mentioned above as json? I feel that "only" two things are missing: the ability to read file content from the template (which is certainly possible but not from the DirectoryTemplate class, right?) and the ability to recurse into directories, reading the whole tree in one go.
Also, there would need to be a way to differentiate directories representing an array from directories representing an object. In my current code, I'm doing that by going through all the children, if they all have numeric names, I deem it an array. Probably not the best criteria, especially if the numeric names are non-contiguous.
I figure that the other way round - taking in a json file and turning it into a directory is a bit more difficult, as, while the StreamTemplate engine could be used to dissect the json, there would still have to be a bit of code specific to storing json.
But I wonder: given IFS and it's copy on write feature, this might make a pretty descent way of storing large configurations. Since directories can be directly accessed, full as well as partial reads / updates / adds should be easy, element order doesn't matter in json and element hierarchy would be reflected 1:1 by directories. To clearly mark arrays from objects of objects, I figure a user attr could be used on the containing directory?
From my application's point of view, I believe this might actually allow me to completely remove ArduinoJSON from it, as any serialization / deseralization / object value read could be done through this. And since the app mostly uses json for configuration, the performance impact of going through flash should not be an issue. Maybe I could even use Stream templates to read values from the api / websocket messages which are json.
I will say that I'm nowhere near understanding the stream classes well enough to implement this, but I would appreciate feedback, if this might be a good idea and even a valuable add-on to Sming as well as maybe pointers in the right direction?
regards
pj
Beta Was this translation helpful? Give feedback.
All reactions