-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
895df6e
commit 00d959f
Showing
2 changed files
with
26 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
name=RTC Memory | ||
name=RTCMemory | ||
version=1.0.0 | ||
author=Fabiano Riccardi <fabiano.riccardi@outlook.com> | ||
maintainer=Fabiano Riccardi <fabiano.riccardi@outlook.com> | ||
sentence=A class to facilitate the management of data persistence across different memory hierarchy (RAM, RTC memory and flash memory) on ESP8266 | ||
paragraph= | ||
url= | ||
url=https://github.com/fabiuz7/rtc-memory-esp8266 | ||
category=Data Storage | ||
architectures=esp8266 | ||
architectures=esp8266 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,52 @@ | ||
# RTCMemory for ESP8266 | ||
A library to makes easier to benefit of RTC memory embedded in ESP8266, designed for Arduino platform. | ||
# RTCMemory | ||
|
||
A library to make easier to benefit of RTC memory embedded in ESP8266, designed for the Arduino platform. | ||
|
||
## Motivation | ||
[ESP8266 Arduino core](https://github.com/esp8266/Arduino) provides *byte-oriented* functions to read, write and check integrity of RTC memory. Hence accessing to string, integer or float may require to deal with pointers and tricky casting. RTCMemory hides this complexity, making you to access directly to high-level data stored in RTC memory. Moreover, if you really need to preserve this data, you may want to protect them from power loss. For this reason, this library allows you to backup the content of RTC memory on non-volatile flash memory. | ||
|
||
[ESP8266 Arduino core](https://github.com/esp8266/Arduino) provides *byte-oriented* functions to read, write, and check the integrity data on RTC memory. Hence, accessing common data types, such as string, integer, or float, requires to deal with pointers and casting. RTCMemory hides this complexity, making you access directly to high-level data stored in RTC memory. Moreover, if you need to preserve this data from power loss, this library allows you to back up the entire content on non-volatile flash memory in a single line. | ||
|
||
## Features | ||
|
||
- Make easier to access to RTC data | ||
- Backup data on flash memory | ||
- Support for SPIFFS and LittleFS file systems | ||
|
||
## Usage | ||
|
||
You should be aware of very few APIs to take advantage from RTCMemory library. | ||
Firstly, define your data structure (max 512 bytes): | ||
You should be aware of very few APIs to effectively use RTCMemory. | ||
First, define a data structure that will contains your data (max 508 bytes): | ||
|
||
typedef struct { | ||
int counter; | ||
} MyData; | ||
|
||
Then declare the rtcMemory (at global scope will be fine): | ||
Then instantiate the rtcMemory (global scope is fine): | ||
|
||
RtcMemory rtcMemory("/yourfile"); | ||
RtcMemory rtcMemory("/path/to/file"); | ||
|
||
the filepath is an optional parameter, if you don't need the persistent backup you can omit it! Then you will initialize RTC Memory through: | ||
|
||
bool result = rtmMemory.begin(); | ||
|
||
*result* tells you if the RTC memory (or the flash, if filepath was provided) has data or is fresh. | ||
Get the data buffer from the RTC memory: | ||
*result* is true if there is some valid user data in RTC memory (or if RTC memory is not valid and filepath was provided, in the flash), otherwise is false. | ||
Get the buffer containing your data: | ||
|
||
MyData* myData = rtcMemory.getData<MyData>(); | ||
|
||
Modify your data as you prefer. Finally save data on RTC: | ||
Modify your data as you prefer. Finally, save data on RTC: | ||
|
||
rtcMemory.save(); | ||
|
||
Remember that RTC memory is a low-power volatile memory, hence this memory would be lost on power loss. To persist your data also flash, call: | ||
Remember that RTC memory is a low-power volatile memory, hence data on this memory are lost on power loss. To backup your data in flash, call: | ||
|
||
rtcMemory.persist(); | ||
|
||
This is quick overview of the library, for a more comprehensive documentation you would look at the header file. | ||
This is a quick overview of the library, for more comprehensive documentation you may look at the header file. | ||
|
||
### Selecting the file system | ||
|
||
ESP8266 Arduino provides 2 file systems: the SPIFFS and LittleFS. In April 2020, SPIFFS was deprecated, but given its incompatibility with LittleFS (formatting is required), some projects may continue to require SPIFFS. By default, this library uses SPIFFS, but you are free to switch the LittleFS enabling (uncommenting) the proper #define. By default, in the first lines of rtc_memory.cpp, you can find: | ||
|
||
#define ESP_LOGGER_FLASH_FS_SPIFFS | ||
//#define ESP_LOGGER_FLASH_FS_LITTLEFS |