I have been playing Arduino for couple of days as expected hitting some road blocks. My project needs to store auth details in order to authenticate. So I used EEPROM to store those value and It worked as expected but the problem arose after resetting power. The stored got corrupted after resetting the power. I have added the output of the serial monitor before and after resetting the power. All your help would be much appreciated. Thanks
Before power reset
This. All you can really store into EEPROM are bytes; if you try to store a struct of Strings like you are doing, you are asking for trouble. Store your data into fixed-size c-strings. Since they are arrays of chars and a char is 8 bits long, it's easy to shuttle them in and out of EEPROM.
I hope you are being sensible with EEPROM usage and you are not writing to it more often than necessary.
I think it can be done with some overhead, but they have to be structures of fixed-size elements. Something like
struct FooBar
{
char foo[20];
char bar[10];
};
should work, because we know beforehand that it's always going to take up 30 bytes in EEPROM. Of course, as long as the size is fixed, you can always flatten the structure into single bytes, store these into EEPROM and then reconstruct the original structure from EEPROM readings. A String is problematic because we don't know how big it's going to end up being at compile time.
If I experienced this issue I would first test with the most basic (easy) data configuration. Then if that does not get corrupted on restart I would incrementally move towards the structure I wanted.
But that's just me.
That seems reasonable: I do follow a similar approach. Sometimes, I'd start with dummy, hard-coded data, just to test the functions downstream. And, generally (i.e. not only in cases like this one) I steer clear of String. It's just too messy.