guys,
I'm trying to read the stored string in eeprom. The storing method is at the thread:
neteemrom confusion - Networking, Protocols, and Devices - Arduino Forum post #16
I found a tutorial at Getting string value out of function - Programming Questions - Arduino Forum and that perfectly works. But this is not exactly my case.
Now, I need to read it back. I have tried with the function:
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:
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:
F
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...
Serial.print("Server Addr via eeprom: ");
String serverURL;
//readEepromString(serverURL, SERVER_ADDR_SIZE, SERVER_ADDR_OFFSET);
//readEepromString(serverURL, 34, 35);
//readEepromStr(serverURL);
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: ");
Serial.println(sub_str);
Advise please...