Problem facing abstract specific char array from GSM Serial data

hi,

i tried to take phone number from incoming SMS from serial data of GSM Module 800 with arduino.

But i have not getting success .

here is my code

#include <SoftwareSerial.h>

SoftwareSerial SIM900A(11, 10);

#include <Wire.h>


// Array to hold the number a SMS is retreived from

const byte numChars = 30;
char receivedChars[numChars];
boolean newData = false;
char tempChars[numChars];
void setup()
{
  SIM900A.begin(9600);   // Setting the baud rate of GSM Module
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  Serial.println ("SIM900A Ready");
  delay(1000);
  Serial.println ("Type s to send message or r to receive message");
  SIM900A.println("AT+CMGF=1");
  delay(500);
  SIM900A.print("AT+CNMI=2,2,0,0,0\r");
  delay(100);

}
void loop()
{

  if (SIM900A.available() > 0)
    Serial.write(SIM900A.read());
  strcpy(tempChars, receivedChars);
  recvWithEndMarker();
  showNewData();
  if (Serial.available() > 0)
    switch (Serial.read())

    {
      case 's':
        SendMessage();
        break;
      case 'r':

        RecieveMessage();
        break;
    }

}
void RecieveMessage()
{

  Serial.println ("SIM900A Membaca SMS");
  delay (4000);
  SIM900A.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  delay(500);

  //Serial.write ("Unread Message done");
}
void SendMessage()
{
  Serial.println ("Sending Message");
  SIM900A.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);

  SIM900A.println("AT+CMGS=\"+917987553768\"\r"); //Mobile phone number to send message*/
  delay(1000);

  SIM900A.println("hipp");// Messsage content
  delay(1000);

  SIM900A.println((char)26);// ASCII code of CTRL+Z
  delay(1000);

}
void recvWithEndMarker()
{

  static byte ndx = 0;
  char endMarker = '\n';
  char rc;


  while (SIM900A.available() > 0 && newData == false) {
    rc = SIM900A.read();

    if (rc != endMarker) {
      receivedChars[ndx] = rc;
      ndx++;
      if (ndx >= numChars)
      {
        ndx = numChars - 1;
      }
    }
    else {
      receivedChars[ndx] = '\0'; // terminate the string
      ndx = 0;
      newData = true;
    }
  }
}

void showNewData() {
  if (newData == true) {
    Serial.print("This just in ... ");
    Serial.println(receivedChars);
    newData = false;
  }
}


Serial out will be "This Justin......+CMT: "+91798755xx68","","21/12/13,18:32:56+22" Hfd
But iam getting the out put is This just in ... +979855768,","2/1/131832:7+2" H

Note:-I have made this program compile the other two program available in forum's old conversation and tutorials

where will be the problem ..please advice me...... :pray:

receivedChars has space for 29 characters and a null. It looks like you're receiving more than that.

After increase ,nothing improved

Probably overflowing receive buffer with all the commands you are sending without checking for replies in between.

Why are you reading input in loop outside of the receive function? You will lose characters doing that.

That's it!

I am not an expert in programing, please quote the line of program so that i can understand easily

Thanks for thread.But sms content not showing in single array

here is my code

#include <SoftwareSerial.h>

SoftwareSerial SIM900A(11, 10);

#include <Wire.h>


// Array to hold the number a SMS is retreived from
String textMessage;
const byte numChars = 80;
char receivedChars[numChars];
boolean newData = false;
char tempChars[numChars];
void setup()
{
  SIM900A.begin(9600);   // Setting the baud rate of GSM Module
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  Serial.println ("SIM900A Ready");
  delay(1000);
  Serial.println ("Type s to send message or r to receive message");
  SIM900A.println("AT+CMGF=1");
  delay(500);
  SIM900A.println("AT+CNMI=2,2,0,0,0\r");
  delay(100);

}
void loop()
{

  // if (SIM900A.available() > 0)
  //{
  //Serial.write(SIM900A.read());
  //}
  strcpy(tempChars, receivedChars);
  recvWithEndMarker();
  showNewData();
  if (Serial.available() > 0)
    switch (Serial.read())

    {
      case 's':
        SendMessage();
        break;

    }

}


void recvWithEndMarker()
{

  static byte ndx = 0;
  char endMarker = '\n';
  char rc;


  while (SIM900A.available() > 0 && newData == false) {
    rc = SIM900A.read();

    if (rc != endMarker) {
      receivedChars[ndx] = rc;
      ndx++;
      if (ndx >= numChars)
      {
        ndx = numChars - 1;
      }
    }
    else {
      receivedChars[ndx] = '\0'; // terminate the string
      ndx = 0;
      newData = true;
    }
  }
}

void showNewData() {
  if (newData == true) {
    Serial.print("This just in ... ");
    Serial.println(tempChars);
    newData = false;
  }
}
void SendMessage()
{
  Serial.println ("Sending Message");
  SIM900A.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);

  SIM900A.println("AT+CMGS=\"+917987553768\"\r"); //Mobile phone number to send message*/
  delay(1000);

  SIM900A.println("hipp");// Messsage content
  delay(1000);

  SIM900A.println((char)26);// ASCII code of CTRL+Z
  delay(1000);

}

S. O/p is

SIM900A Ready
Type s to send message or r to receive message
This just in ... 
This just in ... AT+CMGF=1


This just in ... OK

This just in ... AT+CNMI=2,2,0,0,0



This just in ... 
K

This just in ... +CMT: "+917987553768","","21/12/13,21:10:28+22"

This just in ... +CMT: "+917987553768","","21/12/13,21:10:28+22"


Now its some how working.But This just in ... +CMT: "+917987553768","","21/12/13,21:10:28+22" sms content not showing on array...why ?

please help me...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.