EEPROM on ESP32

I’m working with ESP32s, and trying to get the EEPROM to store data. I’m working direct from the Arduino examples - code below. I’m trying a couple of different boards (AZ-Delivery and a Feather ESP32), but not managing to get anything sensible out of the EEPROM - it generally returns everything as 0. I’ve tried with platform = https://github.com/Jason2866/platform-espressif32.git, and now I get some numbers, but nothings sensible.

Should EEPROM work here?

Code:

#include "EEPROM.h"
struct MyObject {
  float field1;
  byte field2;
  char name[10];
};

void setup() {
    Serial.begin(115200);
    delay(1400);
  int eeAddress = 5; //Move address to the next byte after float 'f'.

  MyObject source = { 3.5f, 65, "Hello!" };
  EEPROM.put(eeAddress,source);

  MyObject target;
  EEPROM.get(eeAddress, target);
  Serial.println("Read custom object from EEPROM: ");
  Serial.println(target.field1);
  Serial.println(target.field2);
  Serial.println(target.name);
}

void loop() {
  /* Empty loop */
}

Output with platform = https://github.com/Jason2866/platform-espressif32.git:

Writing custom object to EEPROM: 
3.50
65
Hello!
Read custom object from EEPROM: 
0.00
140
��?

If I add a EEPROM.commit() before reading it’s the same.

Using platform = espressif32, I get:

Writing custom object to EEPROM: 
3.50
65
Hello!
Read custom object from EEPROM: 
0.00
0

Any ideas?

Where is the call to EEPROM.begin() with the max size of your stored information?

And conversely, where is the call to .commit() to flush to the flash?

Ah! That’s what I get for reading the Arduino docs (https://docs.arduino.cc/learn/programming/eeprom-guide) - they don’t seem to have an EEPROM.begin().

(I had tried commit, but it didn’t make any difference).

I hadn’t realised that the arduino-esp32 libraries had diverged, so the link is really helpful. If I understand right, the Preferences library is the proper way to go on ESP32 (arduino-esp32/libraries/Preferences at master · espressif/arduino-esp32 · GitHub). This makes my code look like this, which functions perfectly:

#include "Preferences.h"
#include "ColorStructures.h"

Preferences prefs;

void setup() {
    Serial.begin(115200);
    delay(1400);
    prefs.begin("colortest");
    FRGBW initial = FRGBW(0.0,0.25,0.5,0.75);
    FRGBW toStore = FRGBW(1.0,0.75,0.5,0.25);

    initial.toSerial();
    prefs.getBytes("incol",&initial,sizeof(FRGBW));
    initial.toSerial();
    prefs.putBytes("incol",&toStore,sizeof(FRGBW));
    initial.toSerial();
    prefs.getBytes("incol",&initial,sizeof(FRGBW));
    initial.toSerial();
}

void loop() {
  /* Empty loop */
}