Hi, I need help for a project I'm working on.
In this project I have the need of storing some variables in the flash and then read them afterwards.
I'm storing them with a file in littlefs in json format using the ArduinoJson library.
Now the problem is that when I have to sync them, I don't know what kind of data type I'm reading for each combination of keys and values and where I need to sync it to.
So my idea (probably it's dumb but it's what it came in my mind for now) was to create a new struct:
struct SettingDataBase
{
unsigned int SettingID;
unsigned int SettingDataType;
String SettingName;
String SettingValue;
String SettingAddresStr;
};
So with that, I can create an array of this new struct as big as I need. This will create my database that I can read with a simple for loop. This struct let me easily add or remove a new voice and, by reading the address of the actual variable, store them directly.
My idea of storing my database (which is simply an array of the new data type "SettingDataBase") was to hardcode it only once by declaring it as a global variable and then, when I need to retrive the setting, sync it back using the database fields.
Now this is where I'm stuck: I don't know if is it possible to cast a String to, for example, an int*, char* and vice versa.
This is complicating my work, maybe there's a simpler and faster way to handle settings stored in the flash which is also easy to maintain in case i need to add or remove elements and that doesn't require to hardcode too much stuff.
Let me know if someone knows a better way to do that.
Thanks and have a nice day.