OH3: OH3 looses communication with Mosquitto

  • Platform information:
    • Hardware: Raspberry PI 3+
    • OS: openhabian-pi-raspios32-v1.6.2b.img
    • Sonoff Basic and Sonoff S26

Kind regards to the community.
I configured all the components, connected them and got them working with OH3. After a while, I notice that OH3 says: "COMMUNICATION_ERROR
CONNECT failed as CONNACK contained an error code: NOT_AUTHORIZED.
Mosquitto is running. I tested this with the MQTT Explorer tool on Windows.
Who can help me? How do I get stable communication between OH3 and Mosquitto?

First of all: where is your broker installed and how did you install and configure it?

Means: you could send and receive MQTT messages and your channels and items were updated accordingly? please be more specific, leave your broker configuration here (of course without the credentials), and describe when and how the connection breaks - otherwise we don’t have anything to help you

Yes, with the MQTT Explorer (a tool under windows) I can send and receive data. I just saw the following error message in OH3.
io.netty.channel.AbstractChannel$AnnotatedNoRouteToHostException: No route to host: /
I had deleted the MQTT Broker in OH3 and restarted the Raspy before. Then I created the broker again and I saw the above message

Please be more specific… We can’t help you that way. So either you don’t know what MQTT does and that’s why you see these errors, or you have a wrong configuration within OH3… in both situation we need what I asked for:

  1. a proper description of the steps you took (including the configuration within OH3)
  2. the errors you receive
  3. the surrounding information on how and what you did with MQTT explorer

Hallo und guten Abend Herr Binder, vielen Dank für Ihre Antworten. Ich beschäftige mich rein privat mit dem Thema und bin Ihnen dankbar für die Freizeit die Sie hier investieren. Ich bin ein absoluter Windows Nutzer und habe mit Linux quasi keine Erfahrung.
Nun zum Thema
Ich habe das zuvor genannte Image auf meinem Raspy installiert und untere zuhilfenahme eines Tutorials von Bangertech auch zum Laufen gebracht. Ich habe Schalter eingebunden und hatte bereits eine kleine Oberfläche auf dem Handy gestaltet.

Mit einmal war die Verbindung zwischen OH3 und Mosquitto OFFLINE. Alle Bemühungen es wieder zum Laufen zu bringen, sind bisher gescheitert. Es kann ja kein Programmierfehler sein, da ich keinen Code schreibe.
Mit Hilfe des MQTT Explorers auf meinem Laptop, kann ich auch auf den Mosquitto zugreifen, den Status der Schalter sehen und auch den Toggle-Befehl absetzen. Auch wenn ich die Schalter über die eigene Weboberfläche anspreche sehe ich die Reaktion im MQTT Explorer. Das heißt für mich Mosquitto läuft.

Ich habe bereits zweimal das Openhab Image neu aufgesetzt und neu begonnen. Dann bekomme ich das System auch zum Laufen. Nur nach einer Zeit X ist es wieder weg.

Beste Grüße
Joachim Artz

Noch etwas zur Installation. Ich habe zuvor genanntes Image installiert und aus dem Konfigurationsmenü heraus das Mosquitto installiert und eingestellt. Openhab und Mosquitto sind auf dem Raspberry installiert

Please remain in english, it’s the official forum language.
Second, please provide the configuration within OH3. If you can use the broker installed on the same raspberry as OH3 is installed (which works fine, nothing wrong with that…) that means, the Broker is live and running - but openHAB3 can’t use it. So, we need to make sure, this works.

And it’s ok if you’re a novice and that’s why we are here to help in the forum. But as described, we need more input… So please do the following:

  1. please read the MQTT-docs here:
    MQTT Things and Channels - Bindings | openHAB
    or here
    Getting Started with MQTT
    to get familiar on what MQTT does and does not
  2. then please describe what you did (I can read from your post, that you installed mosquitto from openHABian (which is crucial, because now we now, what broker you use and that you’re using the openHAB image) and then
  3. please post your configuration of the broker within openHAB, because the error must be inside this.

and if you like, please describe, what use case you’re after, meaning why do you need MQTT and what do you want to achieve with it - helps for context.

PS: and please, I’m not mad at you - it’s just, we need some more input other than “it doesn’t work”

No problem, we can continue in english.

  1. I have installed the OH-image and Mosquitto on the Raspy
  2. I opened OH in my Browser (Chrome)
  3. I installed the addon MQTT-Binding
  4. I went in the main menue to the item MQTT system broker connection
  5. Connection Name: MQTTBrokerJA / Broker Host: localhost / no further settings
  6. I went to Things and press MQTT-Binding
  7. I press MQTT-Broker
  8. Unique ID: no settings
  9. Label: MQTT Broker JA
  10. Broker Hoste Name: localhost
    And then I got the message: COMMUNICATION_ERROR

CONNECT failed as CONNACK contained an Error Code: NOT_AUTHORIZED.

On the Raspy I did a test
mosquitto_pub -d -t testTopic -m “Hello world!”

There I got the message
Client mosqpub|4527-openHABian sending CONNECT
Client mosqpub|4527-openHABian received CONNACK (5)
Connection Refused: not authorised.
Error: The connection was refused.

Remove that - it might not work as expected. It is something has needs removing, as it is a relic from the days that the MQTT Binding included its own broker. And it sounds like you’ve tried to setup two connections.

Instead, create a connection to your broker like this:

Presumably that’s because you didn’t provide your username and password in your command

When you set your Mosquitto broker up, did you choose a username and password? I’m not sure whether openhabian sets one by default…

Sorry, it was my mistake. I choosed MQTT Broker not MQTT system broker connection

OK, so you didn’t do these steps?

Or did you do these after this step?

As @binderth says, it really would make this a lot easier if you just showed us your configuration. For your MQTT Broker Thing, please go to the Code tab and copy/paste everything there in-between code fences.

I tried with and without a username / password. Both without success

UID: mqtt:broker:e8f29743a7
label: MQTT Broker JA
thingTypeUID: mqtt:broker
lwtQos: 0
publickeypin: true
keepAlive: 60
qos: 0
reconnectTime: 60000
host: localhost
secure: false
certificatepin: true
lwtRetain: true
enableDiscovery: true

Please read through the documentation I gave you above. It seems you don’t know how and why you use MQTT in the first place.

So, if you don’t know, if you configured your broker with username/password or not, it won’t make sense to go through further steps with your configuration… (…and what do you do with MQTT explorer anyways?)
Again: What’s your purpose of using MQTT in the first place?

You could compare your configuration from the MQTT Explorer with the one in the binding, if your Windows client is able to use the broker, you should simply use this configuration in openHAB.

It’s starting to get more frustrating for us, if you seem to just throw in something and don’t know yourself, what you’re doing:

My bet (don’t know, because we still lack crucial information) is, you configured mosquitto with login/password - but the configuration of your broker in OH3 misses this information. Again: please make sure, you understand at first, what you’re doing - then we can help you with specific information and we all don’t go in blindly…

Hello Thomas sorry that ist so difficult. But let me start again.
Today I’ve installed the newest version of OH3 and Mosquitto on my Raspy. I’ve installed Mosquitto with the user “openhabian” and a Passwort (2 letters and 6 numbers).
I downloaded the Addon MQTT-binding and activated Wifi.
This I did all on my Raspy.
I started the system and everything looked fine. Only I saw this line:
2021-01-28_18:00:40_CET [openHABian] Checking for default openHABian username:password combination… FAILED

Now I started the OH3 in Chrome on my notebook.

  1. I went in the menue Settings to the item MQTT system broker connection
  2. Connection Name: no / Broker Host: localhost / secure connection=off/ no further settings
    I went back to Things and press MQTT-Binding
    I press MQTT-Broker
    Unique ID: MeinBroker / Label: MQTT Broker / Broker Hostname: localhost
    And then I got the message: COMMUNICATION_ERROR
    CONNECT failed as CONNACK contained an Error Code: NOT_AUTHORIZED.
    openhabian@openhabian:~ $ mosquitto_pub -d -t testtopic -m “hello”
    Client mosqpub|4907-openhabian sending CONNECT
    Client mosqpub|4907-openhabian received CONNACK (5)
    Connection Refused: not authorised.
    Error: The connection was refused.

With my MQTT Explorer, running on my Notebook, I have no problems to connect to Mosquitto.
It doesn’t matter if I use a user/password or not.

UID: mqtt:broker:MeinBroker
label: MQTT Broker
thingTypeUID: mqtt:broker
lwtQos: 0
publickeypin: true
keepAlive: 60
qos: 0
reconnectTime: 60000
host: localhost
secure: false
certificatepin: true
lwtRetain: true
enableDiscovery: true

I think that you are right with the user/password in Mosquitto. But I don’t know, where is my mistake.

This is all informations I can give you and I’ve tried to communicate it so precise as possible. If that’s not enough for you, I’ll have to take an other way.

Sorry, I think here you are not right. It is the menue item below Other Services.

I’m aware what it is, but I am right. You’re not supposed to use that. Configure your broker using the tutorial I posted, or if you don’t believe me, use the documentation:

That one is really strange! but I have to stop you right here:

Did you install mosquitto with sudo openhabian-config and then chosing menu 23? With that comes an setup guide, which should ask you for username/password combination?

don’t ever use System MQTT broker unless you know exactly what you’re doing. MQTT broker (first entry in OH3-GUI) is the one for you.