0

I am very very new to ESP Programming.

I am trying to store Strings into EEPROM of ESP8266. I am storing the string into eeprom successfully but while reading it from EEPROM extra character 'd' is coming into the picture. I assumed it is a character to end the string but it does being used into the String url and the further code of connecting to server is throwing error due to wrong URL. My question is how to resolve this issue.

void writeString(int addr, String data)
{

   uint8_t size = data.length();
   for (uint8_t i = 0; i < size; i++) {
      EEPROM.write(addr + i, data.charAt(i));
   }
   EEPROM.write(addr + size, '\0');
   EEPROM.commit();

}


String read_String(int addr)
{

  String result = "";
  uint8_t count = 0;
  while (true) {
     char byte = EEPROM.read(addr + count);
     if (byte == '\0') {
       break;
     }
     else {
       result.concat(byte);
     }
  count++;
  }

 result = result.substring(0, (result.length()));
 return result;

}

Function Calling Snippet:

//Writting to EEPROM
String inputMessage1 = "myurl.co.in";
writeString(10, inputMessage1);

//READING from EEPROM
String hostStr = read_String(10);
Serial.print( "Connecting to Server... "+hostStr);

OUTPUT

Connecting to Server... myurl.co.ind
  • Include serial print into your routines and do a step by step debug on the serial monitor Its like finding Waldo. – Codebreaker007 Mar 26 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.