I have to publish three variables which have a width of 5 and precision of 2.
I am using this function to convert from float to char string -
dtostrf(floatVar1, 5, 2, charBuf1);
I now need to publish the charBuf1, charBuf2, charBuf3 to the MQTT broker . I tried ,
client.publish( topic, charBuf1);
But it threw an error. I am using the ESP32 chip and PubSubClient library.
Need help. Thanks
Wow .. that helped. Appreciate your guidance !!
So this one did the job and now I can publish the "postValue" to the MQTT broker and all good !!
void readBME280() {
tempC = bme.readTemperature();
tempF = (1.8 * tempC + 32);
press_hPa = bme.readPressure() / 100;
humid_percent = bme.readHumidity();
elevation_m = bme.readAltitude(SEALEVELPRESSURE_HPA);
dtostrf(tempC, 2, 2, charBuf);
dtostrf(tempF, 3, 2, charBuf1);
dtostrf(press_hPa, 4, 2, charBuf2);
dtostrf(humid_percent, 2, 2, charBuf3);
dtostrf(elevation_m, 4, 2, charBuf4);
strcpy(postValue, charBuf);
strcat(postValue, " ; ");
strcat(postValue, charBuf1);
strcat(postValue, " ; ");
strcat(postValue, charBuf2);
strcat(postValue, " ; ");
strcat(postValue, charBuf3);
strcat(postValue, " ; ");
strcat(postValue, charBuf4);
Serial.println(postValue);
}