I am stuck on a problem that should have an easy solution, but that I'm unable to find due to my lack of knowledge programming Arduino.
I am working with a Nano 33 IOT exchanging (publishing and receiving) messages with a MQTT broker (Ubidots in this particular case). When sending an integer value to the broker, I have no problems:
char msg_out[20];
itoa(intvalue,msg_out,10);
mqttclient.publish(topic, msg_out,retain);escribe o pega el código aquí
The problem comes when having to send a float value instead of an integer one. I cannot find any way of sending the string with the float value conversion. Function dtostrf(floatvalue,5,2,msg_out) does not work, and there is no ftoa() function doing something similar to itoa() but with float values.
gfvalvo, thanks for your reply. You are right. The dtostrf() DID not work, and now (I don't know why) it does work (?!?). I don't understand what has happened ... but now it works:
dtostrf(t,5,2,msg_out);
if (!mqttclient.publish(pubTopicTemperature, msg_out, retain)) Serial.println("** ERROR 7 Publish");
Independently of this, following idahowalker suggestion, I have tried also: