String 如何在Arduino中将实际字符串转换为字符变量字符串(带括号的字符变量)?
我对带有ESP8266和ArduinoIDE的NodeMCU有问题: 我想使用一个软AP,每次设备启动时都会随机生成密码,密码长度应该是8位,刚好可以显示在我的8位7段显示器上。 我创建了一个8位数长的数字,并直接转换为字符串。遗憾的是,“WiFi.softAP”命令只接受括号中的变量类型常量字符。我怎样才能将字符串放入带括号的字符中,或者让WiFi.softAP吞下字符串类型 我已经做到了这一点:String 如何在Arduino中将实际字符串转换为字符变量字符串(带括号的字符变量)?,string,arduino,char,arduino-esp8266,String,Arduino,Char,Arduino Esp8266,我对带有ESP8266和ArduinoIDE的NodeMCU有问题: 我想使用一个软AP,每次设备启动时都会随机生成密码,密码长度应该是8位,刚好可以显示在我的8位7段显示器上。 我创建了一个8位数长的数字,并直接转换为字符串。遗憾的是,“WiFi.softAP”命令只接受括号中的变量类型常量字符。我怎样才能将字符串放入带括号的字符中,或者让WiFi.softAP吞下字符串类型 我已经做到了这一点: MAX7219_7segment PWScreen(14,12,13); String A,B,
MAX7219_7segment PWScreen(14,12,13);
String A,B,C;
const char *ssid = "Sellerie";
ESP8266WebServer server(80);
/* Just a little test message. Go to http://192.168.4.1 in a web browser
* connected to this access point to see it.
*/
void handleRoot() {
server.send(200, "text/plain", C);
}
void setup() {
int pw = random(10000000,99999999);
String spassword = String(pw);
//const char *password = spassword;
pinMode(0, INPUT); // D0
pinMode(5, INPUT); //D1
pinMode(LED_BUILTIN, OUTPUT);
pinMode(14, OUTPUT);
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.print("Configuring access point...");
WiFi.softAP(ssid, spassword);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
server.on("/", handleRoot);
server.begin();
Serial.println("HTTP server started");
PWScreen.write_number(pw);
致意
Sellerie为了解决这个问题,我只需将整数取消注释为字符串行
//const char*password=spassword代码>
并使const char*password=spassword
toconst char*password=spassword.c_str()代码>正如Bence Kaulics在我的帖子下的评论中所回答的那样,它工作得完美无缺。
谢谢 const char*password=spassword.c_str()代码>成功了,谢谢!