MQTT binding help

Hi All,

Apologies if this is in the wrong section,

First all let me say thank you to the creators of OpenHAB, I’ve only been tinkering with it for a few weeks & already see the amount of work & effort already put in!

Hopefully my issue is a simple Items/Sitemaps configuration problem,

Here’s my boats setup

OpenHab 2 installed on an Odroid C1 running Ubuntu 14.04.5 LTS.(using apt-get install openhab2-offline)
with MQTT binding installed under PaperUI (Add-Ons>Bindings & also Persistence)

This also has Mosquitto (version 1.4.10 - Also apt-get installed)

I’ve successfully configured the MQTT broker which is pulling temperature sensor information via wifi from a NodeMCU ESP-12E with ESP Easy firmware.

The node is reporting in to the MQTT broker ok - Node2 is the name of the sensor, Boat/Temperature the Channel

odroid@odroid:~$ mosquitto_sub -d -t /Node2/Boat/Temperature
Client mosqsub/11718-odroid sending CONNECT
Client mosqsub/11718-odroid received CONNACK
Client mosqsub/11718-odroid sending SUBSCRIBE (Mid: 1, Topic: /Node2/Boat/Temper ature, QoS: 0)
Client mosqsub/11718-odroid received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/11718-odroid received PUBLISH (d0, q0, r0, m0, ‘/Node2/Boat/Temperature’, … (5 bytes))
12.00

I’ve added the item in as follows

Number Temp “Temperature [%.2f F]” (Sjoukje) {mqtt="<[mosquitto:/Node2/Boat/Temperature:state:default]"}

Sitemap is very minimal currently!

sitemap default label=“Sjoukje Sensors”
{
Frame label=“On-board Temperature” {
Text item=Temp
}
}

I don’t get any sensor information.

I’ll be adding more once I work this out - the plan is to have a few water sensors in the boat hull, a relay for the heating system, plus water tank level sensors, I’ve already configured RGBW’s with a MiLight controller.

Can anyone point me in the direction of what I’m doing wrong with the MQTT binding?

Thanks
James

Have you defined broker in addons/mqtt.cfg?

Hi Pawel

I have the following in the mqtt.cfg

I’ve un-commented the lines on the comments as the leading # turns it to a heading on the forum

Define your MQTT broker connections here for use in the MQTT Binding or MQTT
Persistence bundles. Replace with an ID you choose.

URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
mymosquitto.url=tcp://localhost:1883

Optional. Client id (max 23 chars) to use when connecting to the broker.
If not provided a default one is generated.
mymosquitto.clientId=

Optional. User id to authenticate with the broker.
mymosquitto.user=odroid

Optional. Password to authenticate with the broker.
mymosquitto.pwd=odroid

Optional. Set the quality of service level for sending messages to this broker.
Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
(Deliver exactly once). Defaults to 0.
mymosquitto.qos=0

Optional. True or false. Defines if the broker should retain the messages sent to
it. Defaults to false.
mymosquitto.retain=true

Optional. True or false. Defines if messages are published asynchronously or
synchronously. Defaults to true.
mymosquitto.async=true

Regards
James

Change your items file to:

Number Temp "Temperature [%.2f F]" (Sjoukje) {mqtt="<[mymosquitto:/Node2/Boat/Temperature:state:default]"}

Done (sorry i misses that one!)

Sadly its still showing no data

James

I have the same problem, everything looks to be set up correctly but it doesn’t receive the data

Its a bit strange,

In mine, the last time i see the MQTT service initializing and starting in the OH2 logs was 2 days ago & nothing at all since.

I’ve rebooted the entire machine a few times so would expect to see it again.

I’ve used mqttfx on my laptop to confirm the brokers all ok, so its the OH2 MQTT services that i think are the issue - i have a feeling they’re not starting.

Edit - I think i know where i messed up, i didn’t copy over the 1.8 Transport & Binding Jar files.

I read that they are meant to go in the addons folder where is that on OH2? i only see addons.cfg in the services directory - do they go there?

James

After every restart of openHAB you should see

2016-12-28 20:30:52.766 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2016-12-28 20:30:52.781 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'

in your openhab.log, otherwise your MQTT binding is not working.

Nope,

Just restarted it again & scanned the log file - nothing since 2 days ago.

I’ve got Legacy 1.x binding & Access remote repository checked under Extension Management.

James

I suggest doing a bundle:list on your karaf console and check if the binding is loaded and active:

196 | Active   |  80 | 1.9.0.201612250211    | openHAB MQTT Binding
203 | Active   |  80 | 1.9.0.201612250211    | openHAB MQTT Transport Bundle

Transport Bundle is a dependency and should be automatically installed as soon as you install the MQTT binding …

182 | Active | 80 | 1.9.0.201612250211 | openHAB MQTT Transport Bundle
184 | Resolved | 80 | 2.0.0.201612251526 | openHAB Basic UI Fragment, Hosts:
212 | Active | 80 | 1.9.0.201612250211 | openHAB MQTT Persistence Bundle
214 | Active | 80 | 1.9.0.201612250211 | openHAB MQTT Binding

looks ok

James

just a quick follow up after tidying up my log files.

i see the MQTT transport now stopping when i reboot the machine, but it doesnt seem to start up.

2016-12-29 10:03:39.542 [INFO ] [penhab.io.transport.mqtt.MqttService] - Stopping broker connection 'mymosquitto’
2016-12-29 10:03:39.663 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Stopped Paper UI
2016-12-29 10:03:39.814 [INFO ] [basic.internal.servlet.WebAppServlet] - Stopped Basic UI
2016-12-29 10:03:39.907 [INFO ] [.dashboard.internal.DashboardService] - Stopped dashboard
2016-12-29 10:07:02.520 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'default.items’
2016-12-29 10:07:02.857 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'rrd4j.persist’
2016-12-29 10:07:02.956 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'logging.persist’
2016-12-29 10:07:08.263 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'default.sitemap’
2016-12-29 10:07:08.799 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'default.things’
2016-12-29 10:07:08.899 [WARN ] [.thing.internal.GenericThingProvider] - Thing Group does not have a bridge so it needs to be defined in full notation like :Group:All
2016-12-29 10:07:11.206 [INFO ] [.dashboard.internal.DashboardService] - Started dashboard at /start
2016-12-29 10:07:11.786 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2016-12-29 10:07:11.915 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /ui
2016-12-29 10:07:12.269 [INFO ] [panel.internal.HABPanelDashboardTile] - Started HABPanel at /habpanel

Is there any way to manually start the Broker transport in OH2?

James

Yesterday I have some similar problem with MQTT and I find difference between mqtt and mqtt1, so made changes in my runtime.cfg and addons.cfg

binding = network,lgtv,mqtt1

and all is work

Done that but sadly still the same,

I couldn’t see anywhere in the runtime.cfg to add it though so just added it in to the addons.cfg

I’ve got a spare Raspberry Pi so I’m going to install the old version of OpenHAB on that and see if it works

James

There is only a MQTT 1.9 binding, so it has to be always mqtt1 if installed through a cfg file.
Or you install it through a GUI, then you just have to it “Install” … both lead to the same result.

Because the binding is already active, proven by your karaf output, this step does not help you.

THAT (Stopping broker connection 'mymosquitto') is an error message from your broker, not from MQTT binding.
That’s a whole different story.
You should troubleshoot your mosquitto, not your MQTT binding!

Edit:

I just stumbled across that in your older post: it is not necessary to copy anything in the openHAB2 folder to make MQTT working. Just install a broker, test it with f.e. MQTT.fx, install the MQTT binding and create your items with the correct topic. That’s it. You should delete that in your addons folder it it is still there.

Thanks for the reply sihui

The MQTT error was in the Openhab2 log file, not the broker.

i installed hte binding originally through the PaperUI.

To clarify - from my laptop i can use Mqttfx successfully to connect ot the machine, subscribe to the topics & receive the sensor data being published

Mosquitto log file

1483005979: mosquitto version 1.4.10 (build date Thu, 25 Aug 2016 10:12:09 +0100) starting
1483005979: Config loaded from /etc/mosquitto/mosquitto.conf.
1483005979: Opening ipv4 listen socket on port 1883.
1483005979: Opening ipv6 listen socket on port 1883.
1483005984: New connection from 192.168.1.100 on port 1883.
1483005984: New client connected from 192.168.1.100 as ESPClient2 (c1, k15, u’odorid’).
1483007416: New connection from 192.168.1.103 on port 1883.
1483007416: New client connected from 192.168.1.103 as MQTT_FX_Client (c1, k60, u’odroid’).

ip 192.168.1.100 is my sensor node.
ip 192.168.1.103 is my laptop running Mqttfx

Mqttfx logs

2016-12-29 20:30:14,839 INFO — MqttFX ClientModel : sucessfully subscribed to topic /Node2/Boat/Temperature (QoS 0)
2016-12-29 20:35:54,129 INFO — MqttFX ClientModel : messageArrived for: /Node2/Boat/Temperature
2016-12-29 20:35:54,141 INFO — MqttFX ClientModel : messageArrived: 1

Hence i’m concentrating on the tie in from OH2 to MQTT.

James

Sorry, no more ideas.
I never had to go that deep into this stuff because MQTT worked almost right out of the box for me in openHAB2.

Good luck.

haha no worries sihui, thanks for helping.

When i get a chance i’ll try it as a fresh setup on the spare Pi & see what happens.

Must admit though I’ve learnt a lot about Mqtt, Linux & OH2 as a result of the last few days so not all a loss!

James

Did you shorten that log?
Because in my log it looks different when a client connects:

1483075536: New connection from 192.168.2.183 on port 1883.
1483075536: New client connected from 192.168.2.183 as ESPClient3 (c1, k15).
1483075536: Sending CONNACK to ESPClient3 (0, 0)
1483075536: Received SUBSCRIBE from ESPClient3
1483075536: 	/esp8266three/# (QoS 0)
1483075536: ESPClient3 0 /esp8266three/#
1483075536: Sending SUBACK to ESPClient3

I’m still thinking your problem is related to mosquitto and not to the binding …

Hi @Jamesb4uk, I was trying to look at your config file but it’s kind of hard to tell what is going on because of the uncommented comments. You should be able to show the full contents of that file by putting three ` (backticks) characters at the beginning of the line before the file contents, and then end it with three more after the last line of the file. That’s how I’m doing the file contents below.

I think I might see a problem with your mqtt config anyways, but I’ll let you confirm. In my config below, the line where I define the url begins with “mqtt:” You do not have the same part of that line in your file. That’s the part that lets openHAB know to get the configuration to the correct binding, so it’s very important.

After that, the next important step is to make sure the name of the broker in your items file matches the name you gave the broker in your config file. So if your config says mqtt:mymosquitto.url=tcp://localhost:1883, then you need to make sure that the start of the binding config in your items file matches the “mymosquitto” part like this: {mqtt="<[mymosquitto:/Node2... .

#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
mqtt:mosquitto.url=tcp://mqtt:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
#<broker>.clientId=<clientId>

# Optional. User id to authenticate with the broker.
#<broker>.user=<user>

# Optional. Password to authenticate with the broker.
#<broker>.pwd=<password>

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
#<broker>.qos=<qos>

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
#<broker>.retain=<retain>

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
#<broker>.async=<async>

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
#<broker>.lwt=<last will definition>

If modifying your mqtt config doesn’t fix it, then it will be good for you to learn more about how to track what is happening in openhab. To track down anything, you usually want to turn on the DEBUG logs for the binding. So in your case, you’d turn the mqtt logging to DEBUG. You can read about how to do that here: http://docs.openhab.org/administration/logging.html

Then you want to watch the logs. There are various ways to do this. Instead of rebooting to see what happens, I usually like to have 3 terminal windows open for the server. On the first one, I run tail -f openhab.log in the openhab logs directory. On the second one I run tail -f events.log in the openhab logs directory. These two logs usually give you pretty much anything you need to know, unless you configure a binding’s logging to go to its own separate file. In the third terminal I run other commands, like editing config files and restarting the service. Depending on the distro, you can usually restart openhab by running sudo systemctl restart openhab or sudo service restart openhab. You may not need the sudo and the command may be slightly different, but that’s the gist of it. The benefit of doing it this way is that you can just keep the tails running and you never have to reconnect your windows to the server.

Hope this helps!