Go Down

Topic: Read an SMS, identify the sender phone number, and answer to the sender (Read 9504 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!

kiliannam

Hi ileto85,
I am having a similar problem withmy project. Were you able to soleve the problem? and if so, would you mind posting  it here?

Thank you :)

ilteo85

Hi! Yes i've solved it! Here is the two function i've used :

Code: [Select]


String CellNumtemp;
String CellNum;


// check if there are incoming SMS
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");
    //save the phone number of the senders in a string (this works with italian region you must adapt to   yours) 
    CellNumtemp = textMessage.substring(textMessage.indexOf("+39"));
    CellNum = CellNumtemp.substring(0,13);
    smsstato();
    CellNumtemp = "";
    textMessage = "";   
  }
  mySerial.print("AT+CMGD=1\r");
  delay(100);
  mySerial.print("AT+CMGD=2\r");
  delay(100);   
}


// Send sms with all the information to the number stored
void smsstato(){
  // delete the first SMS
  mySerial.print("AT+CMGD=1\r");
  delay(100);
  mySerial.print("AT+CMGF=1\r");   
  delay(1000);
  mySerial.print("AT+CMGS=\"");
  mySerial.print(CellNum);
  mySerial.print("\"\r"); 
  delay(1000);
  //The text of the message to be sent.
  mySerial.print("INFO: Latitudine: ");
  mySerial.print(latitude);
  mySerial.print(", Longitudine: ");
  mySerial.print(logitude);
  mySerial.print(", Ampere: ");
  mySerial.print(consumotemp);
  delay(1000);
  mySerial.write(0x1A);
  delay(1000);
  Serial.println("sms stato");
}




I extract the number using 2 string.. that's the only way i was able to solve it.. I think that
there are more efficient ways..
Let me know if you found it useful and if it's all clear 

Absolute_Advance_Automation

Hi! Yes i've solved it! Here is the two function i've used :

Code: [Select]


String CellNumtemp;
String CellNum;


// check if there are incoming SMS
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");
    //save the phone number of the senders in a string (this works with italian region you must adapt to   yours) 
    CellNumtemp = textMessage.substring(textMessage.indexOf("+39"));
    CellNum = CellNumtemp.substring(0,13);
    smsstato();
    CellNumtemp = "";
    textMessage = "";   
  }
  mySerial.print("AT+CMGD=1\r");
  delay(100);
  mySerial.print("AT+CMGD=2\r");
  delay(100);   
}


// Send sms with all the information to the number stored
void smsstato(){
  // delete the first SMS
  mySerial.print("AT+CMGD=1\r");
  delay(100);
  mySerial.print("AT+CMGF=1\r");   
  delay(1000);
  mySerial.print("AT+CMGS=\"");
  mySerial.print(CellNum);
  mySerial.print("\"\r"); 
  delay(1000);
  //The text of the message to be sent.
  mySerial.print("INFO: Latitudine: ");
  mySerial.print(latitude);
  mySerial.print(", Longitudine: ");
  mySerial.print(logitude);
  mySerial.print(", Ampere: ");
  mySerial.print(consumotemp);
  delay(1000);
  mySerial.write(0x1A);
  delay(1000);
  Serial.println("sms stato");
}




I extract the number using 2 string.. that's the only way i was able to solve it.. I think that
there are more efficient ways..
Let me know if you found it useful and if it's all clear 

yeah it's working. thanks

kiliannam

Thank you for the quick response, it worked for me too, Thanks :)

Go Up