简体   繁体   English

Sim800l 将输入保存为字符串

[英]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.

相关问题 SIM800L 串接 - SIM800L string concatenation 如何将串行数据(URL)发送到sim800l以获取长字符串 - How to send serial data (URL) to the sim800l for long strings 如何将TextEdit字段的输入保存到字符串中? - How to save input from TextEdit field into a string? JAVA:在Jframe GUI中将用户输入另存为字符串 - JAVA: Save user input as a string in a Jframe GUI 字符串“ Hello \\ 0”是否等于{&#39;H&#39;,&#39;e&#39;,&#39;l&#39;,&#39;l&#39;,&#39;o&#39;,&#39;\\ 0&#39;}或{&#39;H&#39;,&#39;e&#39;,&#39;l&#39;, &#39;l&#39;,&#39;o&#39;,&#39;\\ 0&#39;}? - Is the string “Hello\0” equal to {'H','e','l','l','o','\0'} or {'H','e','l','l','o','\0'}? Arduino字符串检查SIM900A GSM模块编程代码 - Arduino String checking SIM900A GSM module programming code 构建长度为L的字符串,其中正好有N个回文 - Build string of length L with exactly N palindromes in it C ++:将L“”字符串分配给WCHAR []? - C++: Assign L“” string to WCHAR[]? 如何制作扫描用户输入(文本)并将其保存在动态字符串上的C程序 - How can i make C program that scans user's input(text) and save it on a dynamic string 将输入文本的十六进制值保存到字符串var中,反之亦然ANSI C - Save hex value from input text to a string var and vice versa ANSI C
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM