[SOLVED] MQTT - Failed to connect to broker

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
dampa
Normal user
Posts: 38
Joined: 19 Jul 2018, 01:48

[SOLVED] MQTT - Failed to connect to broker

#1 Post by dampa » 09 Aug 2019, 12:53

Up to a couple weeks ago, all my ESPEasy devices were working fine but suddenly they are all failing to connect to my local MQTT brokers (using either the hostname or the IP) with the error:

15651: MQTT : Intentional reconnect
15713: MQTT : Failed to connect to broker

All devices work fine when connecting to a cloud broker. The version of ESPEasy doesn't seem to matter, it happens using
mega-20190805,
mega-20190106,
mega-20181026

What is strange is that the broker (mqttpizw.local) works in all other cases and even works if I take a WeMos running ESPEasy (which won't connect) and flash it with an Arduino sketch doing MQTT. Here are the things that work

Pi -> MQTT -> Pi
------------------------
NR on rosemarypi ——> mqttpizw.local ——> NR (on mac) works

WeMos (ESPEasy) -> MQTT -> Pi
--------------------------------
wemos42 ——> beebotte ——> NR (on mac) works
wemos42 ——> mqttpizw.local ——> NR (on mac) FAILS
wemos42 ——> 192.168.48.102 (mqttpizw.local) ——> NR (on mac) FAILS

wemos33 ——> mqttpizw.local ——> NR (on mac) FAILS

NOTE: wemos33 was now flashed with an Arduino sketch using MQTT pointing at 192.168.48.102
WeMos (arduino) -> MQTT -> Pi
————————————————
wemos33 ——> 192.168.48.102 (mqttpizw.local) ——> NR (on mac) works

I thought it might have been a firmware update to my apple base station, but I downgradded the firmware and still have the problem.


Any thoughts/suggestions.
Last edited by dampa on 09 Aug 2019, 23:19, edited 1 time in total.

User avatar
ThomasB
Normal user
Posts: 385
Joined: 17 Jun 2018, 20:41
Location: USA

Re: MQTT - Failed to connect to broker

#2 Post by ThomasB » 09 Aug 2019, 19:25

Several ESPEasy devices breaking at the exact same time seems unlikely. So, I agree something has likely changed in the broker's configuration (which has impacted the chosen controller settings used in the ESPEasy devices).

Some things to try can be found in this discussion:
viewtopic.php?t=5691

- Thomas

dampa
Normal user
Posts: 38
Joined: 19 Jul 2018, 01:48

Re: MQTT - Failed to connect to broker

#3 Post by dampa » 09 Aug 2019, 22:25

Just found another clue. I went and looked at the mosquitto log on the pi (/var/log/mosquitto/mosquitto.log) and I see this

1565375291: New connection from 192.168.48.42 on port 1883.
1565375291: Socket error on client <unknown>, disconnecting.
1565375321: New connection from 192.168.48.29 on port 1883.
1565375321: Socket error on client <unknown>, disconnecting.
1565375351: New connection from 192.168.48.23 on port 1883.
1565375351: Socket error on client <unknown>, disconnecting.

Every one of those IP are a wemos with ESPEasy running

Is this a mqtt version issue? the Pi is running
pi@mqttpizw:/var/log/mosquitto $ mosquitto -v
1565382066: mosquitto version 1.4.10 (build date Wed, 13 Feb 2019 00:45:38 +0000) starting

How do I sepcify a client id?

TD-er
Core team member
Posts: 1368
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: MQTT - Failed to connect to broker

#4 Post by TD-er » 09 Aug 2019, 22:35

What timeout value is being used on the broker side?
It used to be 10 sec as default for Mosquito, but I guess it could have been lowered in the settings?

You can test by setting a LWT in some MQTT controller and look at the broker to see if the ESPeasy node is considered to be disconnected.
For these kind of tests, I normally use a separate topic and a MQTT viewer like MQTTbox. But any viewer is fine as long as you can see the live data.

User avatar
ThomasB
Normal user
Posts: 385
Joined: 17 Jun 2018, 20:41
Location: USA

Re: MQTT - Failed to connect to broker

#5 Post by ThomasB » 09 Aug 2019, 22:46

Code: Select all

 Socket error on client <unknown>, disconnecting.
That is an error that can be reported if the controller's user name or password is wrong. Also, reboot your router(s) in case their IP tables are confused.

- Thomas

dampa
Normal user
Posts: 38
Joined: 19 Jul 2018, 01:48

Re: MQTT - Failed to connect to broker

#6 Post by dampa » 09 Aug 2019, 23:19

TD-er, ThomasB

Thank you for looking at this the problem was with the mosquitto configuration file. I got a copy of dynamicdave's configuration file and once I put that in, it started working. I was not using userid and passwords and I think the missing 'allow_anonymous true' might have been the issue.

this is what I get for updating systems without a complete backup :oops:

Here is the working mosquitto configuraton file:
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

user mosquitto
max_queued_messages 200
message_size_limit 0
allow_zero_length_clientid true
allow_duplicate_messages false

listener 1883
autosave_interval 900
autosave_on_changes false
persistence true
persistence_file mosquitto.db
allow_anonymous true
log_dest file /var/log/mosquitto/mosquitto.log

# include_dir /etc/mosquitto/conf.d

User avatar
ThomasB
Normal user
Posts: 385
Joined: 17 Jun 2018, 20:41
Location: USA

Re: [SOLVED] MQTT - Failed to connect to broker

#7 Post by ThomasB » 10 Aug 2019, 00:30

Glad to hear you solved it.
- Thomas

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests