0

I am working with Arduino and SIM800A. My goal is to save the sms message received by SIM800A to a string variable to be used later. Yet to my surprise, the message always get cut off and I have no clue why.

I send to SIM:

This is a test message

The Serial Monitor only shows:

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

Below is the code

#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 = "";
  }
}
hacaoideas
  • 105
  • 8

0 Answers0