MQTT Client.Publish

Hello,

My C++ coding skills leave a lot to be desired so I apologize in advance.

I am having problems publishing values from my BME280 to my MQTT Mosquitto server.

I can get the print the values to the serial monitor like this:

Serial.print(bme.readTemperature());

But, when I try and do this:

client.publish("WeatherStation1\BME280\Temperature", bme.readTemperature());

I get the error:

no matching function for call to 'PubSubClient::publish(const char [9], float)'

I am pretty sure it's because the "payload" is a "const char[]"

Ideally I have been trying to find a function that I can call that will return the const char without any spaces. So it has calculated the length needed?

Can anyone help me with this conversion please?

Can anyone help me with this conversion please?

dtostrf()

MQTT commonly uses forward slashes (/) as path delimiters. If you want to use backslashes (), you have to escape them in C++ code:

char buffer[15];
client.publish("WeatherStation1\\BME280\\Temperature", dtostrf(bme.readTemperature(),8,2));