不推荐在 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屋!
查看全文