Go Down

Topic: serialPrint help (Read 1 time) previous topic - next topic

DMond

Mar 18, 2013, 01:17 pm Last Edit: Mar 18, 2013, 01:26 pm by desmondttm123 Reason: 1
hi, i was wondering if anyone could hep me out with this sketch. This is for a IcomSat Gsm Shield and i want it to light an LED when a specefic SMS is sent. the Serial Print "n" is the SMS that it receives. Is there a way to say like if "n" = "On" then pin 13 high?

Code: [Select]
#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");
 
 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))
   {
     Serial.println(n);
     Serial.println(smsbuffer);
   }
   delay(1000);
 }



I tried doing something like this, but it says "n" is not a function

Code: [Select]
void loop()
{
  if(started){
    //Read if there are messages on SIM card and print them.
    if(gsm.readSMS(smsbuffer, 160, n, 20))
    {
      Serial.println(n);
      Serial.println(smsbuffer);
      if(n("on"));
      {
        digitalWrite(led, HIGH);
    }
    }
    }
    delay(1000);
  }


the error
Code: [Select]
GSM_GPRSLibrary_SMS.ino: In function 'void loop()':
GSM_GPRSLibrary_SMS:56: error: 'smsbuffer' cannot be used as a function



I appreciate your help!! thank you!

PaulS

Quote
the Serial Print "n" is the SMS that it receives.

How do you know that? Are you sure it isn't smsbuffer that contains the data of interest?

Printing stuff without identification is almost worse that not printing anything.

Code: [Select]
Serial.print("n = [");
Serial.print(n);
Serial.println("]");

would convince me that you really know what is in n.

The strcmp() function bears investigation.

DMond

hi and thanks for the reply, i am actually unsure whether it is "n" or smsbuffer, im just making an assumption. so how can i make it behave like an "if ,then " function? thanks

DMond

hi i just checked and it is smsbuffer not n, my mistake

PaulS

Quote
so how can i make it behave like an "if ,then " function?

How can you make what behave like an "if ,then " function?

Did you look at strcmp()?

DMond

hi, im not that familiar with the strcmp() function. ill read about it and let you know how it goes. thanks!

DMond

Hi, i tried this sketch. it didnt come out a compiling error, but i cant get it to work. any suggestions? thanks

Code: [Select]
#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");
 
  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))
    {
      Serial.println(n);
      Serial.println(smsbuffer);
    }
    delay(1000);
  }
}
void Check_Protocol(char inStr[])
{
   Serial.println(smsbuffer);
     if(!strcmp(smsbuffer,"ON")) Serial.println("on");
  if(!strcmp(smsbuffer,"OFF")) Serial.println("off");
}

WizenedEE

Say exactly what you want to happen and exactly what is happening. For example, is "status=READY" being printed to the serial monitor? If not, your code never sets started to true in any other place.

DMond

Hi, what i Expect to happen is that when i send an sms with the text "ON" the serial monitor will display "on" but will not display if it is any other sms. Yes status =Ready is printed.

WizenedEE

You're never calling Check_Protocol

DMond

hi, I dont quite understand, how do i call "check_protocol"?

WizenedEE


hi, I dont quite understand, how do i call "check_protocol"?

The same way you call any function, like delay. You just put Check_Protocol(<arguments>) somewhere in another function. It looks to me like you want it inside the inner if statement in loop() and to give it the argument of smsbuffer.

DMond

Quote
The same way you call any function, like delay. You just put Check_Protocol(<arguments>) somewhere in another function. It looks to me like you want it inside the inner if statement in loop() and to give it the argument of smsbuffer.

hi, i have been trying for days and i cant seem to get it to work...can you give me an example of the code? i am not sure how to use the strcmp as well as the check protocol. thanks

PaulS

Quote
hi, i have been trying for days and i cant seem to get it to work.

Where is your code?

Quote
am not sure how to use the strcmp as well

I'm sure that Mr. Google has something on the order of 22,000,000 examples.

Go Up