Saving parameters in a non-volatile memory

I want to save some parameters

typedef struct
    uint8_t device_id;
    char ssid[32];
    char pass[32];
    int loc_port;
    int remote_port;
    uint8_t remote_ip[4];
    uint8_t mac_addr[6];
    uint8_t sens_type;
    uint32_t interval;

SYS_PARAMS sys_parameters;
uint8_t sys_buffer[512];

void SYS_ParamRead()
    int i;
    for (i = 0; i < sizeof(SYS_PARAMS); i++)
         sys_buffer[i] =; 

     memcpy(&sys_parameters, &sys_buffer, sizeof(SYS_PARAMS));

void SYS_ParamWrite()
    int i;
    memcpy(sys_buffer, &sys_parameters, sizeof(SYS_PARAMS));
    for (i = 0; i < sizeof(SYS_PARAMS); i++)
        EEPROM.write(i, sys_buffer[i]);

So I set some parameters, say sys_parameters.device_id = 7; and then invoke SYS_ParamWrite().
On start up


 Serial.print("DEVICE ID ");

And I see "DEVICE ID 0". What do I miss?

P.S. It's ESP8266 chip.

In SYS_ParamRead() you are not reading from the EEPROM

Why not use EEPROM.put() to save the parameter struct as a whole and EEPROM.get() to load it back as a whole ?

EEPROM.put()? OK, I'll try.

Well, I did so.
As a read - EEPROM.get(0, sys_parameters);
As a write - EEPROM.put(0, sys_parameters);

However I still read "DEVICE ID 0".

We don't have EEPROM in ESP8266 actually. Is there any wrapper to adapt it to a flash memory?

Is there an EEPROM.begin() in your setup()? You also need to tell it how much memory to use for EEPROM emulation.

Ooops. That was missing - EEPROM.begin(). Now it's OK. Thank you.

I am glad that "it" is working but for future reference please post complete sketches and not snippets of them so that those helping do not have to guess what the problem might be

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.