嗨,我的代码中使用Adafruit Fona和Arduino Uno上的GSM存在错误。我的void loop()有错误,它向我发送了一个错误:
这是错误:ISO C ++禁止将字符串常数转换为'char*'[-wwrite-strings] 如果(! 顺便说一句,我正在使用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=?\r\n"));
}
}
}
}
我认为char有错误,但我无法解决
here is the error: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
if (!fona.sendSMS(callerIDbuffer, "Hey, I got your text!")) {
i am using arduino and adafruit fona by the way, any one who wants to help is very much appreciated
here is my code
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=?\r\n"));
}
}
}
}
i think theres an error in char but i can't solve it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这只是糟糕的库,它不使用
const char *
对c字符串参数,这些参数不会在功能内部更改。这是C ++中的旧校C风格方法。另外,应该将其报告为警告,而不是错误。现在您有两个选择 - 修复该库或忽略此警告。我不喜欢第二种选择,但这对您来说是最简单的方法(但是忽略警告不是一件好事,有时它们可能真的很讨厌的错误)。
It's just crappy library that doesn't use
const char *
for C string parameters that won't get changed inside of functions. It's old school C style approach in C++.Also it should be reported just as a warning, not an error. Now you have two options - fix that library or ignore this warning. I don't like the second option, but it'll be the easiest way for you (but it's not a good thing to ignore warnings, sometimes they might be realy on point of some nasty bug).