Writing to EEPROM using an input resource

Hi,

I have an input resource (slider widget) which is used for dynamically changing a variable in my sketch. I would like also to be able to write this variable into EEPROM so next reboot my device loads the saved value.

I am uncertain about what is the first free available address of the EEPROM. I use ThingerWebConfig.h with ESP8266 and what I am understanding is that somewhere the SSID, passoword, device credentials etc. should be stored. Is it safe to start write to EEPROM from address 0 ?

This is my example code:

#include <EEPROM.h>

int addr = 0;

    void setup()
    {
      EEPROM.begin(512);

    // Input resource to remotelly modify the maxDoorDistance variable defined as a global variable.
      thing["maxDoorDistance"] << [](pson& in){
        if (in.is_empty()){
            in = maxDoorDistance;
            } else {
              maxDoorDistance = in;
              EEPROM.write(addr, maxDoorDistance);
              EEPROM.commit();
              } 
        };
    }

    void loop(){

    }

The WifiWebConfig is using the ESP8266 filesystem for storing device credentials, and the EEPROM has its own reserved space in the flash, so I think it should not be a problem. Check the docs here:

https://github.com/esp8266/Arduino/blob/master/doc/filesystem.md

1 Like

thanks @alvarolb, always on point!

It works, so now I can save all my configuration variables into EEPROM. Perfect! :smiley:

1 Like

How did u do? the link is not found.

It is now here: