Record (Save) serial monitor text in a string

Hi there

I am trying to do a project with SIM808 module and an Arduin UNO. I want to receive an SMS, process it and make some feedback based on the received SMS. So, I need to record the received SMS in a string so that I can do the process. my code for send and receive is provided here:

 #include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 10);
String text="zero";   
void setup()
{
  mySerial.begin(9600);   // Setting the baud rate of GSM Module  
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  delay(100);
}


void loop()
{
  if (Serial.available()>0)
   switch(Serial.read())
  {
    case 's':
      SendMessage();
      break;

    default:
      RecieveMessage();
      break;
  }

 if (mySerial.available()>0)
   Serial.write(mySerial.read());

     if (text!="zero"){
      mySerial.println("that is good");

      delay(90000);
  
  }
}



 void SendMessage()
{
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"+989171887761\"\r"); // Replace x with mobile number
  delay(1000);
  mySerial.println("I am SMS from GSM Module");// The SMS text you want to send
  delay(100);
   mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}


 void RecieveMessage()
{
  mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS

  delay(1000);
 }

And what I receive in my serial monitor is (I sent a text message with body “Test12” here):

+CMT: "+9123456789","","17/11/16,01:37:46+14"
Test12

Now, I need to record all the printed stuff, or the body of the message. So, my question is that how can I record it as a string?

Your help is very appreciated. If you know any old post related to this also, I would be grateful to see, sorry, I could not find what I want!

Thanks for your help

Zeedo65

You can't get it back from the serial monitor. But your code sent it to the serial monitor so your code could save it to a string before it prints it to the serial monitor.

Serial.write(mySerial.read());

Instead of just passing it straight through to the serial monitor see @Robin2's Serial Input Basics thread (google can find it) and learn how to store what you are receiving into a char array.

Now, I need to record all the printed stuff, or the body of the message. So, my question is that how can I record it as a string?

First step is to figure out which code is reading the data that is arriving from the GSM. That would be easier if you were not using such a dumb name for the instance of the SoftwareSerial class that reads that data.

Second step is to actually create an array to store the data in.

Third is to store the data in a variable so that it can be stored in the array and sent to the Serial Monitor application.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

Thank you very much everybody. I got to know where the problem is.

It is very true Robin2:“Two or three hours spent thinking and reading documentation solves most programming problems.” :slight_smile:

hey zedo .
can u explain mee how did u solve it?

After 3 years, not much chance zeedo65 is here tonight. Try sending a PM and start your own topic on the subject if you can't get help there.

Also :) did you follow the links and suggestions posted above? :)