Arduino草图中从字符串常量到'char *'[-Wwrite-strings]错误的弃用转换 [英] Deprecated conversion from string constant to 'char*' [-Wwrite-strings] error in Arduino sketch
本文介绍了Arduino草图中从字符串常量到'char *'[-Wwrite-strings]错误的弃用转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Arduino和ESP8266发送传感器数据.但是在Arduino中编译草图时,我收到一条错误消息-不建议从字符串常量转换为'char *'[-Wwrite-strings] .
I'm sending sensor data using Arduino and ESP8266. But while compiling the sketch in Arduino I'm getting an error saying - deprecated conversion from string constant to 'char*' [-Wwrite-strings].
#include "SoftwareSerial.h"
SoftwareSerial esp(10, 11);// RX, TX
void setup() {
esp.begin(9600);
Serial.begin(9600);
delay(100);
Serial.println("Started...");
reset();
connectWifi();
}
//reset the esp8266 module
void reset() {
esp.println("AT+RST");
delay(1000);
if (esp.find("OK")) Serial.println("Module Reset"); //error
}
推荐答案
正如Aeldred所说,您只需要将String强制转换为 char * .
As Aeldred said you have just to cast you String to char*.
所以您的草图将如下所示:
so your sketch will looks like :
#include "SoftwareSerial.h"
SoftwareSerial esp(10, 11);// RX, TX
void setup() {
esp.begin(9600);
Serial.begin(9600);
delay(100);
Serial.println("Started...");
reset();
connectWifi();
}
//reset the esp8266 module
void reset() {
esp.println("AT+RST");
delay(1000);
if (esp.find((char*)"OK")) Serial.println("Module Reset"); //error
}
这篇关于Arduino草图中从字符串常量到'char *'[-Wwrite-strings]错误的弃用转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文