MQTT disconnects

I understand this is a common problem, however none of the topics I have read answer my questions.

What exactly do I have to do in order to get this working?

I have (I think) a MQTT server running, and OpenHab seems to like it, but when I start the client MQTT.fx, Openhab throws an error every 2 seconds that it is disconnected.

When I close the client, Openhab behaves again.

If no other client can connect to this, how on earth can I test it?

Is this normal?

Thanks in advance for any help you can give.

If you want logs, files (or locks of my hair that I have pulled out) please let me know.

This is always a good starting point:

You are probably using the same client id as openHAB when you connect with MQTT.fx.

Each client must have a unique id and at least with Mosquitto it will kick OH off the broker when another client connects with the same id.

You are 100% correct, changed the Client ID and it doesn’t kick me out anymore, many thanks.

I have noticed that device (or item) states don’t update with their new state in BasicUI, is this normal?

No, they should update fairly quickly.

Have you verified via the logs that the items are changing?

What browser are you using?

What operating system?

What version of OH?

All my other items update, just not the mqtt one.

The items do indeed change via the logs, just no visual update, however they do update on my iPhone openhab app.

Using chrome on windows 7 ultimate. edit You might have meant what OS OH is on… that is a Rpi3.

Latest version of openhab2.

It’s strange, if I open 2 browsers and point them both at basicUI, my other items synchronise (if I switch on a lamp on 1, it shows on the other), this doesn’t happen with the mqtt item.

I also don’t get the item at all in PaperUI (no item in the Control tab), it just isn’t there.

Just a thought… do all my subscribed topics have to start with ‘openhab’?

I mean, at the moment my topic is ‘flat/test’.

Should it be ‘openhab/flat/test’?

The reason I ask is that when I start mqttlens and subscribe to # (everything), I get a message posted to ‘openhab/flat/test’, and directly after a message posted to ‘flat/test’, even though there is no such topic. I know I could simply subscribe to the topic explicitly and wouldn’t get that posting, it just confused me why it is there.

Latest stable? Latest snapshot?

Did you even read my link above???

Yes, that’s how I found out about MQTTlens, which I prefer, before that I was using MQTTfx.

However, since your question seems rhetorical, I just read it again, it doesn’t mention anything about topic prerequisites.

No idea. But I have just SSH’d into the server and it says 2.1.0 Release build. Whatever that means. The only reason I think it’s the latest version is because I did an apt-upgrade thingy a few days ago. All this Raspeberry Pi tomfoolery doesn’t exactly speak to my skill set.

Please excuse my ignorance.

Many apologies, when you asked ‘Did you even read the link above?’, I did not presume you actually meant ‘Did you even read the link above, and follow all the links on that page, and follow all the links on the pages the links had within those pages?’ As such I would like to change my answer.

No, I did not even read the link above.

What I actually did was read only the first link (above), and follow the step-by-step.

Having read section 5, as suggested, it is still ambiguous as to whether subscribed topics have to start with a particular prefix, since the only topic I have is ‘flat/test’ then ‘flat’ could be considered my top-level topic, and as such satisfies any future topics where ‘flat’ is also the top level topic, although there is a whole paragraph that states multiple topics with differing top level topics can be maintained on the same broker.

My question was more to inquire if openhab itself added ‘openhab’ as a top level prefix to its MQTT topics prior to publish or subscribe.

It is entirely possible that I have a remnant of an old topic I created during testing that still exists in some form, somewhere, and is getting reported during a wildcard subscribe.

Then this could be a solution:

Apparently brokers retain topics indefinitely.

For those wanting to purge old topics, this is what I found.

Delete all the topics. It worked for me.

sudo service mosquitto stop
sudo rm /var/lib/mosquitto/mosquitto.db
sudo service mosquitto start

Devices wont show current statuses until they publish again, because there will be no topic available, which is a drawback, but at least you’ll have a nice clean broker.

Hope that helps.

1 Like