User Manual
ThisexampleteststheDFRobot_SIM808GPS/GPRS/GSMShield'scallansweringandSMSreadingfunction.
1.Openthe`SIM808_LoopHandle`exampleorcopythecodetoyourproject
2.Downloadandsetthefunctionswitchto`Arduino`
3.TheshieldwillautoanswerphonecallsorsendSMSMessagestotheserialterminal
#include<DFRobot_sim808.h>
#defineMESSAGE_LENGTH20
chargprsBuffer[64];
char*s=NULL;
DFRobot_SIM808sim808(&Serial);
voidsetup(){
//mySerial.begin(9600);
Serial.begin(9600);
//********Initializesim808module*************
while(!sim808.init()){
Serial.print("Sim808initerror\r\n");
delay(1000);
}
delay(3000);
Serial.println("InitSuccess,pleasecallorsendSMSmessagetome!");
}
voidloop(){
//********Waitserialdata*************
if(sim808.readable()){
sim808_read_buffer(gprsBuffer,32,DEFAULT_TIMEOUT);
//Serial.print(gprsBuffer);
//**************DetectthecurrentstateofthetelephoneorSMS************************
if(NULL!=strstr(gprsBuffer,"RING")){
sim808.answer();
}elseif(NULL!=(s=strstr(gprsBuffer,"+CMTI:\"SM\""))){//SMS:$$+CMTI:"SM",24$$
charmessage[MESSAGE_LENGTH];
intmessageIndex=atoi(s+12);
sim808.readSMS(messageIndex,message,MESSAGE_LENGTH);
Serial.print("RecvMessage:");
Serial.println(message);
}
sim808_clean_buffer(gprsBuffer,32);
}
}
ReadSMSMessages
ThisexampleteststheDFRobot_SIM808GPS/GPRS/GSMShield'sabilitytoreadSMSmessages.
1.Openthe`SIM808_SMSread`exampleorcopythecodetoyourproject
2.Downloadandsetthefunctionswitchto`Arduino`
3.TheshieldwillreceiveSMSMessagesandsendthemtotheserialterminal