Go Down

Topic: reading sms (Read 8 times) previous topic - next topic

kevin-se

not working,on the serial monitor AT commands seems to stop after the
first check
AT+CMGF=1
AT+CMGR
AT+CMGD=1,4
Stops after ist check,before kept on checking

Code: [Select]
int led = 13;
int onModulePin = 9;        // the pin to switch on the module (without press on button)

int timesToSend = 1;        // Numbers of SMS to send
int count = 0;

int n_sms,x,sms_start;
char data[256];

void switchModule(){
  digitalWrite(onModulePin,HIGH);
  delay(2000);
  digitalWrite(onModulePin,LOW);
}

void setup(){

  Serial.begin(19200);                // UART baud rate
  delay(2000);
  pinMode(led, OUTPUT);
  pinMode(onModulePin, OUTPUT);
  switchModule();                    // switches the module ON

  for (int i=0;i < 5;i++){
    delay(5000);
  }

  Serial.println("AT+CMGF=1");         // sets the SMS mode to text

  delay(1000);
}

void loop(){


  Serial.println("AT+CMGR");    //Reads the first SMS
  Serial.println("AT+CMGD=1,4");


  Serial.flush();
  for (x=0;x < 255;x++){           
    data[x]='\0';                       
  }
  x=0;
  do{
    while(Serial.available()==0);
    data[x]=Serial.read(); 
    x++;           
    if(data[x-1]==0x0D&&data[x-2]=='"'){
      x=0;
    }
  }
  while(!(data[x-1]=='K'&&data[x-2]=='O'));

  data[x-3]='\0';        //finish the string before the OK
  Serial.print("data: [");
  Serial.print(data);    //shows the message
  Serial.println("]");
  if(strcmp(data, "on") == 0)
  {
    Serial.println("Turning LED on");
    digitalWrite(led,HIGH);
  }
  if(strcmp(data, "off") == 0)
  {
    Serial.println("Turning LED off");
    digitalWrite(led,LOW); // Turn the pin off



  }   
}     


kevin-se

after adding parts to the sketch,the serial output looks like this,
with the original sketch it used to continuously check but now it seems
to stop after a few checks,


Code: [Select]
+CFUN: 1

+CPIN: READY

Call Ready
AT+CMGF=1
AT+CMGL
AT+CMGD=1,4

]
AT+CMGL
AT+CMGD=1,4

]
AT+CMGL
AT+CMGD=1,4

PaulS

Quote
after adding parts to the sketch,

"I changed my code, but I'm not going to show it to you." Did I paraphrase that correctly?

kevin-se

when i send sms's it works perfectly,but i have problems reading sms's and activating outputs,for some reason the loop in the sketch stops after the first check when ever i try to read the serial data,

PaulS

Quote
when i send sms's it works perfectly,but i have problems reading sms's and activating outputs,for some reason the loop in the sketch stops after the first check when ever i try to read the serial data,

And, yet, still no code.

Go Up