OpenHAB – leading spaces -> dtostrf

10. November 2017 at 18:19
Print Friendly, PDF & Email

Fixing an error caused by dtosrtf

For my home automation, I am using an arduino sending data via MQTT to OpenHAB.

The code is based on the repository of Matthew Bordignon

https://github.com/matbor/arduinoTemps2mqtt

As it was getting colder outside; I was wondering why OpenHAB did read the outside temperature anymore.
The simple answer: the temperature was less than 10 degrees celsius and the module was sending ‘ 6.8’.
OpenHAB did not know what to do and rejected the data.

So I have changed the code
Before: dtostrf(celsius, 4, 1, charMsg);
After: dtostrf(celsius, 0, 1, charMsg);

Now the module is sending ‘6.8’, no leading space anymore.