An MQTT broker is needed to proceed! For testing purposes you can use an open one but it’s better to install one locally. A good option is Eclipse Mosquitto on a normal Linux system. Mosquitto is part of the optional components of openHABian
A standalone MQTT client is needed for troubleshooting, e.g.
Please follow these links to learn more. You’ll need the knowledge to have fun in the later steps below.
The following steps will guide you through setting up a working connection between the openHAB MQTT Binding and openHAB to publish messages and subscribe to topics.
Connect with the standalone MQTT client to your Broker (You didn’t skip the list above, did you?).
This way you can check the error-free operation and verify your login credentials. Later you’ll be glad to have the client open to see what’s going through the Broker.
Subscribe to a topic. If you are unsure to which, the global selector # will do.
Install the MQTT Binding (binding-mqtt1) through Paper UI
Configure the Binding settings. Because it is a openHAB 1.x Binding, we need to do that through a configuration file (A new openHAB 2 Binding is on its way!)
You should see a configuration file mqtt.cfg among your service files ($OPENHAB_CONF/services/mqtt.cfg). In short the file has to contain the URL of your broker and login credentials (if available):
Check the openHAB log to see if the binding was able to connect to the broker: You can do so via file or console or on an openHABian system via the openHAB Log Viewer (frontail) at: http://openhabianpi:9001
Use the standalone MQTT client from before to publish an MQTT Message with the Content/Payload “ON” to Topic “testing/mqtt/topic”. Hit Publish.
The openHAB log should confirm the working connection between Client --> Broker --> Binding and show the received message:
2017-09-05 21:44:11.170 [ItemStateChangedEvent ] - MQTT_Test changed from OFF to ON
You have followed the instructions above but openHAB wasn’t able to connect to the Broker? First check your connection details again. Make sure the given IP address is correct and the login credentials match.
In rare cases a bug in openHAB causes a wrong or old configuration to be stored in the internal storage of openHAB. If in doubt, please follow these intructions:
Stop the openHAB service (e.g. sudo systemctl stop openhab2)
Add the following line at the beginning of $OPENHAB_CONF/services/mqtt.cfg: pid:org.openhab.mqtt
Restart the openHAB service (e.g. systemctl start openhab2)
You are ready to define Items to communicate with all kinds of devices and applications via MQTT!
That’s what I thought. So despite the hopefully soon available new binding, I decided to write this thread as a quick help here and now. @David_Graeff Please feel free to take as much as you can from the OP for the new Bindings README. A short introduction, some links and setting up of a testing Item might be useful to new users, even with the new binding.
Oh corrected. I’ve added MQTTLens. Thanks!
@rlkoshak@Dim from now on you just have to link it when a new user with old problems arises. Remember do to add details when possible. It would be great if we could have more threads like this…
Agreed. I can point to the Solving Exec Binding Problems thread as another one. I’m going to convert that to a wiki right now. Honestly, I’m pretty weak with Exec too. I only know as much as I do from helping others with their problems. I don’t use it myself. Others please contribute to this one too.
@David_Graeff, the new binding is very ambitious. I look forward to using it!
Even if it were available today, we would be fielding MQTT 1.x version questions for at least another year. People migrate painfully slowly.
First of all, the Tutorial shouldn’t be a replacement for the need to read documentation.
The focus should stay on “How to get started with the Binding” and the Binding is able to publish data just fine. Imo the Action is something rather special and I’m not sure if we would even need it in a “101 Tutorial”…
But yeah whatever Feel free to add it’s README to the references list in the beginning and mention the action before or after the Troubleshooting chapter.
This mini tutorial got me running in few minutes, while I spent hours to try already.
I think most of the oddity was because I did not realize we should use all config files since other examples uses PaperUI to define the entire solution.