嗨,我的代码中有一个错误,在Arduino Uno上使用Adafruit fona和GSM.我的void loop()有



错误如下:ISO c++禁止将字符串常量转换为'char*' [-Wwrite-strings]如果(! fona。sendSMS(callerIDbuffer, "嘿,我收到你的短信了")) {顺便说一下,我使用arduino和adafruit fona,任何想要帮助的人都非常感谢

这是我的代码

void loop() {

char* bufPtr = fonaNotificationBuffer;    //handy buffer pointer

if (fona.available())      //any data available from the FONA?
{
int slot = 0;            //this will be the slot number of the SMS
int charCount = 0;
//Read the notification into fonaInBuffer
do  {
*bufPtr = fona.read();
Serial.write(*bufPtr);
delay(1);
} while ((*bufPtr++ != 'n') && (fona.available()) && (++charCount < (sizeof(fonaNotificationBuffer)-1)));

//Add a terminal NULL to the notification string
*bufPtr = 0;
//Scan the notification string for an SMS received notification.
//  If it's an SMS message, we'll get the slot number in 'slot'
if (1 == sscanf(fonaNotificationBuffer, "+CMTI: " FONA_PREF_SMS_STORAGE ",%d", &slot)) {
Serial.print("slot: "); Serial.println(slot);

char callerIDbuffer[32];  //we'll store the SMS sender number in here

// Retrieve SMS sender address/phone number.
if (! fona.getSMSSender(slot, callerIDbuffer, 31)) {
Serial.println("Didn't find SMS message in slot!");
}
Serial.print(F("FROM: ")); Serial.println(callerIDbuffer);

// Retrieve SMS value.
uint16_t smslen;
if (fona.readSMS(slot, smsBuffer, 250, &smslen)) { // pass in buffer and max len!
Serial.println(smsBuffer);
}
//Send back an automatic response
Serial.println("Sending reponse...");
if (!fona.sendSMS(callerIDbuffer, "Hey, I got your text!")) {
Serial.println(F("Failed"));
} else {
Serial.println(F("Sent!"));
}

// delete the original msg after it is processed
//   otherwise, we will fill up all the slots
//   and then we won't be able to receive SMS anymore
if (fona.deleteSMS(slot)) {
Serial.println(F("OK!"));
} else {
Serial.print(F("Couldn't delete SMS in slot ")); Serial.println(slot);
fona.print(F("AT+CMGD=?rn"));
}
}
}
}

我认为char有错误,但我无法解决

这只是一个蹩脚的库,不使用const char *的C字符串参数,不会在函数内部改变。这是c++中老式的C风格方法

也应该作为警告而不是错误报告。现在您有两个选项-修复该库或忽略此警告。我不喜欢第二种选择,但这对你来说是最简单的方法(但忽略警告并不是一件好事,有时它们可能真的是一些讨厌的错误)。

相关内容

  • 没有找到相关文章

最新更新