The best way of to concat or append char

Hi. First of all, I am not very good in C++ but know the basic of it. I wrote a program sample, where arduino talk to my xig (internet gateway) using xbee.

void loop(void)
{ 
  
// allocate two bytes for to hold a 10-bit analog reading  
char payload[] = "http://192.168.1.3/pachube/temp.php?temp=38&feed=6519\r\n";

// payload array lenght needs to be at least one higher than the number of bytes to be transmitted
// 16-bit addressing: Enter address of remote XBee, typically the coordinator
  Tx16Request tx_5001 = Tx16Request(0x1966, (uint8_t*)(payload), strlen(payload));
  TxStatusResponse txStatus = TxStatusResponse(); //Check this out.
  
 xbee.send(tx_5001);
 
 delay(5000);

}

The problem is, I do not know the best way to rewrite above program just to have variables in URL’s parse.

Something like this, char payload[] = "http://192.168.1.3/pachube/temp.php?temp=<float value>&feed=<char type>\r\n";

where temp value is a float type (example, temp = ((float)DHT11.temperature,2):wink: .

I am totally no idea how to write and already spend a week just to find a good programming but I faced a lot of errors. Maybe my programming skill is not good enough. So, I really need help, so that my project could forward as plan.

The problem is, I do not know the best way to rewrite above program just to have variables in URL's parse.

The sprintf() function could do that, except that it doesn't handle floats. The dtrostrf() or dtostre() functions can convert a float to a string, but they don't allow a lot of flexibility in the formatting of the value. Perhaps the default would be good enough, though.

Yes. It can not handle float. So, my next question, if I convert float to string, can I convert it again char? how?

or make everything as a string, append or concat them and finally convert to char?

or I need to rewrite payload type in (Tx16Request(0x1966, (uint8_t*)(payload), strlen(payload));)? I think Tx16Request only except uint8_t*. Am I right?

So, my next question, if I convert float to string, can I convert it again char? how?

A string is a NULL terminated array of chars. So, if you convert a float to a string, you have an array of chars. You can't convert a float to a char.

You can convert a string to a float, using atof().

or make everything as a string, append or concat them and finally convert to char?

A string is a char array. The strings can be concatenated using strcat(). You can't convert a string (an array of chars) to a char. That would be like trying to put 100 feet in one shoe.

I think Tx16Request only except uint8_t*. Am I right?

Yes, but you can cast any one byte type (byte, char, unsigned char, signed char, etc.) array to a uint8_t *, using (uint8_t *)in front of the array name.