Go Down

Topic: read String from EEPROM via function (Read 151 times) previous topic - next topic


I'm trying to read the stored string in eeprom. The storing method is at the thread:

https://forum.arduino.cc/index.php?topic=503469.15 post #16

I found a tutorial at http://forum.arduino.cc/index.php?topic=73078.0 and that perfectly works. But this is not exactly my case.

Now, I need to read it back. I have tried with the function:

Code: [Select]
String readEepromString(int strSizeEepromAddr, int strEepromAddrOffset) {
//void readEepromString(String strToRead) {
  int strSize = EEPROM.read(strSizeEepromAddr);
  char strBuff[strSize];
  String strToRead;
  for (int i = strEepromAddrOffset; i <= (strEepromAddrOffset+strSize); i++) {
    strBuff[i] = EEPROM.read(i);
  strToRead = String(strBuff);
  return strToRead;

Called it as:

Code: [Select]
Serial.println(readEepromString(SERVER_ADDR_SIZE, SERVER_ADDR_OFFSET));

here ADDR_SIZE = 34, ADDR_OFFSET = 35 as a reference.

The output is coming as

Server Addr via eeprom:
Server set to: !Ÿ!¬

I'm totally confused. Also the regular method is not working for reading from eeprom, though the other way shen i saved, it did perfectly. I'm not sure what I'm missing...

Code: [Select]
Serial.print("Server Addr via eeprom: ");
      String serverURL;
      //readEepromString(serverURL, SERVER_ADDR_SIZE, SERVER_ADDR_OFFSET);
      //readEepromString(serverURL, 34, 35);
      Serial.println(readEepromString(SERVER_ADDR_SIZE, SERVER_ADDR_OFFSET));

      int strSize = EEPROM.read(SERVER_ADDR_SIZE);
      char strBuff[strSize];
      for (unsigned int i = SERVER_ADDR_OFFSET; i <= (SERVER_ADDR_OFFSET+strSize); i++) {
        strBuff[i] = EEPROM.read(i);
      String sub_str = String(strBuff);
      //Serial.println(); //for debug
      //Till above can be ommited if wish, as reading from eeprom is not a mandatory at this stage
      Serial.print("Server set to: ");

Advise please...


Done... the solution was a at https://gist.github.com/smching/05261f11da11e0a5dc834f944afd5961

and I had to make some small corrections as m requirement. Else it's working nice.

Go Up