MQTT on Arbuino not working

HI all,

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:

mosquitto_sub -v -t 192.168.1.162 -t openhab/rm1/tem
openhab/rm1/tem 26.60C
openhab/rm1/tem 26.60C
openhab/rm1/tem 26.60C

this is my config on Openhab:

/openhab/configurations/openhab.cfg:

mqtt:broker.url=tcp://192.168.1.162:1883
mqtt:broker.clientId=openhab


/openhab/configurations/items/default.items:

Group All
Group gGroundFloor (All)

Group GF_Living “Living Room” (gGroundFloor)

Number MyFirstSensor “Temperature [%.1f C]” (GF_Living) {mqtt="<[broker:openhab/rm1/tem:state:default]"}


/openhab/configurations/sitemaps/default.sitemap

sitemap default label=“Main Menu”
{
Frame label=“My First Sensor” {
Text item=MyFirstSensor
}
}

I spend few days already on reviewing and changing the config, but it is still not working.
What did I miss?

Try the following definition in the item file:

Number MyFirstSensor “Temperature [%.1f C]” (GF_Living) {mqtt="<[broker:openhab/rm1/tem:state:REGEX((.*))]"}

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);

Andrea =>I try and it is still not working.
Stefan => the C is on my message

tail -15 /opt/openhab/logs/events.log
2015-10-15 20:53:46 - MyFirstSensor state updated to 28.20C

I will review my arduino for the string.

Thanks both

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 :frowning:

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”)

My script is working Now, thanks all.