Pages: 1 [2] 3 4 5   Go Down
Author Topic: reading sms  (Read 7848 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    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?
Logged

South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry,i was a bit excited ,
Code:
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
   
   
 }   
}     
   
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Change some of your code to look like this:
Code:
        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.
Logged

South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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



  }   
}     
Logged

South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
+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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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,
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

after hours of trying,i deleted some code and ended up with this,it seems to continuously check for new sms's but when i send the shield an sms it does not show up on the serial monitor and does not switch led on,maybe my delete command wrong;

Code:
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


  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");




  while(Serial.available()==0);

  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



  }   
}     
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
maybe my delete command wrong;
One can help with coding without understanding which AT command does what. You should have functions that send exactly one AT command. The name of the function should clearly reflect what the AT command being sent does.

If
Code:
  Serial.println("AT+CMGR");    //Reads the first SMS
reads the message, and
Code:
  Serial.println("AT+CMGD=1,4");
deletes it, then, yes, you have a problem with the delete command.

data no longer gets a value, because you no longer actually read anything. So, the fact that sending the Arduino a SMS causes nothing to happen is not really surprising.
Logged

South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok will modify
Logged

South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 33
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok,left out the AT command for deleting sms's,the AT+CMGR=1 reads incoming sms's but nothings displayed on the serial monitor and no switching occurs,the AT+CMGR command keeps looping on serial monitor but not reading the new sms's
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"OK, I made some more code changes that I'm not going to show you..." Haven't we been down this path before?

We can NOT see what you are doing.

We've hired a psychic, but he's not due to start until the 12th of never. Until then, you have to help out.
Logged

Pages: 1 [2] 3 4 5   Go Up
Jump to: