Read data from SMS header


hy everyone!
i'm trouble acquiring data received sms header.
i want extract data number , message received sms.
i don't know why counters not working correctly , why password check returns false.

all welcome!

code: [select]
char receivedsms[120] = "";
int rcvdcheck = 0;
int rcvdconf = 0;
int indice = 0;
int rcvdfim = 0;
char number[13];

int msglength = 0;
string strnumber = "";

char password[5] = "1234";


char extractednumber[13];
char receivedtxt[25];


//######################################
//          functions
//######################################

void response()
{
  int count = 0;

  while (1)
  {
    if (serial1.available())
    {
      char data = serial1.read();
      if (data == 'k') {
        serial.println("ok");
        break;
      }
      if (data == 'r') {
        serial.println("error");
        break;
      }
    }
    count++;
    delay(10);
    if (count == 1000) {
      serial.println("gsm offline");
      break;
    }
  }
}

void config()
{
  serial.println("start: ");
  serial.println();

  delay(1000);
  serial.print("feedback disable:           ");
  serial1.print("ate0\r");
  response();

  serial.print("gsm status:                ");
  serial1.print("at\r");
  response();

  serial.print("sms mode:        ");
  serial1.print("at+cmgf=1\r");
  response();

  serial.print("sms text:    ");
  serial1.print("at+cnmi=1,2,0,0,0\r");
  response();

  serial.print("clean sms memory:        ");
  serial1.println("at+cmgd=1,4\r");
  response();

}

void clearbuffers()
{
  strcpy(receivedsms, "");
  strcpy(receivedtxt, "");
  rcvdcheck = 0;
  rcvdconf = 0;
  indice = 0;
  rcvdfim = 0;
  string strnumber = "";


  (int = 0; < 13; i++)
  {
    number[i] = ' ';
  };

  msglength = 0;
}


void extracttext()
{
  int contador = 0;
  int contadorvirgula = 0;
  int contadormais = 0;

  char pelica = '"';
  char virgula = ',';
  char mais = '+';

  int a, b = 0;


          (int x = 0; x < 120; x++)
          {           
           
                if (contador == 1)
                {
                  extractednumber[a] = receivedsms[x];
                  a++;               
                }

                if (contador == 6)
                {
                  receivedtxt[b] = receivedsms[x];
                  serial.print(receivedtxt[b]);
                  b++;               
                }
           
 
                if (receivedsms[x] == pelica)
                {
                  contador++;
                }
          }




 
  serial.println("extracted:");
  extractednumber[13]='\0';
  serial.println(receivedtxt);
  serial.println(extractednumber);
 


  serial.println("counters:");
  serial.println(contador);
  serial.println(contadorvirgula);
  serial.println(contadormais);
}


void recsms()
{


  if (serial1.available())
  {

    char data = serial1.read();

    if (data == '+') {
      rcvdcheck = 1;
    }
    if ((data == 'c') && (rcvdcheck == 1)) {
      rcvdcheck = 2;
    }
    if ((data == 'm') && (rcvdcheck == 2)) {
      rcvdcheck = 3;
    }
    if ((data == 't') && (rcvdcheck == 3)) {
      rcvdcheck = 4;
    }
    if (rcvdcheck == 4) {
      rcvdconf = 1;
      rcvdcheck = 0;
    }


    if (rcvdconf == 1)
    {
      if (data == '\n') {
        rcvdfim++;
      }
      if (rcvdfim == 3) {
        rcvdfim = 0;
      }

      receivedsms[indice] = data;
      indice++;

      if (rcvdfim == 2) {
        rcvdconf = 0;
        msglength = indice - 2;
        indice = 0;
      }

      if (rcvdconf == 0)
      {

        (int x = 4; x < 17; x++)
        {
          number[x - 4] = receivedsms[x];

        }

        strnumber = number;


        serial.println(strnumber);

        serial.println(receivedsms);

       
        extracttext();
       



        if (strstr(receivedtxt, password)!= null)
        {
          serial.println("password validated");
        }
        else
        {
          serial.println("password error");
        }

        serial.println("");
        serial.println("##################################################");
        serial.println("");


        clearbuffers();
      }
    }
  }
}
//#####################################################

void setup()
{
  serial.begin(9600);
  serial1.begin(9600);
  config();
}

void loop()
{
  recsms();
}

code: [select]
  int a, b = 0;
what value in after statement? if said zero, you'd wrong.

code: [select]
                  extractednumber[a] = receivedsms[x];
                  a++;

write @ random location, before, in middle of, or way past end of array , increment junk in a. not idea.






your excessive number of blank lines








               and your
   piss-poor indenting
                   leave










a lot desired. tools + auto format can indenting. delete the









excess blank lines yourself.


Arduino Forum > Using Arduino > Programming Questions > Read data from SMS header


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts