2

I'm running UNV SIM808 Shield with Arduino Uno using DFRobot_SIM808. The shield has no issues detecting incoming SMS while powered on. I just found out if the shield is off while sending the SMS, it won't detect it when it becomes online again.

#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>
#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0;
char phone[16];
char datetime[24];
#define PIN_TX 3
#define PIN_RX 2
SoftwareSerial mySerial(PIN_TX,PIN_RX);
DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,
void setup() {
 mySerial.begin(9600);
 Serial.begin(9600);
 //******** Initialize sim808 module *************
 while(!sim808.init()) { Serial.println("Starting Sim808..."); sim808.powerUpDown(9); }
 delay(3000); 
 Serial.println("Init Success, please send SMS message to me!");
}
void loop() {
 //*********** Detecting unread SMS ************************
 messageIndex = sim808.isSMSunread();
 Serial.print("messageIndex: ");
 Serial.println(messageIndex);
 //*********** At least, there is one UNREAD SMS ***********
 if (messageIndex > 0) { 
 sim808.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
 
 //***********In order not to full SIM Memory, is better to delete it**********
 sim808.deleteSMS(messageIndex);
 Serial.print("From number: ");
 Serial.println(phone); 
 Serial.print("Datetime: ");
 Serial.println(datetime); 
 Serial.print("Recieved Message: ");
 Serial.println(message); 
 }
}

I'm sharing the serial monitor data after powering off the shield. I sent a this message (2:24) at 2:24 AM local time. 10 mins later, I powered the shield on and waited for the message to be detected but with no luck for 15 mins. I sent another message (2:49) local time while the shield is on and it was detected right away along with the previous message.

It runs every 3 seconds but I cleaned the data

02:34:56.342 -> Starting Sim808...
02:35:06.958 -> Init Success, please send SMS message to me!
02:35:09.602 -> messageIndex: -1
02:40:00.686 -> messageIndex: 0
02:45:02.311 -> messageIndex: 0
02:49:26.940 -> messageIndex: 0
02:49:29.560 -> messageIndex: 0
02:49:32.216 -> messageIndex: 0
02:49:33.565 -> messageIndex: 7
02:49:36.269 -> From number: +***********
02:49:36.322 -> Datetime: 21/04/21,02:24:20+12
02:49:36.369 -> Recieved Message: 2:24
02:49:37.624 -> messageIndex: 8
02:49:40.373 -> From number: +***********
02:49:40.373 -> Datetime: 21/04/21,02:49:28+12
02:49:40.426 -> Recieved Message: 2:49
02:49:43.029 -> messageIndex: 0
02:49:45.691 -> messageIndex: 0
02:49:48.314 -> messageIndex: 0

Here is code for sim808.isSMSunread(); function. Maybe there is something can be tweaked within the code can mitigate this issue:

char DFRobot_SIM808::isSMSunread(){
 char gprsBuffer[48]; //48 is enough to see +CMGL:
 char *s;
 
 sim808_check_with_cmd("AT+CMGF=1\r\n","OK\r\n",CMD); delay(1000);
 sim808_send_cmd(F("AT+CMGL=\"REC UNREAD\",1\r\n"));
 sim808_clean_buffer(gprsBuffer,31); 
 sim808_read_buffer(gprsBuffer,30,DEFAULT_TIMEOUT); 
 if(NULL != ( s = strstr(gprsBuffer,"OK"))) {
 delay(50);
 return 0;
 } else {
 sim808_wait_for_resp("OK\r\n", CMD); 
 sim808_send_cmd("AT+CMGL=\"REC UNREAD\",1\r\n");
 sim808_clean_buffer(gprsBuffer,48); 
 sim808_read_buffer(gprsBuffer,47,DEFAULT_TIMEOUT);
 if(NULL != ( s = strstr(gprsBuffer,"+CMGL:"))) {
 s = strstr(gprsBuffer,":");
 if (s != NULL) {
 sim808_wait_for_resp("OK\r\n", CMD);
 return atoi(s+1);
 }
 } else {
 return -1; 
 }
 } 
 return -1;
}

What i'm looking for is to make the shield detect any unread messages if it was sent while off?

enter image description here

asked Apr 17, 2021 at 19:57
11
  • you will have to build a time machine Commented Apr 17, 2021 at 21:22
  • sounds like your provider does not store SMS messages and transmits when your device comes online ... test it with your cell phone ... turn off your phone and send SMS to your phone .... then turn on your phone Commented Apr 17, 2021 at 23:19
  • @jsotola Once I put the sim in my phone, I got the SMS immediately. Commented Apr 17, 2021 at 23:34
  • 1
    then you need to learn how the phone retrieves stored messages ... it has nothing to do with the arduino Commented Apr 17, 2021 at 23:43
  • do the sim808 have at commands like in this page developershome.com/sms/readSmsByAtCommands.asp ? Commented Apr 22, 2021 at 22:28

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.