Pages: [1]   Go Down
Author Topic: strcmp() function and led on off problem with sim900  (Read 1125 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello friends

i am trying to control the LED pin13 by using sim 900
so i first tried it to control LED by serial consol and its working fine i.e if i am sending "ON" led is turning on and for "OFF" via serial consol so  everything is fine
now i want to control the same via sms using SIM900 so whenever i am sending sms ON the 13 number LED shoul be ON and viceversa

i am using sim900 gsm library and try to do it but its  not working  i have modified the code and the code is compiling but led is not glowing when i send on or off
what is the problem in this code??


Code:
#include "SIM900.h"
#include <SoftwareSerial.h>
//If not used, is better to exclude the HTTP library,
//for RAM saving.
//If your sketch reboots itself proprably you have finished,
//your memory available.
//#include "inetGSM.h"

//If you want to use the Arduino functions to manage SMS, uncomment the lines below.
#include "sms.h"
SMSGSM sms;

//To change pins for Software Serial, use the two lines in GSM.cpp.

//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.

//Simple sketch to send and receive SMS.

int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];

void setup()
{
  //Serial connection.
  Serial.begin(9600);
  Serial.println("GSM Shield testing.");
  //Start configuration of shield with baudrate.
  //For http uses is raccomanded to use 4800 or slower.
  if (gsm.begin(2400)){
    Serial.println("\nstatus=READY");
    started=true;  
  }
  else Serial.println("\nstatus=IDLE");
pinMode( 13, OUTPUT );
  
  if(started){
    //Enable this two lines if you want to send an SMS.
    //if (sms.SendSMS("3471234567", "Arduino SMS"))
    //Serial.println("\nSMS sent OK");
  }

};

void loop()

{


  if(started){
    //Read if there are messages on SIM card and print them.
    if(gsm.readSMS(smsbuffer, 160, n, 20))//n=array for the sender's number  //smsBuffer=array for the sender's message
    {
            Serial.println(smsbuffer);
      
      Serial.println(n);
      char inSerial[5];  
  int i=0;
  delay(1000);
  
  if (Serial.available() > 0)
  {            
       while (Serial.available() > 0) {
         inSerial[i]=Serial.read(); //read data  
         i++;      
       }
       inSerial[i]='\0';
      Check_Protocol(inSerial);}
    }
  }
}

void Check_Protocol(char inStr[])
{  
  Serial.print("Command: ");
  Serial.println(inStr);
      
  Serial.println("Check_Protocol");
  if(!strcmp(inStr,"ON")) digitalWrite(13,HIGH);
  if(!strcmp(inStr,"OFF")) digitalWrite(13,LOW);
}


Logged

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

If, instead of just printing raw bits of data to the serial monitor, you actually identified what that data was, I think you'd see what the problem is.

Instead of
Code:
            Serial.println(smsbuffer);
Use
Code:
            Serial.print("smsbuffer: [";
            Serial.print(smsbuffer);
            Serial.println("]");

That way, you know where the data is stored on the Arduino.

Then, look at where you actually use the data from the text message. Nowhere, that is.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
Serial.print("smsbuffer: [";
            Serial.print(smsbuffer);
            Serial.println("]");

i tried this but not able to even print on or off
i am very confused!!!!!!!!!!!!!!!!!!!!!
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 109
Posts: 4076
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you get any output to the serial monitor when you printed smsbuffer as suggested ?  If so, what was it ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it is printing like this for on but for off strangely its not printing anything!!!! smiley-surprise

this is what my serial moniter say when i send on but nothing is happenging

thanks for your intrest in my post
what should be the problem???

GSM Shield testing.

status=READY
smsbuffer: [on
]
+91xxxxxxxxxxx
 
« Last Edit: April 20, 2013, 11:34:38 pm by chintan123 » Logged

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

Quote
it is printing like this for on but for off strangely its not printing anything!!!!
OK.... Then,,,, you have three problems....

One, you are not getting correct data in smsbuffer in all cases. That could be a library problem (unlikely) or some network issue or something outside the Arduino.

Two, you have smsbuffer that sometimes contains correct data. Now, look at your code, and see where you USE smsbuffer after you print it. Nowhere. Does that seem right? Not to me. Do you now know what you need to do?

Third, your ! key is sticking, and your shift key is not working. I'd suggest that you get your keyboard cleaned.
Logged

Pages: [1]   Go Up
Jump to: