0

I am trying to receive an SMS on my arduino and print it out to the serial monitor. I am using the A9G gsm/gps module for doing that. Here is the code for it

#include <SoftwareSerial.h>

//Create software serial object to communicate with A6
SoftwareSerial mySerial(10, 11); //A6 Tx & Rx is connected to Arduino #3 & #2

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(115200);
  
  //Begin serial communication with Arduino and A6
  mySerial.begin(115200);

  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=2,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
  updateSerial();
}

void loop()
{
  updateSerial();
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}

The code works and I get a response but the response does not include the body of the message. This is the response I got after sending "hello" to it;

CIEV: "MESSAGE",1
+CMT: "+233201729573",,"2021/06/18,12:20:03

As you can see it rightly sends me a notification but it does not include the "hello" which is the actual message I want to receive. Can anyone help me out?

1

I have sorted that out for sometime now. It turns out for some reason SerialSoftware was truncating my messages because the serial buffer size was too small. All I had to do was increase the buffer size to a higher number in the SoftwareSerial.h file and it worked.

0

Your serial reception code is much much much too primitive to be of any use.

You're waiting for 0.5 seconds for data to come in, which gets stored in a 64 byte buffer. Then you read out the contents of that 64 byte buffer.

Anything more than 64 bytes gets discarded.

You need to read the data actively as it comes in (NO delay()!) looking for specific things in the data (OK, ERROR, your text message response, etc) until the whole response from the modem has been received.

2
  • I recently jsut found out that I could change from 64 byte buffer to a much higher buffer. Which is what I did and now it works. However I am only able to do this on a windows pc and not from a linux system which is what I use.
    – Atia
    Jun 18 at 21:34
  • Just to add up, after searching for the SoftwareSerial.h file and finding out its location and changing the serial buffer size, I am able to get it working on a linux system(ubuntu) now. Thanks.
    – Atia
    Sep 27 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.