I know that you dislike global jsonbuffer/object but i think that many ppl just want to have set of seettings available with boot time and most of them should be unchanged as long as device is on.
IMHO that would be often used pattern.
In that situation, I use custom data structures as suggested here in FAQ: What's the best way to use the library?
This is a win in three levels:
Reducing the size of global variables is crucial as they reduce the RAM remaining for the rest.
Moreover, the JSON object tree consumes memory even if the program doesn't use it.
For example, if someone adds values in the JSON settings that are not actually used by the program, the memory will be used anyway.
One could even get to a situation where the program is unable to run because all the memory will be consumed by the settings.
So I see this more as an anti-pattern, but I'd like to get you opinion @nardev...
What is the benefit compare to custom data structures?
PS: I forgot another strong advantage of custom structures:
Didn't notice this one in the F.A.Q. thnx.
p.s. :D
in my case the web HTML/JS gives me json on it's own way, which is than easy to parse and populate HTML form again in case of edit. So i didn't want to touch that.
On the other hand, since it's a list of mqtt topics with device and codes data (for ir/rc transmitters), i just made another json object with full topics path like:
{
聽聽"my_device_name/rc-switch/socket_main_light0":聽{
聽聽聽聽"code":聽"654321",
聽聽聽聽"type":聽"rc-switch"
聽聽},
聽聽"my_device_name/relay-pin/socket_main_light2":聽{
聽聽聽聽"code":聽"13",
聽聽聽聽"type":聽"relay-pin"
聽聽},
聽聽"my_device_name/ir-switch/socket_main_light":聽{
聽聽聽聽"code":聽"{get_from_config_file_no_31}",
聽聽聽聽"type":聽"ir-switch"
聽聽}
}
So, since it's safe to read this object always, i just check if the topics exists, and if it does, just do what ever i need to do...
Should we close this..??
This is a question that pops up very often, let's keep this open for a while and see if we get some reactions.
Then, I'll add my answer to the FAQ, where it belongs, and close this issue.
Thank you very much for asking this @nardev, I'm sure this will help a lot of users.