MQTT connection failed rc -2 Topic is solved

For devices supporting the Auto Discovery feature. Like ZWaveJS2MQTT, Zigbee2MQTT.

Moderator: leecollings

Post Reply
User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

MQTT connection failed rc -2

Post by Rolandet »

Hi all,

I've spent some time going through the search, so forgive me if there's already a topic for this error (and hopefully with a solution)
If not, then I hope you can help me out:

Recently installed new SD card (old one FUBAR). Installed Domoticz etc and mqtt per Jelle Peters' youtube vid
Spoiler: show
https://www.youtube.com/watch?v=w7QhsFqBr30&t=7s
. as I have done many times before (be it a long time ago)

Now the problem I have is that my LSC smart plugs (flashed to tasmota) can not connect to the broker

Code: Select all

Connect failed to 192.168.178.24:1883, rc -2.
I've gone over several topics, about adding/removing

Code: Select all

listener 1883           allow_anonymous true
. etc but I just can not get it to work :(

Anyone here have the golden hint, or is willing to help me debug?

I realise I may have to add some more settings here, in order to troubleshoot. Please ask, and I'll add it a.s.a.p

tnx
Roland
Last edited by Rolandet on Wednesday 12 October 2022 18:13, edited 1 time in total.
Custodes Septentrionum
ferrosk
Posts: 44
Joined: Saturday 26 August 2017 20:13
Target OS: Linux
Domoticz version: 2023.2
Contact:

Re: MQTT connection failed rc -2

Post by ferrosk »

Hi,

By default mosquitto is running in local mode only (listening for connection on localhost interface so it is reachable only by clients running on the same host as mosquitto is running). You need to enable mosquitto to listen on your network (lan) interfaces - add this to conf:

listener 1883 0.0.0.0

but be aware that with this together with "allow_anonymous true" option you authorize connection to mosquitto from all hosts on your network without authentication so it is unsecure!



Domoticz 2023.2 on Odroid M1 and Armbian
MySensors (RFM69 Serial GW): bunch of DIY sensors/devices
Zwave (Z-Wave.me RaZberry board): Danfoss devices
Zigbee (Sonoff Dongle Plus): IKEA, Tesla devices
User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

Re: MQTT connection failed rc -2

Post by Rolandet »

Tnx ferrosk

I'm curious, is this a new feature/setting?
Cause I've used a quite old way of setting things up (hence the reference to the YouTube vid)
Custodes Septentrionum
ferrosk
Posts: 44
Joined: Saturday 26 August 2017 20:13
Target OS: Linux
Domoticz version: 2023.2
Contact:

Re: MQTT connection failed rc -2

Post by ferrosk »

It is default setting since mosquitto version 2.0.0:

https://mosquitto.org/blog/2020/12/vers ... -released/





Domoticz 2023.2 on Odroid M1 and Armbian
MySensors (RFM69 Serial GW): bunch of DIY sensors/devices
Zwave (Z-Wave.me RaZberry board): Danfoss devices
Zigbee (Sonoff Dongle Plus): IKEA, Tesla devices
User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

Re: MQTT connection failed rc -2

Post by Rolandet »

I see. That would explain why my old rpi4 installation (mosquito v1.5.7) doesn't have this issue (to be fair, this topic is about another users setup)
Custodes Septentrionum
User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

Re: MQTT connection failed rc -2

Post by Rolandet »

ferrosk wrote: Tuesday 11 October 2022 21:10 Hi,

By default mosquitto is running in local mode only (listening for connection on localhost interface so it is reachable only by clients running on the same host as mosquitto is running). You need to enable mosquitto to listen on your network (lan) interfaces - add this to conf:

listener 1883 0.0.0.0

but be aware that with this together with "allow_anonymous true" option you authorize connection to mosquitto from all hosts on your network without authentication so it is unsecure!
I've gotten a little further thanks to your suggestion.

In /var/log/mosquitto/mosquitto.log I see:

Code: Select all

Config loaded from /etc/mosquitto/mosquitto.conf
But the device still shows the same error, like mosquitto hasn't properly read the conf file

After a reboot I see the process running:

Code: Select all

PID 517 /usr/sbin/mosquitto -d
Im not sure, but it looks like that would suggest the conf file is not read.

When I kill this process and restart it using sudo systemctl start mosquitto the new PID shows:

Code: Select all

PID 5825 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Now it DOES allow my device to connect (and indeed I can control it from Domoticz)

So somehow the start of mosquitto after reboot doesn't seem to load the conf file
Where can I see what parameters are passed when a program is started automatically after boot?
Custodes Septentrionum
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest