I have a Raspberry pi that run OpenHab and Mosquitto and I try to receive the temperature from Arduino using a MQTT
The MQTT Broker (on the same Raspberry that OpenHab), Publisher (Arduino) and Subscriber (on the same Raspberry that OpenHab) look ok, see my test bellow:
do you send a “C” in your mqtt message from arduino, or just the temperature?
another thing i had to do is convert the temperatures in arduino to a string before sending.
here is my arduino code, where temperature is stored in --> char temp_string[9];
temperatur = sensors.getTempC(tempSensor2);
if (temperatur < 10.0 && temperatur >= 0.0) {
//Serial.println(F("4 stellen"));
dtostrf(temperatur, 4, 2, temp_string);
} else if (temperatur < 0.00 && temperatur > -10.00 || temperatur >= 10.00) {
//Serial.println(F("5 stellen"));
dtostrf(temperatur, 5, 2, temp_string);
} else if (temperatur <= -10.00) {
//Serial.println(F("6 stellen"));
dtostrf(temperatur, 6, 2, temp_string);
}
client.publish("HA/temp/tempSensor2", temp_string);
hey,
it seems the message successfully makes it to openhab.
maybe if you just send the temperature without “C” you can work with that number right away?
my arduino code above makes sure that no blank spaces → " " are sent with the message.
not sure if that is the problem with your setup. anyway, this way i don’t have to deal with blank spaces in OH when temperatures are more ore less than 5 characters, e.g. -10.00 or 1.00
Thanks a lot Stefan, one of my problem was the “C”, by removing it from the message I fix the my script
but I discover that a different problem, I forgot to install the MQTT Java
by the way:
My test to check if I was receiving MQTT message (“mosquitto_sub -v -t 192.168.1.162 -t openhab/rm1/tem”) was not the best, I was looking using Mosquitto client when I needed to check using OpenHab (“sudo sh /opt/openhab/start_debug.sh”)