[Storage] Add support for storing some data in External EEPROM - #5382
[Storage] Add support for storing some data in External EEPROM#5382tonhuisman wants to merge 44 commits into
Conversation
…canner, code optimizations
…eprom Values page
|
@tonhuisman I got my EEPROMs today. Tell me when and what needs to be tested or how I can be of assistance. |
|
Ah, great 😃 You can of course test if the Task Values and Rules variables (writeEE,n,value / [readEE#n]) (NB: n = range 0..MAX-1 !) are restored correctly once you have enabled the corresponding settings on the Hardware page (see screenshot above). Restore should be successful after a power cycle 😄 to simulate the Cold boot situation. NB: I'm thinking of limiting the Rules vars to f.e. 1024 (less on smaller EEPROM sizes!), so more space will be available for Cache values, |
|
Ok... i am already in testing mode (I didn't wait for your reply :P ) Everything seems to work fine. (I have everything covered you mentioned)
|
I see no reason not to do it that way unless somebody really wants to write a lot of vars :) |
|
|
Would it be complicated to make the number of Rules var slots user selectable and put them at the end of the EEPROM and use the rest for C16? The ammount of user selectable slots could be also written to the EEPROM insted of storing it on the flash....
I get it. Would make a user-selectable amount of slots even more useful :) |
But for an analog reading of a LDR it still could mean 1 write per second |
|
I'll see where too put that extra checkbox per value 😅 I have already found a bit per value so I can store this setting 😎 Btw, I think it should be Enabled by default, and user can decide to turn it off Ah, and there's a particular reason not to skip values, as I'm also storing the Checksum for this data, and validating that against the calculated checksum, so when skipping a value the checksum won't be correct anymore 😱 |
Maybe it could also be stored on the EEPROM/FRAM? |
Hmm, not sure if that's such a good plan |
Me neither :) Just thinking out loud... |
What to do for Taskvalues that are not stored, store |
Hmmm.. very good question. I would make sense to use NaN. But that can not be represented (only when choosing a specific other value for it i guess?) Edit: ahhh since it is float 0xFFFFFFFF for NaN would be it right? |
|
I am probably stating the obvious by the memory layout could be like:
|
|
For GPIO pins we want to provide a way to store the states for MCP and PCF GPIOs, so 64 bits isn't going to cut it. And maybe we should store some more data, like PWM data and/or input/output, haven't coded anything for that yet. It's still slow-cooking in a background thread in my head 🤓 And the same is the case for |
Sorry, I don't want to be a pain in the ass 😁 but it seems i don't get it. |
|
First thing that's done is a validity-check of the current EEPROM: https://github.com/letscontrolit/ESPEasy/pull/5382/files#diff-87033636f7a2095187789ef49c13c2e2767c2e1d8eb19618aa17d932dd58ab53R175-R182 That involves a 'couple of bytes' being read, but those are not counted, and even if the params are not OK, the writes to update the params are not counted. NB: AFAIK, reading from an EEPROM is harmless to the device, as opposed to writing, that will eventually wear out the chip. (Most EEPROMs are specced at ~106 writes per byte, though I haven't validated that.) |
There currently is scheduled only a single write action per task update, if a new update comes while the data is still being processed, the new write action is ignored, as it will be handled on the next 'run'. |
I know. It’s not so much about the cycles but about the time that the read occupies the I2C bus. If you have multiple tasks with a 1-sec interval and let this be multiple I2C devices, then there is a lot of stuff going on on the bus. I even have some tasks with a 100-ms (or was it 50ms...) interval getting the analog data of a light sensor (LDR)... I would think that theoretically could lead to issues. |
to get a better understanding.. what params are we talking about? |
|
|
Would it be a problem to treat a task, where all "Eeprom" fields are disabled as an disabled task? |
|
BTW: 0 is still not being displayed as a slot value in /eepromvars. |
Well, yes, that's the intention, but I now see that some improvements can be applied in the code. There's also the feature that I write a NaN value if the taskvalue is not enabled, but currently that's re-checked every time for an enabled task. Will fix that soon-ish. |
…feature/Storage-add-support-for-External-EEPROM
|
@chromoxdor and others that are building this PR locally: |
|
Thanks for the heads up! What’s the other setting? |
MQTT State Class per Value |
…feature/Storage-add-support-for-External-EEPROM
…adee variable retrieval
…feature/Storage-add-support-for-External-EEPROM
…ugh still doesn't fit the build

Resolves #1011
Resolves #2291
Resolves #5602
Forum requests: here here here here here here
Features:
floatordoubleresolution, depending on build, always usingdoublestorage format) usingWriteEE,<slot>,<value>.WriteRTC,<slot>,<value>WriteEE,erase,eraseorWriteRTC,erase,erase.[ReadEE#<slot>]generic Rules variables syntax[ReadRTC#<slot>]. No checksum is calculated as there are not many slots available.[ReadEE#max]External EEPROM/RTC valuespage (/eepromvarsendpoint), available from the Tools page. For 0-values no hex value display is included.FEATURE_EEPROM_EXTERNALfor enabling the External EEPROM storage.FEATURE_RTC_SRAM_STORAGEfor enabling the RTC SRAM storage.WriteEE,Check,WPto re-evaluate the write-ability of the EEPROM[ReadEE#WP], 1 = write-protectedESPEasy::eepromnamespace for better structure and maintainability.BUILD_NO_DEBUGbuilds, so ESP8266 will fit. Still not including these features! See hereNote: I removed some of the original features, leaving only the saving and restoring of values in 'slots', making nearly the full storage space, minus 128 bytes in EEPROMs for future use, available. In RTC SRAM, all bytes are available for supported chips.
Original features, later removed:
Save Task values that are stored in RTC also in EEPROM, when enabled per value in Device pageAdd settings on the Hardware page for restoring settings from EEPROM at Cold and/or Warm bootAdd a checkbox per Task value to enable/disable storing the value in EEPROM, Disabled by default, only visible if the EEPROM (or FRAM) is enabled and available.Store and check some versioning and system parameters in EEPROM, avoiding incompatible data to be restored.Saving of UserVars to EEPROM is now handled in the 'background', to avoid a large time-penalty when a variable is saved in EEPROM. A save interval in seconds can be set to spread the load a bit more (see screenshot)TODO:
WriteEEandWriteRTCcommands)[ReadEE#<slot>]and[ReadRTC#<slot>])Hardware page configuration: (updated: 2026-04-06)