Go Down

Topic: Some SMS get not recognized as new messages by IsSMSPresent (Read 238 times) previous topic - next topic

mulbrich

Hello,

I am using an Arduino UNO R3 and an IComsat v1.1 SIM900 shield with the library I found here:
http://code.google.com/p/gsm-shield-arduino/
which I think is what a lot of other people are using too.

I want to build a device that I can program by sending text messages, so it should see when a new message arrives. I am sending text messages and they arrive fine, but some of them are not being recognized as new messages. But they are there, I can actually read them out.
This is my code:
Code: [Select]
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;
boolean started=false;
int num, k;
char smsbuffer[160];
char n[20];
long int com;

void setup()
{
  Serial.begin(9600);

  if (gsm.begin(2400)){
    Serial.println("\nstatus=READY");
    started=true; 
  }
  else Serial.println("\nstatus=IDLE");

  if(started)
  {
    for (k = 1; k <= 20; k++)                      // free up first 20 positions of messages on SIM card
    {
      Serial.print(k);
      if(sms.GetSMS(k, n, smsbuffer, 160)) sms.DeleteSMS(k);
    }
  }
  Serial.println();
}

void loop()
{
  if (Serial.available() > 0) 
  {
    com = Serial.read();
    if (com == 'x') Serial.println("Hello");
  }
   
  if (started)
    if (num = sms.IsSMSPresent(SMS_UNREAD))
    {
      Serial.println ("New SMS!");
      Serial.print ("Number: ");
      Serial.println (num);
    }
  delay(1000);     
}


When I am sending messages from my cell phone I obtain the following output at the serial monitor:
Code: [Select]
status=READY
1234567891011121314151617181920
Hello
New SMS!
Number: 1
New SMS!
Number: 2
New SMS!
Number: 5


So number 3 and 4 are not being recognized as new messages here.
Surprisingly I found that when I remove the few lines where I read the serial port just at the begin of the loop function, it works better, i.e. less messages are skipped. That's why I kept it here in this code.

Is anyone able to explain to me what the problem is and how I can fix this?

Thanks a lot for your input,

Max

Go Up