[SOLVED] Openab2.2 - mqtt trouble

Hi there,

I’ve been trying to setup openhab2.2 to lisen to my local mosquitto broker, but seem to be running into trouble. The broker is running and accessible by other clients. openhab mqqt is enabled through org.eclipse.smarthome.mqtt.cfg:

mosquitto.url=tcp://192.168.139.11:1883
mosquitto.clientID=openhab
mosquitto.user=***
mosquitto.pwd=***
mosquitto.retain=false

However, openhab seems to have trouble holding the connection to the mqtt broker

2018-02-05 06:26:34.571 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto' to 'tcp://192.168.139.11:1883' with clientid paho4853749063439 and file store '/var/lib/openhab2/tmp/mosquitto'
2018-02-05 06:26:34.635 [INFO ] [.transport.mqtt.MqttBrokerConnection] - MQTT connection to 'mosquitto' was lost: MqttException
2018-02-05 06:26:34.637 [ERROR] [rotocol.mqtt.MySensorsMqttConnection] - MQTT connection offline - {}
org.eclipse.paho.client.mqttv3.MqttException: MqttException
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:176) [229:org.eclipse.paho.client.mqttv3:1.0.2]
	at java.lang.Thread.run(Thread.java:745) [?:?]
Caused by: java.lang.NullPointerException
	at org.openhab.binding.mysensors.internal.protocol.message.MySensorsMessage.generateAPIString(MySensorsMessage.java:391) ~[?:?]
	at org.openhab.binding.mysensors.internal.protocol.mqtt.MySensorsMqttConnection$MySensorsMqttSubscriber.processMessage(MySensorsMqttConnection.java:140) ~[?:?]
	at org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnection$ClientCallbacks.messageArrived(MqttBrokerConnection.java:121) ~[?:?]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:354) ~[?:?]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:162) ~[?:?]
	... 1 more
2018-02-05 06:26:34.653 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to 'mosquitto' every 10000ms

Any idea what I am doing wrong?

this one confuses me the most! :wink:
the “clientID” in your config is “mosquitto”, not “pahoxxx” - and “file store”? did never encounter this one.

so, please:

  • is your broker on your openhab-server or separate?
  • did you change your mqtt.cfg lately?
  • what platform are you running openhab from?

Hi Thomas,
Thanks for the swift reply!
I’m not using mqtt.cfg at all as I read somewhere that for openhab2.2 the mqtt service should only be configured via org.eclipse.smarthome.mqtt.cfg… Note, I have not installed the mqtt binding, but installed the feature.

Yes, mosquitto and openhab are on the same server, a raspi 3

1 Like

Whats “MQTT Service”? never heard of this one?
openHAB knows three kinds of MQTT Add-Ons:

everyone of them is configured through an .cfg within the %services% folder as it is a 1.9 version binding.
so please remove your present configuration and install them as explained in the docs - this one will work.

note:
/var/lib/openhab/config... isn’t meant to be edited by the user. This configuration will be built from the .cfg files or PaperUI database. Please don’t configure something here directly for released bindings and AddOns.

Maybe “service” is not the right term…?! I’ve followed the instructions from the mysensors forum: https://forum.mysensors.org/topic/8201/openhab-2-2-binding-mqtt-support

And yes, I am only editing files in the %services% folder, per the above instructions, I’ve been switching from mqtt.cfg to org.eclipse.smarthome.mqtt.cfg, though

ah! We’re talking non-released bindings here! :wink:
This is a custom made binding from Timo and I have to yield here.
as it is outside of openHAB2 universe and not released, I’m afraid, not many here can help you.

Seems from a first glance at the mysensors-forum thread, that the costum binding will take mysensor Information and transform it to openHAB.

I’m afraid you have to ask in the mysensors forum on more info.

most likely the root cause of your problem is: typo on clientID (it should be clientId) in mqtt.cfg

since this setting openhab is ignored, a default clientId is generated paho4853749063439

stop OH2
nuke /var/lib/openhab2/config/org/openhab/mqtt.config
fix /etc/openhab2/services/mqtt.cfg
start OH2
monitor logs

edit: I would recommend that you try to setup the “regular” mqtt binding, get it working and then try out that custom mysensors version of the mqtt binding

Well yes and no on the unreleased binding, since I haven’t even installed the mysensors binding, yet :wink: - I really wanted to get mqtt to work first…

I’ll check on that typo, maybe that’s a lead! Thanks!

@jjk, please stop for a minute before hurrying down a unknown road! :wink:

you have to distinguish between Standard openHAB functionality and costum made AddOns.

  1. all the MQTT stuff mentioned by me above is standard functionality
  2. the TimO mysensor-binding uses MQTT as transportation and from the looks encapsules the MQTT configuration and mysensor somehow

so, if you “just need MQTT” - use the standard AddOns - if you “just want MySensor information in MQTT” ask TimO what the prerequisites of his own binding are. As I see it, the MySensor/MQTT-binding has both in one, meaning, you can have MySensor configuration and use MQTT as a transportation medium between MySensors and openHAB.

So, please at first understand what you’re about to do - and do it afterwards. I have the impression you are just blindly following some information and HowTo here and there and don’t know exactly, what you’re about to do with this? am I correct?

1 Like

I can’t completely deny that, yes… Reading through the various docs, my impression was there needs to be a mqtt client running first, then mysensors would use that. But obviously it’s not that straight forward :wink:

I think you have to be sure on the prerequisites for the mysensors-binding, it won’t come clear on the thread alone, I’m afraid…

The binding uses the upcoming MQTT support in smarthome/OpenHAB2, not the old version 1 binding! They may work together, but we need to test that. If you’re willing to test that, please let me now.

I’m not sure, what that means - it’s referring to MQTT v2? feature:install esh-io-transport-mqtt indicates some Kind of MQTT within ESH (which is the underlying framework for openHAB2). Perhaps the typo alone could solve this? otherwise you have to ask TimO on a complete walkthrough…

Ha! At least it’s not clear for you either, so it’s not my sheer ignorance alone that left me in the rain :smile: I’ll check on the typo later today when I have access to my server and will report back what it does.

1 Like

…as I said: non-released binding! And I don’t find a clear documentation on this (ok, I didn’t even try, to be honest! :wink: ).
From the outside, it looks like the binding uses the ESH-MQTT transportation binding instead of the openHAB MQTT binding and uses that one for a communication between MySensors and openHAB. I don’t know why and what’s the “better” solution, but the ESH binding seems to be built after the MQTT openHAB1 binding (I think to have MQTT functionality without openHAB within ESH-only installations). So I guess it’s the typo only at this stage.

Ok, I will see and report if fixing the typo will fix the issue this afternoon. That said, I’m not aware of a better documentation for the mysensors binding, either (and I have searched for it :wink:) I’m aware it’s not official, but it’s the best lead I’ve been able to find to integrate mysensors into openhab. If there’s a better/easier way, I’m happy to try that as well!

Try the typo first. Next best thing was to aks TimO for help. Lastly you have to search the forum, there are plenty of mysensors related threads here I bet! :wink:

Ok, quick update: it was not the typo. After stopping OH, deleteting cache, tmp, and the /var/lib/…/mqtt.config and restarting without the typo I get the same result.

Probably I have screwed something complety up running down that road, so I will now try and do a brand new OH install over the next days I guess that’s easier than fiddling around.

update #2: it looks like the exception is indeed being thrown by the (unreleased) mysensors binding. What I didn’t realize was that the binding was still active after I removed it from the addons directory. Following an OH2 restart the ESH binding (esh-io-transport-mqtt) connected properly and without exception, after re-installing the mysensors bnding, the errors came back on. So at least it’s narrowed down to the root cause and I know where to continue looking.

Thanks to @binderth and @Dim for the support in this forum anyways, much appreciated!!

update #3:
Looks like I finally fixed it. So for anyone with the same problem who comes across this thread: there were retained messages my mosquitto broker sent out that the mysensors binding doesn’t seem to like. After deleting the mosquitto persistence file, things seem to work now.

1 Like