user11905: I'm working on a home automation project using Arduino and MQTT.
I've found a problem and my limited programming knowledge find a way to solve it.
I can send text trough MQTT normally, using
client.Publish("some/topic","Some text here");

But when I try to send a variable (int, char, etc), the compiler says "invalid conversion from 'char' to 'const char*' [-fpermissive]"
How can I store DHT11 sensor reading in const char* to send it?
BTW, I've found this code where 
char *tempC;
tempC = dtostrf(((((analogRead(tempPinIn) * 5.0) / 1024) - 0.5) * 100), 5, 2, message_buffer);
client.publish("arduino/temperature",tempC);

is used. But the extra sensor calibration makes it even harder for me to understand whats going on. 

user10003: The function dtostrf() is prototyped as:
char *dtostrf (double          val,
               signed char     width,
               unsigned char   prec,
               char           *sout);

Where:    
   val      Your float variable;
   width    Length of the string that will be created INCLUDING decimal point;
   prec     Number of digits after the deimal point to print;
   sout     Destination of output buffer;

An example of usage is as follows:
/* OPTION ONE */

    char msgBuffer[20];           // make sure this is big enough to hold your string
    char *pointer_to_created_string;

    float testFloat = 123.45;

    pointer_to_created_string = dtostrf(testFloat, 6, 2, msgBuffer);
    client.Publish("...topic...", pointer_to_created_string);

/* OPTION TWO */

    char msgBuffer[20];           // make sure this is big enough to hold your string

    float testFloat = 123.45;

    client.Publish("...topic...", dtostrf(testFloat, 6, 2, msgBuffer));

Don't be put off by the code in the link you included in your question. The first argument sent to dtostrf (everything before the first comma) is nothing more than a some calculations bundled into one single line.

11905: <p>I'm working on a home automation project using Arduino and MQTT.</p>

<p>I've found a problem and my limited programming knowledge find a way to solve it.</p>

<p>I can send text trough MQTT normally, using</p>

<pre><code>client.Publish("some/topic","Some text here");
</code></pre>

<p>But when I try to send a variable (int, char, etc), the compiler says "invalid conversion from 'char' to 'const char*' [-fpermissive]"</p>

<p>How can I store DHT11 sensor reading in const char* to send it?</p>

<p>BTW, I've found <a href="http://e.verything.co/post/61576413925/publishing-arduino-sensor-data-through-mqtt-over" rel="nofollow">this</a> code where </p>

<pre><code>char *tempC;
tempC = dtostrf(((((analogRead(tempPinIn) * 5.0) / 1024) - 0.5) * 100), 5, 2, message_buffer);
client.publish("arduino/temperature",tempC);
</code></pre>

<p>is used. But the extra sensor calibration makes it even harder for me to understand whats going on. </p>
 10003: <p>The function <code>dtostrf()</code> is prototyped as:</p>

<pre><code>char *dtostrf (double          val,
               signed char     width,
               unsigned char   prec,
               char           *sout);

Where:    
   val      Your float variable;
   width    Length of the string that will be created INCLUDING decimal point;
   prec     Number of digits after the deimal point to print;
   sout     Destination of output buffer;
</code></pre>

<p>An example of usage is as follows:</p>

<pre><code>/* OPTION ONE */

    char msgBuffer[20];           // make sure this is big enough to hold your string
    char *pointer_to_created_string;

    float testFloat = 123.45;

    pointer_to_created_string = dtostrf(testFloat, 6, 2, msgBuffer);
    client.Publish("...topic...", pointer_to_created_string);

/* OPTION TWO */

    char msgBuffer[20];           // make sure this is big enough to hold your string

    float testFloat = 123.45;

    client.Publish("...topic...", dtostrf(testFloat, 6, 2, msgBuffer));
</code></pre>

<p>Don't be put off by the code in the link you included in your question. The first argument sent to <code>dtostrf</code> (everything before the first comma) is nothing more than a some calculations bundled into one single line.</p>
