【问题标题】:How do I get an actual string into a char variable string (char variable with brackets) in Arduino?如何在 Arduino 中将实际字符串转换为 char 变量字符串(带括号的 char 变量)?
【发布时间】:2017-03-26 18:42:10
【问题描述】:

我对带有 ESP8266 和 ArduinoIDE 的 NodeMCU 有疑问:

我希望使用 softAP,并且密码应该在每次设备启动时随机生成,它应该是 8 位长,足以显示在我的 8 位 7 段显示器上。 我创建了一个 8digits 长并直接转换为字符串的数字。遗憾的是,“WiFi.softAP”命令只接受括号中的变量类型常量字符。如何以某种方式将字符串转换为带括号的字符或让 WiFi.softAP 吞下 String 类型?

我已经到这一步了:

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);

最好的问候 卖家

【问题讨论】:

标签: string arduino char arduino-esp8266


【解决方案1】:

为了解决这个问题,我简单地将整数取消注释到字符串行

//const char *password = spassword;

并将const char *password = spassword; 设为const char *password = spassword.c_str();,正如 Bence Kaulics 在我的帖子下的评论中回答的那样,它完美无缺。 谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-04
    • 2021-11-21
    • 1970-01-01
    • 2019-04-11
    • 2014-09-20
    • 1970-01-01
    • 2016-12-22
    相关资源
    最近更新 更多