Thank you all for helping me out. This is what I ended up using (ESP8266 1.0 12E with Arduino IDE):
#include <EEPROM.h>
#include <ESP8266WiFi.h>
void setup()
{
Serial.begin(115200);
EEPROM.begin(512);
delay(5000);
Serial.println("clearing EEPROM...");
// write a 0 to first 1000 bytes of the EEPROM
for (int i = 0; i < 1000; ++i) {
EEPROM.write(i, -1);
}
EEPROM.commit();
delay(5000);
Serial.println("Reading EEPROM ssid");
String esid;
for (int i = 0; i < 64; ++i)
{
esid += char(EEPROM.read(i));
}
Serial.print("SSID: ");
Serial.println(esid);
Serial.println("Reading EEPROM pass");
String epass = "";
for (int i = 64; i < 128; ++i)
{
epass += char(EEPROM.read(i));
}
Serial.print("PASS: ");
Serial.println(epass);
}
void loop()
{
}
It's probably longer than it has to be but I pulled stuff from other sketches I've worked on and prioritize function over form. This writes a "-1" to the first 1000 bytes and then prints the first 128 bytes. Since I am only concerned about the first 50 bytes or so this was sufficient for my needs.
EEPROM.commit();
or maybeEEPROM.end();
after writing-1
instead.EEPROM.write()
, you are actually erasing an EEPROM cell, then writing a new value into it. This takes 3.4 ms, irrespective of the value written. You could do an erase-only operation, which takes only 1.8 ms. It looks, though, like this cannot be done with the Arduino EEPROM library, and not even with <avr/eeprom.h> from avr-libc. You would have to access the EEPROM address and control registers directly, as documented in the datasheet of the MCU.