Getting error: incompatible types in assignment of 'const char*' to 'char [100]'
Getting error: incompatible types in assignment of 'const char*' to 'char [100]'
我正在尝试将一个字符保存到 EEPROM,然后再检索它。
我正在使用带有此代码和 arduino IDE:
的 ESP32-CAM
#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)
并查看这些更改后出现的错误(如果有)。
我正在尝试将一个字符保存到 EEPROM,然后再检索它。 我正在使用带有此代码和 arduino IDE:
的 ESP32-CAM#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)
并查看这些更改后出现的错误(如果有)。