user78: I don't understand how to publish to mqtt with retain option (The fourth parameters)
I know that I need length in an byte array but I've try allot to determine how to calculate my payload message to an byte var.
here is my code to publish once I am connected.
String str;
char chBright[4];
str = String(ledBrightness); //converting integer into a string
str = str + '%';
str.toCharArray(chBright, 4);
MQTTClient.publish("/maison/GF/Escalier/stairLight/b", chBright);

document ask the third parameter to be an byte

topic – the topic to publish to char*
payload – the message to publish byte array
length – the length of the message byte
retained – whether the message should be retained byte

0 – not retained
1 – retained


mqtt client for Arduino
How in c++ to get bytes from the message I want to publish?
Tank you to clarify my knowledge

user13432: 
How to Publish to MQTT with retain option?

The quick answer is add payload length, and retained as true as the last parameters to publish(). 
const int BUF_MAX = 8;
char buf[BUF_MAX];
itoa(ledBrightness, buf, 10);
strcat(buf, "%");
int len = strlen(buf) + 1;
MQTTClient.publish("/maison/GF/Escalier/stairLight/b", buf, len, true);

Above is a rewrite with the extra parameter for "retained", payload length, and payload as a null-terminated string. 
Cheers!

user10794: 
How in c++ to get bytes length from the message I want to publish?

For a String object, the method length() tells you the length.
eg.
int len = str.length ();

For a null-terminated C-type string, you can use strlen, eg.
char foo [20] = "bar";
int len = strlen (foo);


78: <p>I don't understand how to publish to mqtt with retain option (The fourth parameters)</p>

<p>I know that I need length in an byte array but I've try allot to determine how to calculate my payload message to an byte var.</p>

<p>here is my code to publish once I am connected.</p>

<pre><code>String str;
char chBright[4];
str = String(ledBrightness); //converting integer into a string
str = str + '%';
str.toCharArray(chBright, 4);
MQTTClient.publish("/maison/GF/Escalier/stairLight/b", chBright);
</code></pre>

<p>document ask the third parameter to be an byte</p>

<blockquote>
  <p>topic – the topic to publish to <code>char*</code></p>
  
  <p>payload – the message to publish <code>byte array</code></p>
  
  <p>length – the length of the message <code>byte</code></p>
  
  <p>retained – whether the message should be retained <code>byte</code></p>
  
  <blockquote>
    <p><code>0</code> – not retained</p>
    
    <p><code>1</code> – retained</p>
  </blockquote>
</blockquote>

<p><a href="http://knolleary.net/arduino-client-for-mqtt/api/#publish3" rel="nofollow" title="Arduino client for mQTT info doc">mqtt client for Arduino</a></p>

<p><strong>How in c++ to get bytes from the message I want to publish?</strong></p>

<p>Tank you to clarify my knowledge</p>
 13432: <blockquote>
  <p>How to Publish to MQTT with retain option?</p>
</blockquote>

<p>The quick answer is add payload length, and retained as true as the last parameters to publish(). </p>

<pre><code>const int BUF_MAX = 8;
char buf[BUF_MAX];
itoa(ledBrightness, buf, 10);
strcat(buf, "%");
int len = strlen(buf) + 1;
MQTTClient.publish("/maison/GF/Escalier/stairLight/b", buf, len, true);
</code></pre>

<p>Above is a rewrite with the extra parameter for "retained", payload length, and payload as a null-terminated string. </p>

<p>Cheers!</p>
 10794: <blockquote>
  <p>How in c++ to get bytes length from the message I want to publish?</p>
</blockquote>

<p>For a String object, the method <code>length()</code> tells you the length.</p>

<p>eg.</p>

<pre><code>int len = str.length ();
</code></pre>

<p>For a null-terminated C-type string, you can use <code>strlen</code>, eg.</p>

<pre><code>char foo [20] = "bar";
int len = strlen (foo);
</code></pre>
