Close

Firmware Update

A project log for Solar water heater monitor

Monitor and log temperature of wood fire boosted Solar hot water heater

saabmanSaabman 10/10/2016 at 09:350 Comments

I had been struggling with sending a floating point value to the MQTTserver. The MQTT implememtation sends a string and message was formatted by using snprintf to create a string array from the data but it doesnt seem to work with floating point values.

I had been getting around it by multiplying the temperature and volatge readings by 100 converting to and int and then sending that figgure. The plan was to read the value later and divide by 100 to recreate the 2 decimal places I wanted - 1 decimal place would be more than adequate but.

Figgureing someone else must have had to deal with this situation I applied some good google foo and found a Home Assistant tutorial by Paulus Schoutsen that did just what I wanted and he used

client.publish(temperature_topic, String(temp).c_str(), true);

https://home-assistant.io/blog/2015/10/11/measure-temperature-with-esp8266-and-report-to-mqtt/

.c_str() was just what I needed so updated my client.publish and gotrid of the *100 business - all much tidier.

Thanks Paul :)

Now having seen the Home Assistant project I think that might give mesome more toolsto use in what I wish to achieve.

Discussions