Go Down

Topic: ESP8266 EEPROM (Read 366 times) previous topic - next topic

x0tester0x

Hello Arduino Community,
I get the values of the EEPROM, but then it throws an error.

Code: [Select]

#include <EEPROM.h>

struct SCHEDULES
{
  String TIME_START;
  String TIME_STOP;
};

void setup()
{
  Serial.begin(115200);
  delay(1000);
 
  EEPROM.begin(512);
 
  test();
}

void test()
{
  int address = 0;
 
  SCHEDULES y = {"07:00", "10:00"};
  EEPROM.put(address, y);
  EEPROM.commit();
  SCHEDULES z;
  EEPROM.get(address, z);
  Serial.println(z.TIME_START);
  Serial.println(z.TIME_STOP);
}

void loop()
{
 
}


Quote
07:00
10:00

Exception (3):
epc1=0x401001ad epc2=0x00000000 epc3=0x00000000 excvaddr=0x400311e8 depc=0x00000000

ctx: cont
sp: 3ffefa40 end: 3ffefc90 offset: 01a0

>>>stack>>>
3ffefbe0:  3fffdad0 00000005 3ffeec40 40202495 
3ffefbf0:  3ffefcd4 000001fe 000001fe 4010029c 
3ffefc00:  3fffdad0 3ffe8a98 3ffefc48 40100720 
3ffefc10:  3ffe8a98 400042db 3fff1084 40202580 
3ffefc20:  40004b31 3ffe8a98 3ffeec40 4020210e 
3ffefc30:  00000000 00000000 00000000 00000000 
3ffefc40:  00000000 00000000 3fff11bc 0000000f 
3ffefc50:  00000005 00000000 00000000 00000000 
3ffefc60:  feefeffe 00000000 3ffeec5c 40202147 
3ffefc70:  feefeffe feefeffe feefeffe 402027c8 
3ffefc80:  feefeffe feefeffe 3ffeec70 40100108 
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(1,6)


 ets Jan  8 2013,rst cause:4, boot mode:(1,6)

wdt reset

I hope you can help.

pylon

Code: [Select]
  SCHEDULES y = {"07:00", "10:00"};
  EEPROM.put(address, y);


You cannot put or read complex types with one call. Use simple types that store their data in consecutive order in memory as the EEPROM class can only handle such types. So don't use the String class, use character arrays and serialize your data before storing, deserialize after reading again.

x0tester0x


wildbill

You cannot put or read complex types with one call.
That was my thought too, but the example in the documentation says otherwise. I can't prove it with the version of the IDE I have though (1.6.12). Nothing that includes EEPROM.h will compile.

pylon

Quote
That was my thought too, but the example in the documentation says otherwise. I can't prove it with the version of the IDE I have though (1.6.12). Nothing that includes EEPROM.h will compile.
That example has an object that has a flat memory footage, so no pointers used. The object the OP used has not flat objects that uses pointers to connect the information, so a pointer to that object doesn't provide a (reversible) serialization of the object as bytes.

Go Up