How to use GET and UPDATE EEPROM individually in a 'struct'?

Again, hi everyone. I have this structure:

struct Settings_s {
  char SSID[21];  // Always number of characters + 1 (null)
  char PASS[21];  // Always number of characters + 1 (null)
  float BlrPWR;
  float maxSuppTemp;
  float minOutdTemp;
  float SetPoint;
  float SetBack;
  bool NTC0_Instl;
};

Settings_s Settings = { "ABCDEFGH_1324", "0Abcd1Bcde2Cdef3Defg", +20000.00, +60.00, -5.00, +21.00, +19.00, true};

PUT and SHOW good the entire structure, thanks to you.
I want to do GET and/or UPDATE individually for each member. Once again, excuse my ignorance!.

Why make things complicated ?
Just get() or put() the whole struct and use the individual elements as required.

When using put() or update() only the bytes that have changed are actually written to the EEPROM

1 Like

Thanks, UKHeeliBob! I knew that I should not rewrite data unnecessarily in the EEPROM. What I didn't know was that by writing (updating) data in bulk, only the data that had changed was updated.
Once again thanks and greetings,

Sorry, UKHeliBob but when I try to update:

void UPDATE_SETINGS() {
	EEPROM.update(EEADDR, Settings);
}

It appears the following error message:

[../EECTRL.h:132:32: error: no matching function for call to 'EEPROMClass::update(int, Settings_s&)'](C:/Users/xldoc/AppData/Local/Temp/VSM Studio/886f79b6e4c940cda031d1b60b84d861/ARDUINO_MEGA_1/EECTRL.h#131.31)

At the beginning of the sketch I have:

#define EEADDR 0

What am I doing wrong?

You are doing nothing wrong, it is just that update() only works for single byte variables. However, if you use put() then that uses the update() method internally to avoid unnecessary writes to the EEPROM so has the same overall effect

I have made the following sketch based on post #5 @UKHeliBob.

#include<EEPROM.h>
#define EEADDR 0x0010

struct Settings_s
{
  char SSID[21];  // Always number of characters + 1 (null)
  char PASS[21];  // Always number of characters + 1 (null)
  float BlrPWR;
  float maxSuppTemp;
  float minOutdTemp;
  float SetPoint;
  float SetBack;
  bool NTC0_Instl;
};

Settings_s Settings =
{ "ABCDEFGH_1324", "0Abcd1Bcde2Cdef3Defg", +20000.00, +60.00, -5.00, +21.00, +19.00, true};


void setup()
{
  Serial.begin(9600);
  UPDATE_SETTINGS();
  Serial.println(Settings.SSID); //shows: ABCDEFGH_1324
  memcpy(Settings.SSID, "pBCDEFGH_1324", sizeof Settings.SSID);
  Serial.println(Settings.SSID); //shows: pBCDEFGH_1324
}

void loop() {}

void UPDATE_SETTINGS()
{
  //EEPROM.update(EEADDR, Settings);
  EEPROM.put(EEADDR, Settings); 
}

Output:

ABCDEFGH_1324
pBCDEFGH_1324

Thanks, @UKHeliBob and @GolamMostafa, now I'm out of the jam.

1 Like

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