Go Down

Topic: problem reading string from sms_txt ( gsm shield ) (Read 68 times) previous topic - next topic

fionda08

Hello everyone these days I bought a shield of tinesyne gsm ( http://www.tinyosshop.com/index.php?route=product/product&product_id=464 )
I have a problem in reading the string sms_txt in practice according to the message that I send him , must switch a pin , but this does not happen . I post the code .

Code: [Select]
/*LIBRERIE*/
Ù#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
SMSGSM sms;

/*VARIBILI*/
int led =6;
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
char sms_position;
char phone_number[20]; // array for the phone number string
char sms_text[300];
int i;



void setup()
{
    //Serial connection.
    Serial.begin(9600);
    Serial.println(" GSM Shield testing.");
    pinMode(led,OUTPUT);
   if (gsm.begin(4800))
    {
        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");
       
       //if NO SPACE ,you need delte SMS  from position 1 to position 20
       //please enable this four lines
       for(i=1;i<=20;i++)
       {
           sms.DeleteSMS(i);
       }
   
   
};

void loop()
{
 

  if(started)
    {
        //Read if there are messages on SIM card and print them.
        sms_position=sms.IsSMSPresent(SMS_UNREAD);
        if (sms_position)
        {
            // read new SMS
            Serial.print("SMS postion:");
            Serial.println(sms_position,DEC);
            sms.GetSMS(sms_position, phone_number, sms_text, 100);
            // now we have phone number string in phone_num
             if(sms_text=="ON"){
               digitalWrite(led,HIGH);
             }
             
             if (sms_text=="OFF"){
               digitalWrite(led,LOW);
             }
             
            Serial.println(phone_number);
            // and SMS text in sms_text
            Serial.println(sms_text);
        }   
    }
};
Fionda08

PaulS

Code: [Select]
             if(sms_text=="ON"){
sms_text is an array. You are comparing the address of the first element in the array to "ON". If is extremely unlikely that they will ever be equal.

That is NOT how to compare strings. strcmp() is.

Go Up