[英]Sim800l save input as a string
I'm trying to save my received SMS into a string but it doesn't work.我正在尝试将收到的短信保存到字符串中,但它不起作用。 This is my error message:这是我的错误信息:
recive_0_1:50:28: error: invalid conversion from 'int' to 'char ' [-fpermissive] exit status 1 invalid conversion from 'int' to 'char ' [-fpermissive] This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.** recive_0_1:50:28:错误:从 'int' 到 'char ' [-fpermissive] 的无效转换退出状态 1 从 'int' 到 'char ' [-fpermissive] 的无效转换此报告将包含“显示详细 output在文件 -> 首选项中启用“编译期间”选项。**
#include <SoftwareSerial.h>
#include <string.h>
char message[160]; // max size of an SMS
char* text;
String data;
//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(4, 5); //SIM800L Tx & Rx is connected to Arduino #3 & #2
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
//Begin serial communication with Arduino and SIM800L
mySerial.begin(9600);
Serial.println("Initializing...");
delay(1000);
mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
updateSerial();
mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
updateSerial();
mySerial.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
updateSerial();
}
void loop()
{
updateSerial();
}
void updateSerial()
{
// char c;
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
//char data=Serial.read();
//Serial.println(data,DEC);
}
while(mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
text=mySerial.read();
Serial.print(text);
//}
}
}
It looks like you're running into problems from trying to convert integers to characters.看起来您在尝试将整数转换为字符时遇到了问题。 I use the below code to read from my SIM card to my SIM900 device:我使用以下代码从我的 SIM 卡读取到我的 SIM900 设备:
1st: my software serial is defined and my setup script run:第一:我的软件序列被定义并且我的安装脚本运行:
SoftwareSerial gprsSerial(7, 8);
void setup()
{
pinMode(13, OUTPUT);
gprsSerial.begin(19200);
Serial.begin(19200);
delay(200);
// set up your AT COMMANDS HERE - I HAVE NOT INCLUDED THESE
}
Then I run my loop function as follows, calling the additional functions specified thereafter, :然后我运行我的循环 function 如下,调用其后指定的附加函数:
void loop() {
readSMS();
delay(2000);
} }
void toSerial(){
delay(200);
if(gprsSerial.available()>0){
textMessage = gprsSerial.readString();
delay(100);
Serial.print(textMessage);
}
}
void readSMS() {
textMessage = "";
gprsSerial.print("AT+CSQ\r");
toSerial();
gprsSerial.print("AT+CMGF=1\r");
toSerial();
gprsSerial.println("AT+CNMI=2,2,0,0,0\r");
delay(2000);
toSerial();
}
With the above you should not get any data type conversion hassles.有了上述内容,您应该不会遇到任何数据类型转换的麻烦。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.