All, I am getting my head around @rickkas7’s amazing JSON library. I plan to use it in my LoRA / Particle Gateway code to do three things:
- Construct the JSON payloads for Particle publish (use snprintf today)
- Interpret JSON formatted commands via a Particle function to configure the gateway and the nodes via API calls
- Keep track of the node configurations: node number, deviceID, last connected and sensorType
The idea is to store the JSON objects as strings in the persistent storage using the StorageHelper library. The question is how to organize the data on #3 above.
I have worked through the example code provided but I am having a bit of an issue working with JSON objects that are more than a single level deep. For example, I would like to organize my node data like this:
{
"Node1":
{
"nodeNumber":1,
"deviceID":"particleDeviceID",
"lastConnect":1667835489,
"sensorType":1
},
"Node2" .....
}
Will this work? I will need to be able to do the following:
- Add new nodes as they join the network (up to some limit for the JSON token size)
- Iterate through all the nodes to see if a deviceID had already been registered
- Make updates and keep the nodeNumbers consistent even when updated values are moved to the end of the JSON token.
- Using a given NodeNumber, (but as a variable not a string), update the values associated with that node.
Many of the tools in this library seem to be oriented toward single-layer JSON tokens (getOuter…) so, would it be better to have a separate JSON token for each of the four variables? If so, as I update some of the values, their index will change so how can I keep them associated together.
That said, if there is a better way to do this, I would be open to any suggestions.
Thanks,
Chip