SMS problems

Hi again

iv got it to work but not realy.....

ill explain my build:

Uno and SensorShield
and a GSM board.

and some sensors and servos

when i send "Test"

it reply with the temp... from DHT11

but som how the "Test" gets lost or is broken somehow

Here is the code:

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "DHT.h"
#include "sms.h"
#include <Servo.h> 
SMSGSM sms;

boolean started=false;

char smsbuffer[160];
char n[20];
char txt[160];

String d;
String textForSMS;

int numdata;
int resetPin = 8;
int ledPin1 = 13;
int fanPwr = 11;
int servPin1 = 9;
int servPin2 = 10;

int rpm = 0;
int pos1 = 90;
int pos2 = 90;
int fanPin = 0;

#define DHTPIN 12
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

Servo myservo1;  // create servo object to control a servo 
Servo myservo2;  // a maximum of eight servo objects can be created 


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("4040xxxx", "Arduino SMS booted up"))
          //Serial.println("\nArduino SMS booted up");
     }
  
      pinMode(ledPin1,OUTPUT);
      pinMode(servPin1,OUTPUT);
      pinMode(servPin2,OUTPUT);
      pinMode(resetPin,OUTPUT);
      pinMode(fanPwr,OUTPUT);
      
      // Servo Setup
          myservo1.attach(servPin1);  // attaches the servo on pin 9 to the servo object 
          myservo2.attach(servPin2);
          myservo1.write(pos1);
          myservo1.write(pos2);
        
  
};

void loop()
{
     delay(2000);
     rpm = analogRead(fanPin);
     float h = dht.readHumidity();
     float t = dht.readTemperature();
     if (isnan(h) || isnan(t)) 
      {
        Serial.println("Failed to read from DHT sensor!");
        return;
      }
      if (t > 26) 
      {
        analogWrite(fanPwr, 200);
      }
      else 
      {
        analogWrite(fanPwr, 0);
      }
     Serial.print("Fugtighed : ");
     Serial.print(h);
     Serial.print("%   ");
     Serial.print("Temp : ");
     Serial.print(t);
     Serial.print("ºC  "); 
     Serial.print("RPM : ");
     Serial.print(rpm);
     Serial.println("rpm"); 
     
     // SMS Text
      textForSMS = "Humidity : ";
      textForSMS.concat(h);
      textForSMS = textForSMS + "% Temp : ";
      textForSMS.concat(t);
      textForSMS = textForSMS + "ºC";  
     
     //SMS Respond     
     if(started) {
          //Read if there are messages on SIM card and print them.
          if(gsm.readSMS(smsbuffer, 160, n, 20)) {
               d = smsbuffer;
               Serial.print(n);
               Serial.print(" Sendt this message : ");
               Serial.println(d);
                if (d == "Temp ")
                  {
                   textForSMS.toCharArray(txt, 160);
                   sms.SendSMS(n, txt);
                   Serial.println(d);
                   Serial.print("SMS Sendt to : ");
                   Serial.println(n);
                  }
                else if (d == "Led on")
                  {
                    Serial.print(d);
                    Serial.println("LED ON");
                    analogWrite(ledPin1, 150);
                  }
                else if (d == "Left")
                  {
                    servLeft;
                    Serial.print("Turning Left : ");
                    Serial.print(pos1);
                  }
                else if (d == "Right")
                  {
                  Serial.println("Turning Right");
                    servRight;
                  }
                else if (d == "Up")
                  {
                  Serial.println("Moving up");
                    servUp;
                  }
                else if (d == "Down")
                  {
                  Serial.println("Moving down");
                    servDown;
                  }
                else if (d == "ServoReset")
                  {
                    pos1 = 90;
                    pos2 = 90;
                  Serial.println("Servo Reset");
                    servReset;
                  }
                else
                 {
                  Serial.println("Nothing to repport");
                 }
                  
             }
     }
};
void servLeft()
{
  for(pos1 = 30; pos1 < 190; pos1 += 1)  // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo1.write(pos1);              // tell servo to go to position in variable 'pos' 
    delay(5);                       // waits 15ms for the servo to reach the position 
  }
}
void servRight()
{
  for(pos1 = 190; pos1>=30; pos1-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo1.write(pos1);              // tell servo to go to position in variable 'pos' 
    delay(5);
  }
}
void servUp()
{
  for(pos2 = 190; pos2>=30; pos2-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo2.write(pos2);              // tell servo to go to position in variable 'pos' 
    delay(5);
  }
}
void servDown()
{
  for(pos2 = 190; pos2>=30; pos2-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo2.write(pos2);              // tell servo to go to position in variable 'pos' 
    delay(5);
  }
}
void servReset()
{
  myservo1.write(pos1);              // tell servo to go to position in variable 'pos' 
  myservo2.write(pos2);              // tell servo to go to position in variable 'pos' 
  delay(5);
}
char smsbuffer[160];
char n[20];
char txt[160];

Those buffers seem overly large to hold "Test".

String d;
String textForSMS;

You do not need to piss away resources using Strings.

};

Only struct and class bodies need a ; after the }. Functions and if/for/while statement bodies do not.

                   textForSMS.toCharArray(txt, 160);

That SAME data is in smsbuffer. There is no need to wrap it in a String instance and then unwrap it into another array.

                if (d == "Temp ")

Do you really send a space after "Temp"?

                    servLeft;

What is this supposed to do?

  for(pos1 = 30; pos1 < 190; pos1 += 1)  // goes from 0 degrees to 180 degrees

It most certainly does not.

but som how the "Test" gets lost or is broken somehow

Print the actual text message between delimiters:

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

Does the text message contain a space, when you send Test?

but som how the "Test" gets lost or is broken somehow

Can you explain in more detail what goes wrong?

Nowhere in your code I can find where you send / receive the word 'Test'.

well
reason for the big buffers is :
sms's can hold up to 160 char
n = number can be up to 20 numbers

ok Test should be Temp

and when o type on my phone it put a space after the word , why i dont know.

i know my code is messy... im new to this and im learning as i go.

got this respond from SerialMonitor

ATT: +CMGL
RIC:
+CMGL: 1,"REC UNREAD","+454040xxxx","","15/12/09,22:19:15+04"
Temp

OK

ATT: OK
RIC:
OK

+454040xxxx Sendt this message : smsbuffer: [Temp]
Nothing to repport
Fugtighed : 39.00% Temp : 19.00ºC RPM : 249rpm
ATT: +CMGL
RIC:
OK

textForSMS.toCharArray(txt, 160);

this is the respond text and has nothing to doo with the smsbuffer

// SMS Text
      textForSMS = "Humidity : ";
      textForSMS.concat(h);
      textForSMS = textForSMS + "% Temp : ";
      textForSMS.concat(t);
      textForSMS = textForSMS + "ºC";

this is making this sms tekst : Humidity : xx.xx% Temp : xx.xxºC

and when o type on my phone it put a space after the word , why i dont know.

smsbuffer: [Temp]

I do NOT see a space after Temp.

well what i need help with is why it dont react when it get the right text... where it goes wrong i dont know

but i know that is in this part:

if(gsm.readSMS(smsbuffer, 160, n, 20)) {               // checking for SMS if status is ready
               Serial.print(n);                                       // printing the number if there is a sms
               Serial.print(" Sendt this message : [");    // Printing the message
               Serial.print(smsbuffer);                          //
               Serial.println("]");                                 //
                if (smsbuffer == "Temp")                      // if there is a message with Temp 
                  {                                                       // send a message return to the Number 
                   textForSMS.toCharArray(txt, 40);       // converting a string to a char 
                   sms.SendSMS(n, txt);                       // sending the sms  
                   Serial.print("SMS Sendt to : ");
                   Serial.println(n);
                  }
                else if (smsbuffer == "Led on")
                  {
                    Serial.print(smsbuffer);
                    Serial.println("LED ON");
                    analogWrite(ledPin1, 150);
                  }
                else if (smsbuffer == "Left")
                  {
                    servLeft;
                    Serial.print("Turning Left : ");
                    Serial.print(pos1);
                  }
                else if (smsbuffer == "Right")
                  {
                  Serial.println("Turning Right");
                    servRight;
                  }
                else if (smsbuffer == "Up")
                  {
                  Serial.println("Moving up");
                    servUp;
                  }
                else if (smsbuffer == "Down")
                  {
                  Serial.println("Moving down");
                    servDown;
                  }
                else if (smsbuffer == "ServoReset")
                  {
                    pos1 = 90;
                    pos2 = 90;
                  Serial.println("Servo Reset");
                    servReset;
                  }
                else Serial.println("Nothing to repport");
              }
                if (smsbuffer == "Temp")                      // if there is a message with Temp
                  {                                                       // send a message return to the Number
                   textForSMS.toCharArray(txt, 40);       // converting a string to a char

smsbuffer is a character array. The address of the array is not likely to be the same as the address of "Temp".

Use strcmp() to compare strings.

thx ill try that

ok i got it to work with this

if (strncmp(smsbuffer,"Temp", 4) == 0)

thx for your input it helped me a lot

here is the code

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "DHT.h"
#include "sms.h"
#include <Servo.h> 
SMSGSM sms;

boolean started=false;

char smsbuffer[160];
char n[12];
char txt[40];


String textForSMS;

int numdata;
int resetPin = 8;
int ledPin1 = 13;
int fanPwr = 11;
int servPin1 = 9;
int servPin2 = 10;

int rpm = 0;
int pos1 = 90;
int pos2 = 90;
int fanPin = 0;

#define DHTPIN 12
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

Servo myservo1;  // create servo object to control a servo 
Servo myservo2;  // a maximum of eight servo objects can be created 


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("4040xxxx", "Arduino SMS booted up"))
          //Serial.println("\nArduino SMS booted up");
     }
  
      pinMode(ledPin1,OUTPUT);
      pinMode(servPin1,OUTPUT);
      pinMode(servPin2,OUTPUT);
      pinMode(resetPin,OUTPUT);
      pinMode(fanPwr,OUTPUT);
      
      // Servo Setup
          myservo1.attach(servPin1);  // attaches the servo to the servo object 
          myservo2.attach(servPin2);
          myservo1.write(pos1);
          myservo1.write(pos2);
}

void loop()
{
     delay(2000);
     rpm = analogRead(fanPin);
     float h = dht.readHumidity();
     float t = dht.readTemperature();
     if (isnan(h) || isnan(t)) 
      {
        Serial.println("Failed to read from DHT sensor!");
        return;
      }
      if (t > 26) 
      {
        analogWrite(fanPwr, 200);
      }
      else 
      {
        analogWrite(fanPwr, 0);
      }
     Serial.print("Fugtighed : ");
     Serial.print(h);
     Serial.print("%   ");
     Serial.print("Temp : ");
     Serial.print(t);
     Serial.print("ºC  "); 
     Serial.print("RPM : ");
     Serial.print(rpm);
     Serial.println("rpm"); 
     
     // SMS Text
      textForSMS = "Humidity : ";
      textForSMS.concat(h);
      textForSMS = textForSMS + "% Temp : ";
      textForSMS.concat(t);
      textForSMS = textForSMS + "ºC";  
     
     //SMS Respond     
     if(started) {
          //Read if there are messages on SIM card and print them.
          if(gsm.readSMS(smsbuffer, 160, n, 20)) {
               Serial.print(n);
               Serial.print(" Sendt this message : [");
               Serial.print(smsbuffer);
               Serial.println("]");
               char Temp[160]="Temp";
               //Serial.println(SMSBuffer.compare(std::string("TEMP")) == 0);
                if (strncmp(smsbuffer,"Temp", 4) == 0)
                  {
                   textForSMS.toCharArray(txt, 40);
                   sms.SendSMS(n, txt);
                   Serial.println(smsbuffer);
                   Serial.print("SMS Sendt to : ");
                   Serial.println(n);
                  }
                else if (strncmp(smsbuffer,"Led on", 6) == 0)
                  {
                    Serial.print(smsbuffer);
                    Serial.println("LED ON");
                    analogWrite(ledPin1, 150);
                  }
                else if (strncmp(smsbuffer,"Turn left", 9) == 0)
                  {
                    servLeft;
                    Serial.print("Turning Left : ");
                    Serial.print(pos1);
                  }
                else if (strncmp(smsbuffer,"Turn right", 10) == 0)
                  {
                  Serial.println("Turning Right");
                    servRight;
                  }
                else if (strncmp(smsbuffer,"Move up", 7) == 0)
                  {
                  Serial.println("Moving up");
                    servUp;
                  }
                else if (strncmp(smsbuffer,"Move down", 9) == 0)
                  {
                  Serial.println("Moving down");
                    servDown;
                  }
                else if (strncmp(smsbuffer,"Servo reset", 11) == 0)
                  {
                    pos1 = 90;
                    pos2 = 90;
                  Serial.println("Servo Reset");
                    servReset;
                  }
                else Serial.println("Nothing to repport");
              }
     }
}
void servLeft()
{
  for(pos1 = 30; pos1 < 190; pos1 += 1)  // goes from 30 degrees to 180 degrees 
  {                                      // in steps of 1 degree 
    myservo1.write(pos1);                // tell servo to go to position in variable 'pos' 
    delay(5);                            // waits 15ms for the servo to reach the position 
  }
}
void servRight()
{
  for(pos1 = 190; pos1>=30; pos1-=1)     // goes from 180 degrees to 30 degrees 
  {                                
    myservo1.write(pos1);                // tell servo to go to position in variable 'pos' 
    delay(5);
  }
}
void servUp()
{
  for(pos2 = 190; pos2>=30; pos2-=1)     // goes from 180 degrees to 30 degrees 
  {                                
    myservo2.write(pos2);                // tell servo to go to position in variable 'pos' 
    delay(5);
  }
}
void servDown()
{
  for(pos2 = 30; pos2 < 190; pos2 += 1)  // goes from 30 degrees to 180 degrees 
  {                                      // in steps of 1 degree 
    myservo2.write(pos2);                // tell servo to go to position in variable 'pos' 
    delay(5);
  }
}
void servReset()
{
  myservo1.write(pos1);                  // tell servo to go to position in variable 'pos' 
  myservo2.write(pos2);                  // tell servo to go to position in variable 'pos' 
  delay(5);
}