Go Down

Topic: Read an SMS, identify the sender phone number, and answer to the sender (Read 327 times) previous topic - next topic

ilteo85

Hi, i'm using arduino and SIM808 V3.2 for a project.
I ve already write the sketch for chek recived SMS and if it is a word that i choose ("STATO")
send an SMS.

I would like that the answer will be send not to a pre established number.
I wish to read the senders number and answer him.
Is it possible? How?

Here is my code right now

Code: [Select]


#include <SoftwareSerial.h>

// Configure software serial port
SoftwareSerial mySerial(10, 11);

// Variable to store text message
String textMessage;


void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("Serial begin ok");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("AT");
}

void loop(){
  ricezione();
  delay(2000);


void ricezione(){
  Serial.println ("controllo ricezione SMS");
  // AT command to set mySerial to SMS mode
  mySerial.print("AT+CMGF=1\r");
  delay(100);
  // Read the first SMS saved in the sim
  mySerial.print("AT+CMGR=1\r");
  delay(10); 
  if(mySerial.available()>0){
    textMessage = mySerial.readString();
    Serial.print(textMessage);   
    delay(10);
  }
  // check if the SMS is "STATO"
  if(textMessage.indexOf("STATO")>=0){   
    Serial.println("Invio info stato arnia");
    smsstato();
    textMessage = "";   
  }
}


void smsstato(){
  // delete the first SMS
  mySerial.print("AT+CMGD=1\r");
  delay(100);
  mySerial.print("AT+CMGF=1\r");   
  delay(1000);
  /i wish that phone number change with the phone number of the sender of SMS
  mySerial.print("AT+CMGS=\"+39348395xxxx\"\r");     
  delay(1000);
  //The text of the message to be sent.
  mySerial.print("prova invio sms: "); 
  delay(1000);
  mySerial.write(0x1A);
  delay(1000); 
}



Thank you very much!

Go Up