Errors using WifiClient and concatenating Strings.

Hi guys,

I’m trying to send a message using WifiClient library and i’m getting error always, since 3 hours of attempts:

char mensaje[50]="";
sprintf(mensaje,“ARDUINO DATA: %f|%f|%f \r”,humidity,tempc,tempf); //These are float Variables.
Serial.println(mensaje);

I’m getting this message output, not the values, all characters printed!, also the % and f letter
" ARDUINO DATA: %f|%f|%f "

And more & last,
Using WiFiClient library, then cliente is a ‘instance’:

cliente.write(“HOLA”); //Works and i get the msg in Raspberry using socket in Java.
cliente.write(mensaje); //Throw errors, request for member ‘read’ in ‘src’, which is of non-class type ‘char [50]’ src.read(obuf, leftLen);

¿How can i concatenize some Strings, with floats, in Arduino. And then with it, send a message over WiFiClient library?.

Thanks in advance and kind regards.

https://playground.arduino.cc/Main/Printf

Also note that by default the Arduino IDE does not set the AVR linker options to support floating point in the xxprintf() routines. So while that saves quite a bit of code space on the AVR builds, it means that printf() functions cannot be used for floating point output on the AVR. Floating support is included by default for the other processors.

Ciao, Ale.

Solution…

String iniMsg = "ARDUIDO DATA: ";
String separator = “|”;
String completeMsg = “”;

completeMsg += iniMsg + humedad + separator + tempc + separator + tempf;
Serial.println(completeMsg);

char charBuffer[50]="";
completeMsg.toCharArray(charBuffer, completeMsg.length());
cliente.write((const uint8_t *) charBuffer, completeMsg.length());
cliente.write("\r"); //FIN MENSAJE