sorry for wasting your time.
That is not snark. I am just telling you the reality.
Try this
void setup()
{
Serial.begin(115200);
float temp = 1.2;
float hum = 3.4;
float pres = 45.6;
Serial.printf("Temperature: %.2f ,Humidity: %.2f , Pressure: %.3f \n", temp, hum, pres);
}
void loop()
{
}
Actually, printf formatting has stymied legions of programmers. That is why, when C evolved into C++, string handling mostly transitioned to the String class which is much easier to use. But it has problems with memory on tiny processor architectures like the AVR used in the original Arduinos.
ok so i've been looking at this all wrong. the serial print is doing nothing for mqtt. i need to put all the line i need to change is
uint16_t packetIdPub1 = mqttClient.publish(MQTT_PUB_TEMP, 1, true, String(temp).c_str());
i just need to figure out how to combine the 3 lines the auther created into one. thank you for helping me in the right direction.
how do i take floating varables and put them in a variable?
mqttout = ("Temperature: % ,Humidity: % , Pressure: %\n", temp, hum, pres);
this is giving me a backwards question mark.
i'm rying to do this so i can input this into the line below inplace of (temp)
uint16_t packetIdPub1 = mqttClient.publish(MQTT_PUB_TEMP, 1, true, String(temp).c_str());
Possibly because you took a wild guess at the formatting string. That won't work. Do a search on "printf" and you will see the 1,000 options.
You were shown in reply #23.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.