Arduino + SIM800A 消息被切断

问题描述 投票:0回答:1

我正在使用 Arduino 和 SIM800A。我的目标是将SIM800A收到的短信保存到一个字符串变量中以供以后使用。但令我惊讶的是,消息总是被切断,我不知道为什么。

我发送至 SIM:

This is a test message

串行监视器仅显示:

+CMT: "+XXXXXXXXXX","","21/02/20,01:52:40+28"
This is a tes

下面是代码

#include <SoftwareSerial.h>

// Configure software serial port
SoftwareSerial Sim(2, 3);

// Variable to store text message
char incomingMessage;
String textMessage;

void setup() {

  pinMode(13, OUTPUT);
  digitalWrite(13, HIGH);
  // Initializing serial commmunication
  Serial.begin(9600);
  Sim.begin(9600);
  delay(100);

  while (!Sim.available()) {
    Sim.println("AT");
    delay(200);
    Serial.println("Connecting...");
  }
  Serial.println("Connected!");
  Sim.println("AT+CMGF=1");  //Set SMS to Text Mode
  delay(200);
//  Sim.println("AT+CMGL=\"ALL\""); 
//  delay(500);
  Sim.println("AT+CNMI=1,2,0,0,0");  //Procedure to handle newly arrived messages(command name in text: new message indications to TE)
  delay(1000);
  Sim.read();
  //Sim.println("AT+CMGL=\"REC UNREAD\""); // Read Unread Messages
}

void loop() {


  if (Sim.available()>0) {
    delay(200);

    // Serial Buffer
    while (Sim.available()>0) {
      incomingMessage = Sim.read();
      textMessage += incomingMessage;
    }

    delay(500);

    Serial.println(textMessage);

    textMessage = "";
  }
}
arduino gsm sim800
1个回答
0
投票

您好,正如您所说,我已经尝试了相同的写入 AT+CNMI=2,2,0,0,0 但仍然没有收到完整长度的消息。我使用的是 SIM800L 模块,它仅接收消息的前 13 个字符。

© www.soinside.com 2019 - 2024. All rights reserved.