Concatenate chars in one single variable to be sent in a SMS using the GSM shiel

Hi, i’m actually doing a project using XBee technology and the GSM. The xbee receives two float variables: the Temperature and the humidity. I want to send a SMS to a phone number with the values of those incoming variables in one single variable or char. i’m trying to use the variable sustitutión but it throws me an error:

invalid conversion from ‘char’ to ‘char*’ [-fpermissive]

in this part of the code:

char hi =sprintf(“Temperature=%s Humdity= %s”,tempstr,phstr);

this is my code

#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;
#include <SPI.h>

#include <XBee.h>//Used for xbee

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();

ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();
XBeeAddress64 address;
//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.


float temp,ph;

union u_sensor{
 int8_t value[4];
 float fsensor;
}sensor;


char tempstr[10]; 
char phstr[10]; 



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");



};

void loop()
{


   xbee.readPacket();
 if (xbee.getResponse().isAvailable()) {
     // got something
     if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {

         Serial.println("paquete disponible...");
         // got a zb rx packet
         // now fill our zb rx class
         Serial.println("recibimos un paquete");
         xbee.getResponse().getZBRxResponse(rx);
         // I check both bytes (or)
      
         getData();
         putData();
       }
     
     }
  delay(1000);




/*
    if(started) {
         //Read if there are messages on SIM card and print them.
       /**  deprecated method
       if(gsm.readSMS(smsbuffer, 160, n, 20)) {
              Serial.println(n);
              Serial.println(smsbuffer);
         }
         **/
         //get 1st sms
     /*
         sms.GetSMS(1,n,20,smsbuffer,160);
         Serial.println(n);
         Serial.println(smsbuffer);
         
         delay(1000);

         */
   // }
    
};


void getData(){
   temp= 0;ph = 0; 
   //Obtenemos el valor de la temperatura
   for(int i = 0;i<4;i++){
      sensor.value[i] = rx.getData(i);
    }
    
   temp=sensor.fsensor;
     Serial.println(temp);
   //Obtenemos el valor del ph
   for(int i = 0;i<4;i++){
      sensor.value[i] = rx.getData(i+4);
   }
     ph=sensor.fsensor;
     Serial.println(ph);  
}

void putData(){
     dtostrf(temp,2,2,tempstr);
     dtostrf(ph,2,2,phstr);
     //char  sms[200]="hola";
     char hi =sprintf("Temperature=%s Humdity= %s",tempstr,phstr);

     
   
     
 
    if(started) {
         //Enable this two lines if you want to send an SMS.
         if (sms.SendSMS("9831435711",hi))
         Serial.println("\nSMS sent OK");
    }
 Serial.println(temp);
 
 Serial.println(ph);
 
}

How can i fix this error or concatenate those variables into one char variable so i can send them in the sms? please help.

Welcome to the Forum. You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don’t do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons.
If you have already posted without using code tags, open your message and select “modify” from the pull down menu labelled, “More”, at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the “</>” icon at the upper left hand corner. Click on the “Save” button. Code tags can also be inserted manually in the forum text using the code and /code metatags.

Please read these two posts:

How to use this forum - please read.
and
Read this before posting a programming question …

aarg:
Welcome to the Forum. You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don’t do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons.
If you have already posted without using code tags, open your message and select “modify” from the pull down menu labelled, “More”, at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the “</>” icon at the upper left hand corner. Click on the “Save” button. Code tags can also be inserted manually in the forum text using the code and /code metatags.

Please read these two posts:

How to use this forum - please read.
and
Read this before posting a programming question …

Ok thank you :slight_smile: i have already fixed it. Can you help me with my code?

     //char  sms[200]="hola";
     char hi =sprintf("Temperature=%s Humdity= %s",tempstr,phstr);

Try changing to this…

char hi[200];
sprintf(hi,"Temperature=%s Humdity= %s",tempstr,phstr);

alanpain:

char hi =sprintf("Temperature=%s Humdity= %s",tempstr,phstr)

If you don't know how a function works, you can always google man function to find a man(ual) page for the function.

E.g man sprintf

charliesixpack:

     //char  sms[200]="hola";

char hi =sprintf("Temperature=%s Humdity= %s",tempstr,phstr);



Try changing to this...


char hi[200];
sprintf(hi,"Temperature=%s Humdity= %s",tempstr,phstr);

thank you so much :slight_smile: you really helped me it works!