MQTT on Rasp PI (Mosquitto)

I am a very green beginner and I am stuck. Right now I have only X10 devices and plans to add MQTT devices. I built a little demo board with an ESP8266 and a DHT22 that sends back temperature and humidity readings via MQTT. The Raspberry PI has a WIFI adapter that is configured as an Access Point. It passes out 192.168.42.XX IP addresses. The ESP8266 can connect to that Access Point and it does publish MQTT messages. From another device on that subnet, I can subscribe to the MQTT messages and the messages do appear. I can also subscribe to the messages right on the PI.
Using the PaperUI, I installed the MQTT binding. I also installed the persistence MQTT bindings. I have rebooted the PI numerous times. While the MQTT binding is installed, it never shows up as an option anywhere else. Searching the community, it seems that I need to edit a mqtt.cfg file. I edited /etc/openhab2/services/mqtt.cfg and added the line.

mosquitto.url=tcp://localhost:1883

Previously I had it as openhab2.url, but changed it to match examples on the web. If I reboot and look at the log file. I see the following messages,but no errors.

2017-02-01 21:18:27.638 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2017-02-01 21:18:27.639 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto’
2017-02-01 21:18:27.923 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ‘openhab2’

2017-02-01 21:19:00.066 [WARN ] [mqtt.internal.MqttPersistenceService] - mqtt-persistence:broker
2017-02-01 21:19:00.067 [WARN ] [mqtt.internal.MqttPersistenceService] - mqtt-persistence:topic
2017-02-01 21:19:00.068 [WARN ] [mqtt.internal.MqttPersistenceService] - mqtt-persistence:message

It somehow has copied the old mqtt.cfg settings, because now I seem to have two entries. But nothing in either the PaperUI or Habmin appear to know anything about my MQTT binding. It is as if it does not exist.
It is probably something very obvious and stupid. Is there a simple example of setting up something like a MQTT temperature sensor from the ground up?
Is there any other log files that contain any more hints about what it does not like?
Am I editing the wrong cfg file?

Thanks for any pointers

Would love to help, but have no idea about OH2…

Hi Steve,
I had something similar when I tried to use different configs for mqtt. I think the ‘old’ config is stuck in your configuration.
One way to check is to log into your karaf console, and check your configs.

log in: sudo ssh openhab@localhost -p 8101. Standard password is habopen.
In the console you type config:list. You will get a very long list of data on your screen, but when you scroll back you will find more detailed information on your configs. Check if you see your mqtt config twice. This is how mine looks like:

----------------------------------------------------------------
Pid:            org.openhab.mqtt
BundleLocation: mvn:org.openhab.io/org.openhab.io.transport.mqtt/1.9.0
Properties:
   mosquitto.clientId = openhab
   mosquitto.url = tcp://192.168.xx.xx:1883
   service.pid = org.openhab.mqtt

If you see two configurations mentioned for mqtt, that might be your problem.

See this topic for further details how to work with the karaf console:

3 Likes

Thanks Maurtis.
I looked at the config:list, What I found was the following single PID entry:

Pid: org.openhab.mqtt
BundleLocation: mvn:org.openhab.io/org.openhab.io.transport.mqtt/1.9.0
Properties:
mosquitto.url = tcp://localhost:1883
openhab2.url = tcp://localhost:1883
service.pid = org.openhab.mqtt

In /etc/openhab2/services I only have the first URL listed. The second URL was a previous entry that I deleted because I thought it was my problem.
I removed the MQTT binding from the PaperUI. Then I rebooted. The mqtt.cfg file remained. I reinstalled the MQTT binding from the PaperUI and rebooted again. When I look at the log file. The same two entries for MQTT remain.
Full disclosure, I have no clue what I am doing in openhab2. I installed it and initially had a demo option. I opened that demo option, looked around and then when I later pointed a browser to the Index page, the demo option was no longer there. However, looking at the log file, it has lots of entries about changing the temperature in the bathroom for example. This makes me think I am stuck in a world under the demo version, as I surely don’t have any temperature control in the bathroom! Other than completely uninstalling and starting over, I don’t know how to get back out of the rabbit hole I seem to be in.
The surreal part of this is that some items are real time and not demo. I brought the PI to work so that I could play with it over my lunch hour. My Inbox within the PaperUI now shows every printer on the companies network.

Maybe good to start a fresh openHABian install? It takes one hour, and you’ll have most of the common necessities installed, it probably is faster than to keep searching what went wrong in your current setup…

Thank you for the suggestion. For most people, it would be a very good suggestion for a newbie. However, since my HW is old (X10), it does not work for me. I started with the openHABian image. The install went very smoothly. However, the X10 interface is mochad which needs to be built on the PI. I guess to save space and download time, lots of stuff was trimmed out that most people do not need. However, the items that I needed were a C++ compiler, lsusb, and netcat. I started adding these, but then just gave up on open HABian and installed a full version of Jessie with openHAB over top of that so I was sure to have all the necessary Linux bits and pieces.
Again, I am not knocking openHABian. I am sure that it is very useful to lots of people and I understand the trade-offs. I am sure folks with newer HW can get up and running with openHABian without ever touching a console prompt.

I was totally unaware of the karaf database. I suspect that I need to go down into there and clean up the configuration from within that database. It is probably full of junk from all my failing test cases. If I cannot make headway with the cleanup, then I am going to just remove openHAB and reinstall it. Then I am going to image the SD Card before mucking around so it will easier to return to a known point.

You may need to clean the old cfg data from the runtime. Refer this post for a method of doing this.

OK, just to follow up, root cause is my lack of understanding of how OpenHab2 works. I installed the MQTT binding and kept thinking that this would show up in the Inbox and be configurable from the GUI. Apparently only 2.0 versions of bindings work that way. Therefore, there are a fair number of files that must be configured with a text editor before MQTT will work for me. The link below details the files that need to be modified. I have not completed it yet, so I cannot vouch if that is the full list.

One small suggest on the PaperUI, it may be helpful to highlight bindings older than OpenHab2 is a different color to help clue the newbies that if they install those bindings additional text configuration is required. Otherwise, the endless install, uninstall, reinstall and then ask why it does not work continues to occur.

Just the mqtt.cfg with one line in a standard setup:
mosquitto.url=tcp://localhost:1883

Those bindings all have a trailing “1” in the binding name, like mqtt1:

This cleary states what @pahansen already suggested: follow his link and clear the old configuration.

That is not accurate. Modifying mqtt.cfg may be all that is required to configure the binding in the most simplest case. However, no one gets any joy from a configured binding that does nothing and is invisible to the rest of openhab2.

Several other files require modification to subscribe to the mqtt topic, parse the messages from said topic, and then take some openhab2 action based on those parsed messages. I think is important to stress that fact. Otherwise, other newbies like me will be wasting lots of time editing just the one file and wondering why nothing appears in any of the GUIs.

That is what I wrote.

You are quoting me out of context. I am the original poster. The original post did not ask about only configuring the binding. The original post is about getting MQTT working with the Raspberry Pi and openhab2.
All I am trying to do is get MQTT working and perhaps help others to avoid the pitfalls that I encountered.
In response to sharing what little I found out, I get contradictory, snide comments that do not move the topic forward, they just add additional confusion to anyone else trying to figure this out.
I think I will just mothball this SD Card and give one of the other home automation programs a try. I have already spent way too much time on items that should be better documented and better supported.

Sorry, was not my intention.

That’s what I did too a long time ago … and came back to openHAB, because nothing can beat it.

I solved this problem: MQTT Connection lost every time an update is pushed