SARENT-SORENTO / gsm-shield-arduino

Automatically exported from code.google.com/p/gsm-shield-arduino
0 stars 0 forks source link

::IsSMSPresent and ::GetSMS not returning next message's position? #69

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
...
position = sms.IsSMSPresent(SMS_UNREAD);
if (position) {
    sms.GetSMS(position, phone_num, sms_text, 100);
}
...

this is the first returned gsm.comm_buf

+CMGL: 5,"REC UNREAD","+639175086850","","13/03/20,16:34:30+32"
First Message

OK

and this is the 2nd returned gsm.comm_buf

+CMT: "+639175086850","","13/03/20,16:41:14+32"
Second Message

+CMGL: 7,"REC UNREAD","+639175086850","","13/03/20,16:41:14+32"
Second Message

OK

----
notice that in the 2nd buff, there is a +CMT:
since the function ::IsSMSPresent is getting only the first occurrence of ":" 

it will get the position of that of CMT not the CMGL with position beside it

Original issue reported on code.google.com by gm-jet...@jeth-ro.com on 20 Mar 2013 at 1:21

GoogleCodeExporter commented 9 years ago
After the first received message, did you send an SMS from Arduino to someone?

Original comment by martines...@gmail.com on 24 Mar 2013 at 1:22

GoogleCodeExporter commented 9 years ago
No, there were no code in the sketch to send outgoing msg, i have come up with 
an alternative to keep looking for the right ret_val by checking if the 
ret_val's next char is a comma,

here's the whole fnc

...
char SMSGSM::IsSMSPresent(byte required_status) 
{
  char ret_val = -1;
  char *p_char;
  byte status;

  if (CLS_FREE != gsm.GetCommLineStatus()) return (ret_val);
  gsm.SetCommLineStatus(CLS_ATCMD);
  ret_val = 0; // still not present

  switch (required_status) {
    case SMS_UNREAD:
      gsm.SimpleWriteln(F("AT+CMGL=\"REC UNREAD\""));
      break;
    case SMS_READ:
      gsm.SimpleWriteln(F("AT+CMGL=\"REC READ\""));
      break;
    case SMS_ALL:
      gsm.SimpleWriteln(F("AT+CMGL=\"ALL\""));
      break;
  }

  // 5 sec. for initial comm tmout
  // and max. 1500 msec. for inter character timeout
  gsm.RxInit(5000, 1500); 
  // wait response is finished
  do {
    if (gsm.IsStringReceived("OK")) { 
                //Serial.println("STRING RECEIVED OK");
      // perfect - we have some response, but what:

      // there is either NO SMS:
      // <CR><LF>OK<CR><LF>

      // or there is at least 1 SMS
      // +CMGL: <index>,<stat>,<oa/da>,,[,<tooa/toda>,<length>]
      // <CR><LF> <data> <CR><LF>OK<CR><LF>
      status = RX_FINISHED;
      break; // so finish receiving immediately and let's go to 
             // to check response 
    }
    status = gsm.IsRxFinished();
  } while (status == RX_NOT_FINISHED);

  switch (status) {
    case RX_TMOUT_ERR:
      // response was not received in specific time
      ret_val = -2;
      break;

    case RX_FINISHED:
      // something was received but what was received?
      // ---------------------------------------------
      if(gsm.IsStringReceived("+CMGL:")) { 
                  //Serial.println("STRING RECEIVED CMGL");
        // there is some SMS with status => get its position
        // response is:
        // +CMGL: <index>,<stat>,<oa/da>,,[,<tooa/toda>,<length>]
        // <CR><LF> <data> <CR><LF>OK<CR><LF>

                        //JET
                        int pos;

                        char *str;
                        str = (char *)gsm.comm_buf;

                        p_char=strchr(str,':');
                        while (p_char != NULL) {
                                        ret_val = atoi(p_char+1);                                 
                                        pos = p_char-str+1;
                                        if(ret_val!=0 && str[pos+2]==',') break;
                                        p_char=strchr(p_char+1,':');
                        }
                        //END JET
      }
      else {
        // other response like OK or ERROR
        ret_val = 0;
                //Serial.print("other response like OK or ERROR");
      }

      // here we have gsm.WaitResp() just for generation tmout 20msec. in case OK was detected
      // not due to receiving
      gsm.WaitResp(20, 20); 
      break;
  }

  gsm.SetCommLineStatus(CLS_FREE);
  return (ret_val);
}
...

Original comment by gm-jet...@jeth-ro.com on 24 Mar 2013 at 5:04

GoogleCodeExporter commented 9 years ago
Thanks for your help.
Marco

Original comment by martines...@gmail.com on 24 Mar 2013 at 7:31

GoogleCodeExporter commented 9 years ago
This issue section is not longer supported.
Please check the support page www.gsmlib.org 

Original comment by martines...@gmail.com on 6 Jul 2013 at 11:27