Pages: [1]   Go Down
Author Topic: Problem reading SMS and compare  (Read 295 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have huge problem  (and maybe misunderstand something) regarding compare incomming SMS with a string.
I'm comfused because it seems/should work, when print SMS to Monitor. Please look at my code below and the feedback from the monitor.

Code:
#include <SoftwareSerial.h>
#include <string.h>

String inData = "";

SoftwareSerial cell(2, 3);

void setup()
{
  Serial.begin(9600);
  cell.begin(9600);
  Serial.flush();
  cell.flush();
 
  delay(10000); //Wait for GSM
 
  Serial.println("Ready ..");
 }

void loop()
{
  if(cell.available() > 0)              // Test if we receive something on the serial port.
  {
    char recv = cell.read();            // Read characters into recv
    inData += recv;                     // Fill inData with characters received (recv)
    if (recv == '\n')                   // If receiving a newline char
    {
      Serial.print("-------------\n");  // Print control chars (--) to ensure we have New Line and ready to compare
      Serial.print(inData);             // Print full string from inData
     
      if (inData == "xxx")              // Compare inData with "xxx"
      {
        Serial.print("OK!\n");          // If xxx is received, then print OK!
      }
      inData="";                        // Clear inData buffer
    }
  }
}


/*
>>>>>>>This is what I'm receiving from incomming SMS on Serial Monitor<<<<<<<

Ready ..

-------------


-------------
+CMT: "+4512312312","","13/05/07,13:56:24+08"

-------------
xxx

*/

Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 48
Posts: 3393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You're adding the newline character you receive to the end of the string, so your comparison fails. try checking against "xxx\n" instead, or don't concatenate the newline.
Logged

Pages: [1]   Go Up
Jump to: