Send SMS with variables..

Hi, this is my firt time here in the forum, i'm havin' some troubles with this code:

SIM900.println("AT+CMGS=\"+xxxxxxxxxxxx\"");

this one works really fine..but the problem cames when i try to send a variable instead of the number:

SIM900.println("AT+CMGS=\"" + Tel_sender + "\"");

Tel_sender is a variable i get doing this (when i receive an sms):

int pos = message.indexOf("+CMT: ");
    Tel_sender = message.substring(pos+7,pos+20);

with the code above i get the number sender and store it in the variable Tel_sender...

(i'm not sure about if it is a char or String or whatever...maybe this is a problem too)

then with the rest of the code i try to send it but no luck..

this is the monitor print:

+CMT: "+XXxxxxxxxxx8","","19/02/07,10:58:23-12"
Er1
SMS sent

AT+CMGF=1
AT+CMGS="+XXxxxxxxxxx8"

OK

but nothing happend in my phone..

Before anything you should verify the content of your 'message' variable. Then concerning the type of 'Tel_sender': it should appear somewhere in your code. Search for somethinf like 'String Tel_sender' or 'char * Tel_sender'.

But if your code compiles correctly, then this line

Tel_sender = message.substring(pos+7,pos+20);

tends to say that 'Tel_sender' is a String.

About the monitor print, it is useless for us as long as we don't know the code lines that make this monitor print... So show your code if want more help.

Hi lesept thanks for the help...yes it is a String..

i tried to use .c_str() and also toCharArray but nothing happend..no message sent

if (Tel_sender == param.Admin and Password == param.Pass)
  {
        Serial.println(Tel_sender );
        Serial.println(Password);
        digitalWrite( LED, LOW) ;
        Serial.println("\nLED 1 On.");
        SIM900.print("AT+CMGF=1\r");
        SIM900.write(("AT+CMGS=\"" + Tel_sender + "\"").c_str());
        SIM900.println("LED 1 On..");  // Text  SMS
        delay(100);
        SIM900.println((char)26);
        SIM900.println();
        delay(5000);
        Serial.println("\nSMS sent");
        message = ""; empty for next  time
  }

param.Admin and param.Pass are variables i have in a struct:

struct {
  char Admin[15];
  char User1[15];
  char User2[15];
  char User3[15];
  char Pass[5];
}param;

this is how i get the variable Tel_sender:

void Sender_SMS(){ 
  if (message== ""){
  //nothing
  }
  else {
    int pos = message.indexOf("+CMT: ");
    Tel_sender= message.substring(pos+7,pos+20);
  }
}

and this is message variable:

message = message + incoming_char ;

this is all so far...i hope you can give me an idea of what i'm doin' wrong or what i've to change..thanks again..

if "+XXxxxxxxxxx8" matches your Tel_sender then it should be ok.

I think there are somethings-garbage from String - substring. Try to print to monitor the ascii numbers of your message.substring to see if it contains any "non printable" characters at the end

if (Tel_sender == param.Admin and Password == param.Pass)

if Tel_sender is a String and param.Admin is a char array, maybe this comparison doesn't work? I've never tried that actually.

Do you see the led extinction due to this line?

digitalWrite( LED, LOW) ;

Hi demkat1, sory i don't follow you, how can i do that?

what i was trying is to convert it to char with:

message.toCharArray(CMessage,message.length());

but i don' know how to do what you said..

actually it does work, perfectly...i also use it with te calls to compare the stored numbers with the

Tel_sender and works just great..

and with:

digitalWrite( LED, LOW) ;

yes the led works great, i even turn it off also,..

i work with 2 phones (2 dif. numbers) and if i do this:

if (Tel_sender == param.Admin or Tel_sender == param.User1){

the admin numbrer and user number both turn the led on...

and like this:

if (Tel_sender == param.Admin){

Admin turns it on, but user1 can't anymore...

demkat1: if "+XXxxxxxxxxx8" matches your Tel_sender then it should be ok.

I think there are somethings-garbage from String - substring. Try to print to monitor the ascii numbers of your message.substring to see if it contains any "non printable" characters at the end

You can do this by looping over your String, and serial printing each character in HEX format:

Serial.println(eachCharacter, HEX);

eachCharacter should be a char type here

i did what you suggest:

Tel_sms.toCharArray( CTel_sms, Tel_sms.length());
Serial.print(Tel_sms);
Serial.print(CTel_sms, HEX);
Serial.println(CTel_sms);
Serial.println(CTel_sms, HEX);

and the monitor shows:

+CMT: "+XXxxxxxxxxxxx5","","19/02/07,14:59:52-12"
Er10
0

the code sent was “er1”…

Anonymous printing sucks. You should NOT have to look back at the code to see what each line means.

Show us ALL of your code, so we can see where you are going wrong.

Hi PaulS the code is very simple:

#include <SoftwareSerial.h>

SoftwareSerial SIM900(7, 8); 

void setup()
{
  SIM900.begin(9600); 
  Serial.begin(9600); 
  Serial.println("OK");
  delay (1000);
  SIM900.println("AT+CPIN=\"XXXX\""); 
  delay(25000); 
}

void mensaje_sms()
{
  Serial.println("Enviando SMS...");
  SIM900.print("AT+CMGF=1\r"); 
  delay(1000);
  SIM900.println("AT+CMGS=\"+XXxxxxxxxXX\""); // this is what i'd like to change for a variable
  delay(1000);
  SIM900.println("SMS enviado desde un Arduino. Saludos.");
  delay(100);
  SIM900.println((char)26);
  delay(100);
  SIM900.println();
  delay(5000); 
  Serial.println("SMS enviado");
}

void loop()
{
  mensaje_sms(); 
  while (1); 
}

i’ve been modifying the code to try to use a variable in it, but was not possible for me…the problem it’s just as simple as that, use a variable where is number inserted by hand…

It’s solved,

SIM900.println("AT+CMGS=\"" + Remitente + "\"");

now it can be colsed…