I am trying to save a char to EEPROM and then retrieve it. I am using an ESP32-CAM with this code and the Arduino IDE:
#include <EEPROM.h>
int addr = 0;
char ssidString[100] = {0};
float floatFromPC2 = 0;
char pskString[100] = {0};
void setup() {
if (!ssidString == "") {
EEPROM.begin(512); //Initialize EEPROM
EEPROM.write(addr, 'A'); //Write character A
addr++; //Increment address
EEPROM.write(addr, 'B'); //Write character A
addr++; //Increment address
EEPROM.write(addr, 'C'); //Write character A
String uuu = pskString;
String www = ssidString + uuu;
Serial.print(www);
for (int i=0; i<www.length(); i++) { //loop upto string lenght www.length() returns length of string
EEPROM.write(0x0F+i,www[i]); //Write one by one with starting address of 0x0F
}
EEPROM.commit();
} else if (ssidString == "") {
EEPROM.begin(512);
Serial.println("WHAT"); //Goto next line, as ESP sends some garbage when you reset it
Serial.print(char(EEPROM.read(addr))); //Read from address 0x00
addr++; //Increment address
Serial.print(char(EEPROM.read(addr))); //Read from address 0x01
addr++; //Increment address
Serial.println(char(EEPROM.read(addr))); //Read from address 0x02
addr++; //Increment address
Serial.println(char(EEPROM.read(addr))); //Read from address 0x03
//Read string from eeprom
String www;
//Here we dont know how many bytes to read it is better practice to use some terminating character
//Lets do it manually www.circuits4you.com total length is 20 characters
for (int i=0; i<16; i++) {
www = www + char(EEPROM.read(0x0F + i)); //Read one by one with starting address of 0x0F
}
String uuu;
for (int i=31; i<32; i++) {
uuu = char(EEPROM.read(0x0 + i));
}
Serial.println("this");
Serial.print(www); //Print the text on serial monitor
Serial.println("that");
Serial.print(uuu);
ssidString = www.c_str();
pskString = uuu.c_str();
}
}
When I do this I get the error:
incompatible types in assignment of 'const char*' to 'char [100]'
I am sending the ssidString and pskString over from an ESP12e to an ESP32-CAM via serial and got it to work by making the byte numbers 100 since it is not know what length the said and pass will be.
I am trying to get the data from EEPROM and put it into WiFi.begin(ssidString, pskString);
Can someone help with this?
Try:
String uuu = String(pskString);
String www = String(ssidString) + uuu;
Also, you shouldn't compare c strings using ==
; try:
if (strcmp(ssidString, "") != 0)
and
else if(strcmp(ssidString, "") == 0)
and see what errors you get after those changes, if any.