You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I like to utilize ArduinoJSON as a tool for parameter management as I can load params from a file and also can access the parameters via their names e.g. via Serial Communication, e.g. sending "location_lat= 42.0" and my script can adjust the variable calling somthing like doc["location_lat"] = 42.0. That way I can try a whole lot of values for all params on the fly, without re-compiling all the time or using tedious potentiometer reads.
Describe the solution you'd like
I'd really like to take this a step further by also accessing nested objects by a single string-key such as "location.lat = 42.0", which should call doc["location"]["lat"] in the background (maybe there is even a more appropriate delimter than '.'). This should of course work for writing and reading.
I'm pretty sure that this should be quite easy to implement, but I did not manage to implement it myself.
The code necessary for that might look something like this:
// NOTE: This is non-tested Pseudo-Code
String key = "location.lat"
float val = 42.0
String delim = "."
int delim_idx = key.indexOf(delim);
if (delim_idx == -1) { return this[key] }
String key0 = key.substring(0, delim_idx );
String key1 = key.substring(delim_idx + 1);
return this[key0][key1] = val // Note: if key1 still contains delim-chars, recursion should handle that
Additional context
Moreover: is there any way to implicitly save the var type inside the doc as well?
That way I could call: "Serial << doc["lat"]<< endl;" instead of: "Serial << doc["lat"].as<float>() << endl;"
Regards and let me know, what you think. Keep on the phenomenal work! 😊👍
The text was updated successfully, but these errors were encountered:
I like to utilize ArduinoJSON as a tool for parameter management as I can load params from a file and also can access the parameters via their names e.g. via Serial Communication, e.g. sending
"location_lat= 42.0
" and my script can adjust the variable calling somthing like doc["location_lat"] = 42.0. That way I can try a whole lot of values for all params on the fly, without re-compiling all the time or using tedious potentiometer reads.Describe the solution you'd like
I'd really like to take this a step further by also accessing nested objects by a single string-key such as "
location.lat = 42.0
", which should calldoc["location"]["lat"]
in the background (maybe there is even a more appropriate delimter than '.
'). This should of course work for writing and reading.I'm pretty sure that this should be quite easy to implement, but I did not manage to implement it myself.
The code necessary for that might look something like this:
Additional context
Moreover: is there any way to implicitly save the var type inside the doc as well?
That way I could call: "
Serial << doc["lat"]<< endl;
" instead of: "Serial << doc["lat"].as<float>() << endl;
"Regards and let me know, what you think. Keep on the phenomenal work! 😊👍
The text was updated successfully, but these errors were encountered: