Go Down

Topic: SIM808 FAILS TO read SMS data. (Read 553 times) previous topic - next topic

giulianoc75


Good afternoon, I posted this same problem in the Spanish forum, but no one could solve it (Sorry for my bad English). I would like to know if anyone can give me any recommendation on how to proceed. I am trying to read the data through the serial port of a SIM808 with my Arduino Due. The problem is that when I send the SMS "# 0213", it shows me in the serial monitor "Clave obtenida :????". That gives me to understand, that in the Serial port it only reads question marks. Do you know any way to solve it? thanks

Code: [Select]
Code: [Select]


int i;;
char clave1;
char clave2;
char clave3;
char clave4;
volatile int PulsoPotencia= 900;
String clave = "";

void setup() {
  Serial.begin(19200);
  Serial1.begin(19200);
  delay(10000);
  Serial1.write("AT+IPR=19200\r");
  Serial1.write('\n');
  delay(100);
  RX();
  Serial1.write("AT+CMGF=1\r");
  Serial1.write('\n');
  delay(100);
  RX();
  Serial1.write("AT+CNMI=2,2,0,0,0\r");
  Serial1.write('\n');
  delay(100);
  RX();
  Serial1.write("AT+CGREG?\r");
  Serial1.write('\n');
  delay(100);
  RX();
  Serial1.write("AT+CSQ\r");
  Serial1.write('\n');
  delay(100);
  RX();
  Serial.println("Setup Listo");
}

void loop() {
  RX();
   if(Serial1.read()=='#'){
     clave1=Serial1.read();
     clave2=Serial1.read();
     clave3=Serial1.read();
     clave4=Serial1.read();
     clave += clave1;
     clave += clave2;
     clave += clave3;
     clave += clave4;
     Serial.println("clave obtenida: " + PulsoPotencia);
    }
}

void RX() {
  i=0;
  while(i<150){
  if (Serial1.available() > 0){Serial.write(Serial1.read());}
  if (Serial.available() > 0){Serial1.write(Serial.read());}
  i++;
  }
}





In case you're wondering, I use the void RX () to read the serial port, and inside it has a while loop. that was the only way I found to solve the following problem . I don't know if it's because before I used an Arduino UNO (8-bit), and now a due that is 32-bit. But when wanting to read the incoming through the Serial port, absolutely nothing was presented. When I sent him the AT commands he looked dead, because nothing was showing on the Serial Monitor. By adding a while loop I managed to give it more time to read the Serial port, and thus solve it.

Go Up