Now it has been running for more than 14 hours since SMS was sent.
Now it has been running for more than 14 hours since SMS was sent.
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 offoff while sending the SMS, it won't detect it when it becomes online again.
It runs every 3 seconds but I cleaned the data
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.
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.
It runs every 3 seconds but I cleaned the data
I'm running UNV SIM808 Shield with Arduino Uno using DFRobot_SIM808. The shield has no issues detecting incoming SMS while powered on. Since it is going to be powered by a battery. I want it to run it for 5 mins looking for incoming SMS and respond if found. If not then turn it off for 60 Mins. However, I just found out if the shield is off while sending the SMS, it won't detect it when it becomes online again.
Now it has been running for more than 14 hours since SMS was sent.
What i'm looking for is to make the shield detect any unread messages if it was sent while off?
#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>
#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0;
char MESSAGE[100];
char lat[12];
char lon[12];
long previousMillis = 0;
long interval = 3600000; // 1 hour
char phone[16];
char datetime[24];
#define PIN_TX 3
#define PIN_RX 2
#define Trigger 9
SoftwareSerial mySerial(PIN_TX,PIN_RX);
DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,
void setup(){
digitalWrite(Trigger, LOW);
pinMode(Trigger, OUTPUT); {
mySerial.begin(9600);
Serial.begin(9600);
previousMillis = millis();
}
void loop(){ //******** Initialize sim808 module *************
while(!sim808.init()) { Serial.printprintln("Starting Sim808..."); /*To Power on SIM808 Shield*/
digitalWritesim808.powerUpDown(Trigger, HIGH9); }
delay(10003000); digitalWriteSerial.println(Trigger, LOW);"Init Success, please send SMS message to delay(3000me!");
}
void loop() {
/*To Power on/*********** SIM808Detecting Shield*/unread SMS ************************
}
messageIndex = Serialsim808.printlnisSMSunread("Sim808 initiated Successfully");
delay Serial.print(1000"messageIndex: ");
Serial.println("Please send SMS message to me!"messageIndex);
//*********** At least, messageIndexthere =is sim808.isSMSunread();one UNREAD SMS ***********
if (messageIndex > 0) { { sim808.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
Serial.print("messageIndex: "); //***********In order not to full SIM Memory, is better to delete Serial.println(messageIndex);it**********
sim808.readSMSdeleteSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
Serial.print("From number: "); Serial.println(phone);
Serial.print("Datetime: "); Serial.println(datetime);
Serial.print("Recieved Message: "); Serial.println(message);
if( sim808.attachGPS() ){ Serial.println("Open the GPS power success"message); } else { Serial.println("Open the GPS power failure"); }
while(!sim808.getGPS()){/*Empty Loop*/}
gettime();}
Serial.print("latitude
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.
02:"); 34:56.342 -> Starting SerialSim808.println(sim808.GPSdata.lat);
Serial.print("longitude 02:"); Serial.println(sim808.GPSdata35:06.lon);958 -> Init Success, please send SMS message to Serial.println();me!
02:35:09.602 -> messageIndex: -1
02:40:00.686 -> messageIndex: 0
02:45:02.311 -> messageIndex: float0
02:49:26.940 la-> =messageIndex: sim808.GPSdata0
02:49:29.lat;560 -> messageIndex: 0
02:49:32.216 -> messageIndex: float0
02:49:33.565 lo-> =messageIndex: sim808.GPSdata7
02:49:36.lon;269 -> From number: +***********
02:49:36.322 -> floatDatetime: ws21/04/21,02:24:20+12
02:49:36.369 =-> sim808.GPSdata.speed_kph;
Recieved Message: 2:24
02:49:37.624 -> messageIndex: 8
02:49:40.373 -> From dtostrf(la,number: 6,+***********
02:49:40.373 6,-> lat);Datetime: 21/04/put float value of la into char array of lat21,02:49:28+12
02:49:40. 6 = number of426 digits-> beforeRecieved decimalMessage: sign2:49
02:49:43.029 2-> =messageIndex: number0
02:49:45.691 of-> digitsmessageIndex: after0
02:49:48.314 the-> decimalmessageIndex: sign.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(){
dtostrf(lo, 6,char 6,gprsBuffer[48]; lon); //put48 floatis valueenough ofto losee into+CMGL:
char array of lonchar *s;
sprintfsim808_check_with_cmd(MESSAGE, "Location:\nhttp://maps.google.com/maps?q=%s,%s", lat,lon"AT+CMGF=1\r\n",lat"OK\r\n",lonCMD); delay(1000);
Serial.printlnsim808_send_cmd("SendingF("AT+CMGL=\"REC SMS"UNREAD\",1\r\n"));
Serial.printlnsim808_clean_buffer(MESSAGEgprsBuffer,31); sim808_read_buffer(gprsBuffer,30,DEFAULT_TIMEOUT);
if(NULL != Serial.println(phone); s = strstr(gprsBuffer,"OK"))) {
sim808.sendSMSdelay(phone,MESSAGE50);
if( sim808.deleteSMS() )return 0;
} else {
Serial.printlnsim808_wait_for_resp("Message"OK\r\n", Deleted"CMD); else sim808_send_cmd("AT+CMGL=\"REC UNREAD\",1\r\n");
Serial.println("Could Not Delete Message"sim808_clean_buffer(gprsBuffer,48);
sim808.detachGPS sim808_read_buffer(gprsBuffer,47,DEFAULT_TIMEOUT); //Turning Off GPS
}
if(NULL unsigned!= long( currentMilliss = millisstrstr(gprsBuffer,"+CMGL:");
)) {
if(currentMillis - previousMillis > 300000) { // 5 Mins
s = sim808.powerdownstrstr(gprsBuffer,":"); Serial.println("Module is Powered Off for");
if (s != Serial.print(interval/1000/60NULL); {
Serial.println(" Minutes");
delay(interval);
previousMillis = millis sim808_wait_for_resp("OK\r\n", CMD);
}
delay(1000);
}
void gettime(){
Serial.print(sim808.GPSdata.year); Serial.print("/"); Serial.print(sim808.GPSdata.month); Serial.printreturn atoi("/"s+1);
Serial.print(sim808.GPSdata.day); Serial.print(" "); }
} else {
return Serial.print(sim808.GPSdata.hour);-1; Serial.print(":");
Serial.print(sim808.GPSdata.minute); Serial.print(":"); }
Serial.print(sim808.GPSdata.second); Serial.print(":");}
Serial.println(sim808.GPSdata.centisecond); return -1;
}
What i'm looking for is to make the shield detect any unread messages if it was sent while off?
I'm running UNV SIM808 Shield with Arduino Uno using DFRobot_SIM808. The shield has no issues detecting incoming SMS while powered on. Since it is going to be powered by a battery. I want it to run it for 5 mins looking for incoming SMS and respond if found. If not then turn it off for 60 Mins. However, I just found out if the shield is off while sending the SMS, it won't detect it when it becomes online again.
Now it has been running for more than 14 hours since SMS was sent.
What i'm looking for is to make the shield detect any unread messages if it was sent while off?
#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>
#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0;
char MESSAGE[100];
char lat[12];
char lon[12];
long previousMillis = 0;
long interval = 3600000; // 1 hour
char phone[16];
char datetime[24];
#define PIN_TX 3
#define PIN_RX 2
#define Trigger 9
SoftwareSerial mySerial(PIN_TX,PIN_RX);
DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,
void setup(){
digitalWrite(Trigger, LOW);
pinMode(Trigger, OUTPUT);
mySerial.begin(9600);
Serial.begin(9600);
previousMillis = millis();
}
void loop(){
while(!sim808.init()) { Serial.print("Starting Sim808..."); /*To Power on SIM808 Shield*/
digitalWrite(Trigger, HIGH);
delay(1000); digitalWrite(Trigger, LOW); delay(3000);
/*To Power on SIM808 Shield*/
}
Serial.println("Sim808 initiated Successfully");
delay(1000);
Serial.println("Please send SMS message to me!");
messageIndex = sim808.isSMSunread();
if (messageIndex > 0) { Serial.print("messageIndex: "); Serial.println(messageIndex);
sim808.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
Serial.print("From number: "); Serial.println(phone);
Serial.print("Datetime: "); Serial.println(datetime);
Serial.print("Recieved Message: "); Serial.println(message);
if( sim808.attachGPS() ){ Serial.println("Open the GPS power success"); } else { Serial.println("Open the GPS power failure"); }
while(!sim808.getGPS()){/*Empty Loop*/}
gettime();
Serial.print("latitude :"); Serial.println(sim808.GPSdata.lat);
Serial.print("longitude :"); Serial.println(sim808.GPSdata.lon); Serial.println();
float la = sim808.GPSdata.lat; float lo = sim808.GPSdata.lon; float ws = sim808.GPSdata.speed_kph;
dtostrf(la, 6, 6, lat); //put float value of la into char array of lat. 6 = number of digits before decimal sign. 2 = number of digits after the decimal sign.
dtostrf(lo, 6, 6, lon); //put float value of lo into char array of lon
sprintf(MESSAGE, "Location:\nhttp://maps.google.com/maps?q=%s,%s", lat,lon,lat,lon);
Serial.println("Sending SMS");
Serial.println(MESSAGE);
Serial.println(phone); sim808.sendSMS(phone,MESSAGE);
if( sim808.deleteSMS() )
Serial.println("Message Deleted"); else Serial.println("Could Not Delete Message");
sim808.detachGPS(); //Turning Off GPS
}
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > 300000) { // 5 Mins
sim808.powerdown(); Serial.println("Module is Powered Off for");
Serial.print(interval/1000/60);
Serial.println(" Minutes");
delay(interval);
previousMillis = millis();
}
delay(1000);
}
void gettime(){
Serial.print(sim808.GPSdata.year); Serial.print("/"); Serial.print(sim808.GPSdata.month); Serial.print("/");
Serial.print(sim808.GPSdata.day); Serial.print(" "); Serial.print(sim808.GPSdata.hour); Serial.print(":");
Serial.print(sim808.GPSdata.minute); Serial.print(":");
Serial.print(sim808.GPSdata.second); Serial.print(":");
Serial.println(sim808.GPSdata.centisecond);
}
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.
Now it has been running for more than 14 hours since SMS was sent.
#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.
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?