I have successfully configured RPi2 OH2.2 with MQTT binding and Mosquitto.
After I noticed, that my password is visible in mqtt.cfg I decided to change it
Now I can send and control my sonoff relay with MQTT commands over MQTT.fx client (on a PC) to Mosquitto broker and get answers back on MQTT.fx again.
But I can’t use OH switches to control MQTT sonoff relay.
Maybe it is some kind of MQTT binding bug?
Can anyone help me to demystify it?
It stopped working when I did create new pass following this tutorial:
I deleted old password and pasted new generated one by hand to /etc/mosquitto/passwd
Changed mqtt.cfg accordingly
Stopped openhab service, deleted /var/lib/openhab2/config/org/openhab/mqtt.config
Started openhab service
Even tried to create new user and add.
Tried to enable “allow_anonymous” (with MQTT.fx I can send/receive without logging in, so again broker works, MQTT binding does not)
Tried to change broker name.
Tried to uninstall MQTT binding, install again, remove MQTT actions, install again.
Tried to restart RPi2 several times after I do something.
So far nothing helped.
MQTT CFG:
justas.url=tcp://192.168.0.68:1883
justas.clientId=klientas
justas.user=
justas.pwd=
justas.qos=0
justas.retain=true
#justas.async=async
justas.lwt=last will definition
to my knowledge, openHAB needs the password stored in mqtt.cfg, there’s currently no way to use a passwd-file
of course you can use a broker configuration without authentification (and openHAB can use that broker also)
with changing all that mqtt-configuration on-the-fly you almost certainly ran into a bug, please have a look here:
if clearing /var/lib/openhab2/cache and /var/lib/openhab2/tmp won’t work, you should have a look in /var/lib/openhab2/config/org/openhab/mqtt.config it should contain the same info (e.g. no credentials), if not, do as in the “Clear the Cache”-thread described and stop OH2, delete cache and tmp again but plus delete mqtt.config (or change accordingly), then start OH2 again
I meant I have changed Mosquitto broker password, so that OH could connect with password that is defined in mqtt.config. Now I can connect to Mosquitto broker with MQTT.fx (client installed on a PC for testing) using openhabian//openhabian, openhab//openhab or no authentication. But with OH MQTT binding I can’t. Tried no authentication.
Although there is Error in log file:
2018-02-01 16:15:02.802 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-02-01 16:15:02.811 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'justas'
2018-02-01 16:15:03.067 [ERROR] [penhab.io.transport.mqtt.MqttService] - Error starting broker connection
java.lang.IllegalArgumentException: null
at org.eclipse.paho.client.mqttv3.MqttConnectOptions.validateWill(MqttConnectOptions.java:168) [239:org.openhab.io.transport.mqtt:1.11.0]
at org.eclipse.paho.client.mqttv3.MqttConnectOptions.setWill(MqttConnectOptions.java:158) [239:org.openhab.io.transport.mqtt:1.11.0]
at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.openConnection(MqttBrokerConnection.java:344) [239:org.openhab.io.transport.mqtt:1.11.0]
at org.openhab.io.transport.mqtt.internal.MqttBrokerConnection.start(MqttBrokerConnection.java:99) [239:org.openhab.io.transport.mqtt:1.11.0]
at org.openhab.io.transport.mqtt.MqttService.updated(MqttService.java:115) [239:org.openhab.io.transport.mqtt:1.11.0]
at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updated(ManagedServiceTracker.java:189) [7:org.apache.felix.configadmin:1.8.16]
at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updateService(ManagedServiceTracker.java:152) [7:org.apache.felix.configadmin:1.8.16]
at org.apache.felix.cm.impl.helper.ManagedServiceTracker.provideConfiguration(ManagedServiceTracker.java:85) [7:org.apache.felix.configadmin:1.8.16]
at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.provide(ConfigurationManager.java:1479) [7:org.apache.felix.configadmin:1.8.16]
at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.run(ConfigurationManager.java:1435) [7:org.apache.felix.configadmin:1.8.16]
at org.apache.felix.cm.impl.UpdateThread.run0(UpdateThread.java:141) [7:org.apache.felix.configadmin:1.8.16]
at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:109) [7:org.apache.felix.configadmin:1.8.16]
at java.lang.Thread.run(Thread.java:748) [?:?]
never saw this error…
I know, the doc says user and password are mandatory, but in the mqtt.cfg file it says optional.
please try to comment out those two lines both in mqtt.cfg and afterwards in /var/lib/openhab2/config/org/openhab/mqtt.config, if it’s still in there.
Then stopped/started OH service, and those lines were again with no comment sign.
So commented again but it does not help.
Tried to change Mosquitto password back to the original, then in mqtt.config I input it as well openhabian//…
stopped/started OH service.
Can’t control with OH, can control with MQTT.fx
Then I have tried to install Mosquitto again through sudo openhabian-config (without uninstalling it first).
Now only one user left openhabian//openhabian.
Still not controlling through MQTT binding, only with MQTT.fx client.
What else I can reinstall, delete or change?
I can try to reinstall OH, if it’s the end of the route.
I’m not sure, if comment works in .config files, try to delete the file and let OH2 generate it again.
apart from that: if you have the broker running and it is reachable and usable from one Client - openHAB2 clearly can use it also with the same credentials. But be aware - openHAB2-MQTT binding won’t allow for the passwd-file (as you already know) - so, I would check:
Broker is running
Broker is reachable and usable from client
try mosquitto_pub or mosquitto_sub from the commandline from your openHAB server (Shows you, whether the openHAB server can reach the broker)
perhaps there’s another problem on another Level with openHAB reaching the broker.
Can you explain a little more on this, what do you mean passwd-file of MQTT binding?
I enter mqtt.cfg password and user, so it knows which credentials to give for Mosquitto broker.
If you mean that picture which is in the first post of this topic, then I did create file to get “encoded” version of the password, which I did input to Mosquitto /etc/mosquitto/passwd, since then, I do not use that file. Did you mean that file?
Broker is running. Because I can reach it with MQTT.fx client software.
Yes its usable, I can send and receive messages.
Yes I have tried that before, but here I tried that again:
yes, that is exactly, what I meant!
so, your broker runs on the same Pi as OH2 (openHABian) runs? Which is fine and running with others here in the Forum also. But you can Change the justas.url=tcp://lcoalhost:1883, just to see what happens here. (within the mqtt.cfg you didn’t use quotes, did you?)
2018-02-01 19:19:56.453 [ERROR] [org.apache.felix.configadmin ] - Cannot use configuration org.openhab.mqtt for [org.openhab.core.scriptengine.action.ActionService, org.osgi.service.cm.ManagedService, id=314, bundle=233/mvn:org.openhab.action/org.openhab.action.mqtt/1.11.0]: No visibility to configuration bound to mvn:org.openhab.io/org.openhab.io.transport.mqtt/1.11.0
There is also typo mistake in that Error line “penhab” instead it should be "openhab"
Maybe we can report this typo to developers?
I noticed, that there are two brokers some “justas” and “broker”.
Interesting.
Because it tries to stop “broker”, but before that nowhere it was started. Its just “justas” who is started before.
hmm… I have the feeling, your installation of openHAB is missing something.
Please uninstall all MQTT (binding and action) and reinstall.
that’s no typo, there’s simply not enough space for the logger to put in everything, it starts from right to left. there’s more missing, it should read: org.openhab.io.transport…
while you’re at it, please delete every mqtt-related config, both in /etc/openhab2/addons/ as in /var/lib/openhab2/config/org/openhab/ while mqtt (action and binding) is deinstalled.
Then start from scratch with your mqtt configuration (just to be sure, /var/lib/openhab2/config/... isn’t meant for you to edit, this will be created from the openHAB configuration at Startup.)