Go Down

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

PaulS

Code: [Select]
    if(strcmp(data, "on") == 0)
{
  digitalWrite(led,HIGH);
}
if(strcmp(data, "off") == 0)
{
   digitalWrite(led,LOW); // Turn the pin off
   
    Serial.println("AT+CMGD=1,4");
}   

What is up
                            with the random
        indenting? Use Tools +
   Auto Format
                 to get the code looking reasonable.

Why is that AT command sent only when the light is to be turned off?

Why is there a 5 second delay after receiving on or off before you do it?

kevin-se

sorry,i was a bit excited ,
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.println(data);    //shows the message
                   
        if(strcmp(data, "on") == 0)
        {
         digitalWrite(led,HIGH);
        }
       if(strcmp(data, "off") == 0)
        {
         digitalWrite(led,LOW); // Turn the pin off
   
   
}   
}     
   

PaulS

You're the one with the hardware. Does it work?

kevin-se

not working ,sent sms on to shield,led pin 13 on uno  does not light ,

PaulS

Change some of your code to look like this:
Code: [Select]
        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
        }   

Show us the serial output.

Go Up