IOT-MCU / ESP-12S-A9-A9G-GPRS-Node-v1.0

63 stars 27 forks source link

Hold SMSs ? #12

Open eried opened 4 years ago

eried commented 4 years ago

Hello, is there a way to hold the SMS messages so they do not pop when received? (i.e. I am waiting for some HTTP POST, and in the middle there is an SMS received so it gets outputed in the middle)

apeman76 commented 3 years ago

Yes, use this code:

String dump(bool printData) {
  byte while_cunt = 0;
  while (swSer.available() == 0){
    while_cunt++;
    delay(15); // It can change for a proper delay
    if(while_cunt >=250){  // If the data from serial was not received past 3.75 seconds
      Serial.println("return");
      return "";   // Exit from dump function
    }
  }
  String content = "";
  while (swSer.available() > 0) {
    content += swSer.readString();
  }

  if (printData) {
    Serial.println(content);
  }
  return content;
}
  swSer.println("AT+CPMS=\"SM\",\"SM\",\"SM\"");
  delay(1000);
  swSer.println("AT+CMGR=1");
  delay(1000);
  String str =  dump(true);

str now holds the answer of the command

eried commented 3 years ago

But what if you get an sms while reading that? It will get included too

apeman76 commented 3 years ago

Ah, I misunderstood your question. AT+CNMI=2,0,0,0,0 Try just this, forget the other code.

//edit hmm I see the 2nd 0 is default: https://www.logicbus.com.mx/pdf/31/Comandos_AT_generales.pdf Maybe disabling serial read while waiting for that post and enabling it after receiving the post is the best idea