Need to understand client.publish in MQTT for arduino [solved]

Hi All,

I'm learning MQTT and Arduino for a project and i have a doubt that i have even after read a lot everywhere.

I have this simple code to send data from sensors to a server, the code works well and the server receive data, but now a need to send an array of variables that comprise "float" and "int" but the code don't work. It give me an 0,1,1,1,1,1,1) reading on the serial.

When i try to use body.toCharArray(payload, 1000); it dont work.

I need help to understand it better and learn how to solve this issue.

hardware: ARDUINO MEGA 2560 + W5100 ( for ethernet )

( English is not my first language, sorry for errors )

The code:

// Variables 

float tempRet;    

float tempIns;  

float tempDes;    

float fase;       

float i;         

int diest; 

// The send code


  if (!client.connected()) {




 char body[1024] = {'0', 'tempRet', 'tempIns', 'tempDes', 'fase', 'i', diest','\0'};

 // publish a message roughly every second.

 if (millis() - lastMillis > 1000) {

   lastMillis = millis();

   client.publish("/GSC", body);  


   Serial.println("Send it");



Found the answer, if anyone need it, in this topic: