获取错误:将'const char*'分配给'char [100]'的类型不兼容



我正在尝试将一个字符保存到EEPROM,然后检索它。我使用的是带有此代码的ESP32-CAM和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();
}
}

当我这样做时,我会得到错误:

incompatible types in assignment of 'const char*' to 'char [100]'

我通过串行将ssidString和pskString从ESP12e发送到ESP32-CAM,并通过使字节数为100使其工作,因为它不知道所述和传递的长度。

我正试图从EEPROM中获取数据,并将其放入WiFi.begin(ssidString, pskString);

有人能帮忙吗?

尝试:

String uuu = String(pskString);
String www = String(ssidString) + uuu;

此外,您不应该使用==来比较c字符串;尝试:

if (strcmp(ssidString, "") != 0)

else if(strcmp(ssidString, "") == 0)

看看在这些更改之后会出现什么错误(如果有的话(。

相关内容

  • 没有找到相关文章

最新更新