Read Sms Messages - DFRobot TEL0097 Manual

Sim808 gps/gprs/gsm shield
Table of Contents

Advertisement

This example tests the DFRobot_SIM808 GPS/GPRS/GSM Shield's call answering and SMS reading function.
1. Open the `SIM808_LoopHandle` example or copy the code to your project
2. Download and set the function switch to `Arduino`
3. The shield will auto­answer phone calls or send SMS Messages to the serial terminal
#include <DFRobot_sim808.h>
#define MESSAGE_LENGTH 20
char gprsBuffer[64];
char *s = NULL;
DFRobot_SIM808 sim808(&Serial);
void setup() {
  //mySerial.begin(9600);
  Serial.begin(9600);
  //******** Initialize sim808 module *************
  while(!sim808.init()) {
      Serial.print("Sim808 init error\r\n");
      delay(1000);
  }
  delay(3000);  
  Serial.println("Init Success, please call or send SMS message to me!");
}
void loop() {
   //******** Wait serial data *************
   if(sim808.readable()){
      sim808_read_buffer(gprsBuffer,32,DEFAULT_TIMEOUT);
      //Serial.print(gprsBuffer);
   //************** Detect the current state of the telephone or SMS ************************
      if(NULL != strstr(gprsBuffer,"RING")) {
          sim808.answer();
      }else if(NULL != (s = strstr(gprsBuffer,"+CMTI: \"SM\""))) { //SMS: $$+CMTI: "SM",24$$
          char message[MESSAGE_LENGTH];
          int messageIndex = atoi(s+12);
          sim808.readSMS(messageIndex, message,MESSAGE_LENGTH);
          Serial.print("Recv Message: ");
          Serial.println(message);
     }
     sim808_clean_buffer(gprsBuffer,32);  
   }
}
Read SMS Messages
This example tests the DFRobot_SIM808 GPS/GPRS/GSM Shield's ability to read SMS messages.
1. Open the `SIM808_SMSread` example or copy the code to your project
2. Download and set the function switch to `Arduino`
3. The shield will receive SMS Messages and send them to the serial terminal

Advertisement

Table of Contents
loading

Table of Contents