Sending numeric value through SMS

Hi

I am stuck with sending numeric value through SMS. I got a piece of code which I used for this project

https://searchcode.com/codesearch/view/37984800/

I am using Ardunio Mega with ICOMSAT 1.1 SIM900

I simplifed this code for SMS sending

#include <SoftwareSerial.h> 
#include <GSM_Shield.h>

//**************************************************************************
char number[]="+9212345678";  //Destination number 
char text[]="hello world";  //SMS to send
byte type_sms=SMS_UNREAD;      //Type of SMS
byte del_sms=0;                //0: No deleting sms - 1: Deleting SMS
//**************************************************************************

GSM gsm;
char sms_rx[122]; //Received text SMS
//int inByte=0;    //Number of byte received on serial port
char number_incoming[20];
int call;
int error;


void setup() 
{
  Serial.begin(9600);
  Serial.println("system startup"); 
  gsm.TurnOn(9600);          //module power on
  gsm.InitParam(PARAM_SET_1);//configure the module  
  gsm.Echo(0);               //enable AT echo 


void SIM900power(); 
// software equivalent of pressing the GSM shield "power" button
  delay(5000);
  digitalWrite(9, HIGH);
  delay(500);
  digitalWrite(9, LOW);
  delay(500);



}


void loop()
{ 
  char inSerial[5];   
  int i=0;
  delay(5000);
  
   

    //Check data serial com 
    
         Serial.print("Send SMS to ");
         Serial.println(number);
         error=gsm.SendSMS(number,text);  
               
               delay(5000);
  
               
           }

This work good for sending SMS as whenever I run program it send me sms.

Now instead of sending a particular text as mention
char text=“hello world”; //SMS to send

I need to float a variable like
float temperature=27;

and send this via SMS

Later I will convert this variable temperature with DS18b20 temperature data.

I made some changes to code but ended in error

void loop()
{ 
  char inSerial[5];   
  int i=0;
  delay(5000);
  
   float temp=27;

    //Check data serial com 
    
         Serial.print("Send SMS to ");
         Serial.println(number);
         error=gsm.SendSMS(number,temp);  
               
               delay(5000);
  
               
           }

Error: working_send_sms:66: error: no matching function for call to ‘GSM::SendSMS(char [12], float&)’

I think I am making mistake in converting float to char.

Can someone help me on this?

This is my 1st post, so please let me know if there are posting errors

#include <SoftwareSerial.h>

On a Mega, with 4 hardware serial ports. Hmmm.

I need to float a variable like
float temperature=27;

Why are you using a float to hold an integer value?

dtostrf() will convert a float to a string.

Hi

Partial problem is solved,
When I use ONE If function than its all ok, SMS well sent with temperature value

But when I make 4 different If functions, each for each sensor than some how temperature get mixed up and some sms get missed

char inSerial[5];   
  int i=0;
  
char buffer1[17];
  char t[10];
 
    float a = tempCurrent1;
  dtostrf(a, 3, 2, t);
  sprintf(buffer1, "%s High Temp Room 1 ", t);
   
  
  char buffer2[17];
  char u[10];
     float b = tempCurrent2;
  dtostrf(b, 3, 2, u);
  sprintf(buffer2, "%s High Temp Room 2 ", u);
   
  
  char buffer3[17];
  char v[10];
    float c = tempCurrent3;
  dtostrf(c, 3, 2, v);
  sprintf(buffer3, "%s High Temp Room 3 ", v);
   
  
  char buffer4[17];
  char w[10];
    float d = tempCurrent4;
  dtostrf(d, 3, 2, w);
  sprintf(buffer2, "%s High Temp Room 4 ", w);
   
  
  
     
    
     if (tempCurrent1 > 5)
    {
         Serial.print("Send SMS to ");
         Serial.println(number);
         error=gsm.SendSMS(number,buffer1);  
          digitalWrite(13, HIGH);
          delay(10000);
          digitalWrite(13, LOW);
        }
    
    if (tempCurrent2 > 10)
    {
         Serial.print("Send SMS to ");
         Serial.println(number);
         error=gsm.SendSMS(number,buffer2);  
          digitalWrite(13, HIGH);
          delay(10000);
          digitalWrite(13, LOW);
        }
        
  
  
    if (tempCurrent3 > 10)
    {
         Serial.print("Send SMS to ");
         Serial.println(number);
         error=gsm.SendSMS(number,buffer3);  
          digitalWrite(13, HIGH);
          delay(10000);
          digitalWrite(13, LOW);
        }
        
          if (tempCurrent4 > 10)
    {
         Serial.print("Send SMS to ");
         Serial.println(number);
         error=gsm.SendSMS(number,buffer4);  
          digitalWrite(13, HIGH);
          delay(10000);
          digitalWrite(13, LOW);
        }

I believe somehow buffers get mixed up.

Can someone help me on this

  dtostrf(a, 3, 2, t);

A field width of 3, with 2 digits after the decimal point. Hmmm.

sprintf(buffer1, "%s High Temp Room 1 ", t);

strcpy() and strcat() would waste fewer resources.

18 characters plus the characters in t and the terminating NULL will NOT fit in a 17 element array.

can you help me with this, how should I code?

saleemsadruddin:
can you help me with this, how should I code?

Very carefully.

how should I code?

What would you do if you have a size 18 foot, and the shoe salesman tries to sell you a size 14 shoe?

Live with the fact that the shoe is too small, or request a bigger size?

Let me try asking shoeman size 18 foot

saleemsadruddin:
Let me try asking shoeman size 18 foot

No, you need a size 18 shoe

Size 24 shoe fit in

Thankyou so much for your help and suggestions

char buffer1[24];
 char t[10];
 float a = tempCurrent1;
dtostrf(a, 3, 2, t);
sprintf(buffer1, "%s High Temp Room 1 ", t);

thank you all , this question and answers is helpful for me too :wink: