Openhab2 + MQTT = myPROBLEM


I made a fresh install of Raspbian Jessy in my Raspberry Pi 2.
Then I installed Openhab2 and Mosquitto server.

I have one NodeMCU module with an LED in gpio 2. The NodeMCU was flashed first with Espeasy firmware and later with another piece of code and the Arduino IDE. Both firmwares worked.

Opening 2 terminals I can send mqtt messages to the NodeMCU, turn on or off the LED and receive feedback.

Now the problem. It seems that Openhab2 can’t connect to mqtt.

  • The Mqtt binding and the JsonPath transformationaddon addons are installed.

  • This is my mqtt.cfg file in etc/openhab2/services/mqtt.cfg


    mosquitto.clientID: openhab

  • This is my default.items file in /etc/openhab2/items

Switch light1 { mqtt=">[mosquitto:/house/light1:command:on:1],>[mosquitto:/house/light1:command:off:0],<[mosquitto:/house/light1:command:on:1], <[mosquitto:/house/light1:command:off:0]"}

  • And this is my default.sitemap file in /etc/openhab2/sitemaps

sitemap default label=“Domotica Villa Alamo” {
Frame label=“Piscina” {
Group item=Piscina
Switch item=light1 label=“Luz piscina”

I can see the Switch in Basic UI, but it doesn’t work. Am I missing something?


A couple of thoughts:

  • Guessing the config can’t handle the url not specifying the protocol. Browsers can handle that but some things may not be able to. Try tcp:// instead.
  • are you running any authentication on mosquitto? If so you’ll need to supply them to openhab in the mqtt.cfg file.

Good point. That may be the problem. I read somewhere to use localhost instead of the ip adress. But I’ll try first replacing url by tcp.
I’m not running any kind of authentication on mosquitto yet.

Thanks for your reply.

Great. I have edited the file mqtt.cfg. The url=tcp was already there (it was my mistake when I added the code to this message). However, I have changed the IP for localhost:1883 and it works now.

Thanks a lot. Now I can keep on working with my system.