title: C++ / Arduino IDE. Publish float to MQTT - is conversion to string -> array necessary?
body: <p>I am trying to publish a float to an MQTT channel in C++, within the Arduino IDE.</p>
  
  <p>The following code does appear to work, but it seems to be a bit long-winded. I cobbled it together from stuff I found online. Is all this really necessary (the conversion to an array via a string), or is there a better way?</p>
  
  <pre><code>#include &lt;ESP8266WiFi.h&gt;
  #include &lt;PubSubClient.h&gt;
  #include &lt;Wire.h&gt;
  #include &lt;SparkFunBME280.h&gt;
  
  BME280 atmosSensor;
  
  String tStr;
  String pStr;
  String hStr;
  char tArr[4];
  char pArr[4];
  char hArr[4];
  
  void setup() {
      Setup wifi, mqtt, etc.
  }
  
  
  void loop() {
    float tempReading = atmosSensor.readTempC();
    float pressureReading = atmosSensor.readFloatPressure();
    float humidityReading = atmosSensor.readFloatHumidity();
    tStr = String(tempReading);
    pStr = String(pressureReading);
    hStr = String(humidityReading);
    tStr.toCharArray(tArr, tStr.length()+1);
    pStr.toCharArray(pArr, pStr.length()+1); 
    hStr.toCharArray(hArr, hStr.length()+1); 
    client.publish("atmos1/temperature", tArr);
    client.publish("atmos1/pressure", pArr);
    client.publish("atmos1/humidity", hArr);
  }
  </code></pre>
  
  <p>N.B. I have pruned this code down considerably, to just the relevant bit. I'm really just asking whether the conversion to a String, and then to an array etc, is necessary.</p>