OH3, cant get temperature readings from Mosquitto

  • Platform information:
    • Hardware: PC
    • OS: Win10
    • openHAB version: 3

Trying to get temperature readings to openHAB3 for the first time. Never used oH before. Seems complicated and most of the tutorials are in German :slight_smile:

I believe I have succesfully connected oH and Arduino to Mosquitto. But can’t read the info from Mosquitto to oH. Not sure if my Arduino sends it in correct format and “channel parameters” or whatever
 Could anyone have a look?

Arduino code:
sensors.requestTemperatures();
temp1 = sensors.getTempCByIndex(0);

 char temp1Char[10];
dtostrf(temp1, 4, 2, temp1Char);
Serial.println(temp1);
client.publish("Arduinotesti", temp1Char);

And Mosquitto sees it like this:
"Received PUBLISH from Arduino (d0, q0, r0, m0, ‘Arduinotesti’, 
 (5 bytes))


NÀyttökuva 2021-02-13 180113

Is the “Arduinotesti” correct in Arduino code? Should it be some other identifier when you look my oH setup?
client.publish(“Arduinotesti”, temp1Char);

In Arduino code, is it correctly trasformed from float to char and is it really needed? Is it correctly in oH when it’s string and number?

Or am I missing something bigger here or is it just something small?

That might be a good thing to check. A third party tool like mqtt.fx will allow you to get the broker to show you the messages. When you know what your Arduino is sending, you have a better chance of making it send what you want, and then to get openHAB to look at it.

Ok. Installed MQTT.fx now to different machine and got it connected ok to Mosquitto. Subscribed as “Arduinotesti” as set in Arduino code. Seems that temperature reading is sent out correctly, thank you rossko57! :slight_smile:

Then I need to figure out how to get the numbers to oH


Based on what you saw there, you’d need to give your channel a stateTopic to subscribe to.
In the first case, you might make a temporary string type channel to get the whole message, for confidence.
Later, you add another channel, perhaps number type, with any transformations that you might need for your payload.

What does stateTopic mean?

It is a parameter of an MQTT binding Generic Thing’s channel, and tells the binding which topic to listen to from the MQTT broker, and to use the payload of any messages on that topic to update any openHAB Items linked to that channel.

So it’s the same “Arduinotesti” which I used succesfully with MQTT.fx to subscribe. Lets try.

rossko57, thank you! :relaxed: It works!