[SOLVED] MQTT OpenHAB2 problem

Hi,
I have a problem with MQQT connection and OpenHAB2. Everything seems to bee good MQQT broker running on PI3. I want to send data from Arduino sensors to OpenHAB. Till now I have data from DHT22 sensor posted to MQQT, but data is not visualized on Basic UI.I tried with switches too, just to see that messages are subscribed/posted unfortunately without success.

mqqt.cfg looks like:

mosquitto.url=tcp://localhost:1883
mosquitto.clientId=openhab
mosquitto.retain=true
mosquitto.async=false

test.sitemap like:

sitemap home label=“MyHouse”
{
Frame label=“Light Switch”
{
Switch item=Switch1
}
}

test.items like:
Switch Switch1 {mqtt=">[broker:home/lights/in:command:ON:1],>[broker:home/lights/in:command:OFF:0],<[broker:home/lights/in:state:ON:1],<[broker:home/lights/in:state:OFF:0]"}

If I understood well when i change switch position message shall be posted or if I send command OFF or ON throug mosquitto_pub -t home/lights/in. Swtich position should be changed to OFF.
Every advice will be appreciated. Thanks in advance

First of all, it is MQTT.

Do you have an mqtt.cfg file, not mqqt.cfg as written?
Did you install the MQTT binding?
Do you see “Starting MQTT broker connection to ‘mosquitto’” in your logs?
Do you see any errors in the logs?
Do you see “New client connected from <IP address> as openhab 
” in mosquitto logs?

1 Like

Do you have an mqtt.cfg file, not mqqt.cfg as written? — What is the difference ? If i see correct name is same
Did you install the MQTT binding? A: Yes I have it already installed
Do you see “Starting MQTT broker connection to ‘mosquitto’” in your logs? A: Here is what is displayed in the log i think that there is something wrong in second message:
2017-08-30 21:51:44.805 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2017-08-30 21:51:44.805 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2017-08-30 21:51:44.917 [ERROR] [org.apache.felix.configadmin ] - Cannot use configuration org.openhab.mqtt for [org.openhab.core.scriptengine.action.ActionService, org.osgi.service.cm.ManagedService, id=345, bundle=209/mvn:org.openhab.action/org.openhab.action.mqtt/1.10.0]: No visibility to configuration bound to mvn:org.openhab.io/org.openhab.io.transport.mqtt/1.10.0

The MQTT binding is looking for a file called mqtt.cfg. If your file is named mqqt.cfg the MQTT binding will not find any configuration file, and that makes a huge difference, :slight_smile:

Oh my bad my file is named correct mqtt.cfg that was a TYPO

In config/services i found 1 more file which is called mqtt-eventbus.cfg doesh it need to be configured too and how?

Alright I think that connection is good because when i stop mosquitto this message is showed in the log:
2017-08-31 10:01:19.881 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to ‘mosquitto’ was lost: Connection lost : ReasonCode 32109 : Cause : Read timed out

But the problem still there is nothing in mosquitto_sub -v -t ‘home/lights/in’ also when i try to publish something mosquitto_pub -v -t ‘homeme/lights/in’ there is nothing happened in Basic UI

Your item definition needs to reference the MQTT broker using the alias that you have defined in the mqtt.cfg file, in your case ‘mosquitto’.

Try to update your item definition as follows:

Switch Switch1 {mqtt=">[mosquitto:home/lights/in:command:ON:1],>[mosquitto:home/lights/in:command:OFF:0],&lt;[broker:home/lights/in:state:ON:1],<[mosquitto:home/lights/in:state:OFF:0]"}

Now this is showed in log:
Line 3689: 2017-08-31 10:28:02.191 [ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type ‘mqtt’ of item ‘Switch1’ could not be parsed correctly.
Line 3690: org.eclipse.smarthome.model.item.BindingConfigParseException: Invalid mqtt binding configuration ‘mosquitto:home/lights/in:state:ON:1’ for item Switch1

Thanks a lot now is working correct there was a TYPO. I not saw it because I just copied your comment

Yes, I am afraid there was a typo in my text, :frowning:
Glad it is now working, however, I think you still have a problem with the configuration of the inbound bindings.

From your example, I understand that your device (sitting at “the other end” of MQTT) uses “0” and “1” that you want to map to “OFF” and “ON” in openHAB.

In this case you need to create a MAP transform (a file in the openHAB transform folder) as follows:

Name: my-mqtt-in.map
Content:

0=OFF
1=ON

Then you need to install the MAP transform (using Paper UI or cfg files), and finally use the MAP file in your item binding.

Please try the following:

Switch Switch1 {mqtt=">[mosquitto:home/lights/in:command:ON:1],>[mosquitto:home/lights/in:command:OFF:0],<[broker:home/lights/in:state:MAP(my-mqtt-in.map)]"}

By using another MAP transform you can simplify the item definition further (if you want):

Name: my-mqtt-out.map
Content:

OFF=0
ON=1

Switch Switch1 {mqtt=">[mosquitto:home/lights/in:command:*:MAP(my-mqtt-out.map)],<[broker:home/lights/in:state:MAP(my-mqtt-in.map)]"}

I already control the switch thanks a lot for help.
Now I’m going on second stage. I want to display arduino sensor dht22 temperature in openhab i have information published already i think that when i add Number it will be fine