So im currently trying to use the serial input to save the ssid of my network to the memory of my esp32 with the EEPROM.h library and then read the memory to output it on the serial monitor.
To write it to the memory i made an extra function:
void storeSSID()
{
char SSID[33]; //char array to write it byte by byte
int len = 0; //Length of String
while(Serial.available()<=0){}
Serial.println();
String Message = Serial.readStringUntil('\n'); //reading the ssid from the serial monitor
len = Message.length() - 1;
Message.toCharArray(SSID, 33); //turning it into a char array
Serial.println(Message);
for(int i=0;i<=len;i++)
{
EEPROM.write(i,SSID[i]);
}
EEPROM.commit();
}
//this part is in my setup() function
char buf[8];
for(int i=9;i>0;i--)
{
buf[i] == EEPROM.read(i);
Serial.println(buf[i]);
display.print(buf[i]);
}
However when i read from the Memory it only outputs null terminators. It is being written reversed in the for loop because i had some weird problem where the loop wouldnt finish when ive done it in normal order.
it was also set to 1 byte in the guide from "Random Nerd Tutorials" and since i had to save every character in a seperate byte i thought i could leave it like that
Then, you define the EEPROM size. This is the number of bytes you’ll want to access in the flash memory. In this case, we’ll just save the LED state, so the EEPROM size is set to 1.
They are only saving the LED state, hence 1 byte of EEPROM is good enough, but you need room for the whole SSID including its terminating '\0' character
As a side note, did you notice that EEPROM on the ESP32 is new deprecated in favour of the Preferences library ?
have a look at the ESP32 preferences library - the documentation states It should be considered as the replacement for the Arduino EEPROM library.
Edit: missed that @UKHeliBob had already recommended preferences!!