Is there any native C++ function that stores data like JS's Localstorage? I'm trying to develop a system that controls a refrigerator and I'm storing the temperature ramps in a txt file but I would like to use a native function if it exists.
It would be better to explain what type of data you want to store, how much data, for how long, and whether the data should persist during power down.
Many Arduinos have EEPROM for semipermanent storage of small amounts of data.
Using EEPROM is not useful as I will have many changes. But the issue of power outages is important.
The idea is to control a refrigerator for beer fermentation. I register the temperature “ramps”, which last a total of 10 to 15 days. When the first registered temperature is reached, the time starts counting. At the end of the time, it moves to the next temperature. Therefore, it is important to keep the data updated on the current ramp/temperature in cases of power outages. The txt file works but I would like to know if there is a better, native form of cpp.
Not a valid objection. EEPROM can be changed at any time, in milliseconds.
I would like to know if there is a better, native form of cpp
meaningless phrase. For help, please provide the requested information.
My issue is not the possibility but the fact that I would make thousands of changes.
Sorry but I didn't understand your question!!! Just say if there is any native cpp function to store data like JS localstorage. Simple. If it doesn't, and apparently it doesn't exist, ok. I have already described the project. What else can I say?
You're thinking in the wrong terms. This has nothing to do with the C++ language. An Arduino-type processor board is not a browser where you can store data in the cloud or on the PC. You need to start by specifying the hardware in which you want to store this data.
It seems you want that data storage to be non-volatile, correct? So, if you don't like EEPROM for that function, you'll have to come up with other hardware ideas. Perhaps SD card or FRAM? Once you make that decision, you can start talking about the code that must be used to store / retrieve the data.
Not a problem. Each cell is guaranteed for at least 100,000 writes, and there are 512 of them in a typical Arduino.
Just say if there is any native cpp function to store data like JS localstorage.
This is not a language issue. Local storage is a HARDWARE service that can be implemented in any programming language.
There are several built in Arduino functions that make it easy to save and update data in EEPROM. Likewise, for reading and writing SD cards, use the SD or SDFat code library functions.
Therefore, it is important to keep the data updated on the current ramp/temperature in cases of power outages. The txt file works but I would like to know if there is a better, native form of cpp.
Where is this text file located such that it is persistent through a power outage?
Since you will need a persistent clock in case of power failure or reboot, you can get DS3231 Real-time clock modules with an EEPROM that can be written many more times than the build-in EEPROM.
store the date in SRAM and only write to EEPROM on power loss to reduce write cycles.
A small circuit with an capacitor and a rectifier will be enough.
Why so many?
temperature doesn't change quickly
As already suggested, you could just save to EEPROM when you detect a power outage.
other technologies are also available; eg, FRAM, MRAM ...
Or have the Arduino battery-backed.
Thanks a lot everyone!!! In fact, I recently discovered JS's localstorage function and I was curious to know if there was a similar function in cpp.
What part of JS Local Storage are you trying to match?
Is it the memory location of the data and its persistence?
Is it the key/value pairing format of the stored data?
Indeed, there are probably many C++ functions (for example EEPROM.put() and EEPROM.get()) orstream related functions for read and write which look like the local store functions.
Storing the time/temperature ramp data for a state machine, and where you are in its execution is not unusal C++ situation.
And now you know that there is for Arduino, in the EEPROM and SD libraries, ready to go!
Or FRAM. Or Littlefs. Or others.
Is it the key/value pairing format of the stored data?
Good point. For key/value pairing, look at the various "container" types that are part of the C++ STL. Or, roll your own with a struct.
I would suggest using FRAM memory, they are available in I2C for a few dollars. I have replaced the EEPROM on the DS3231 with a 256K FRAM chip. Note the FRAM package is a SOP8 and the EEPROM is TTSOP so I had to reform the leads to make it work. Once installed it works great and I now have 32K x 8 non volatile memory. If you do not want to do the soldering there is a nice unit available from Adafruit.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.