Pages: [1]   Go Down
Author Topic: Problem reading SMS and compare  (Read 382 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
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.

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

String inData = "";

SoftwareSerial cell(2, 3);

void setup()
  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 =;            // 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"




New Jersey
Online Online
Faraday Member
Karma: 70
Posts: 3732
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.

Pages: [1]   Go Up
Jump to: