MQTT Connection Failure

I have a basic sonoff device flashed with Tasmota.
The device is discovered by WIFI and all looks well.
But I can not connect it to MQTT. I receive an error as follows…
Connect failed to 192.168.1.15:1883, rc -2. Retry in 10 sec
I have used both my hassio user name and password, and a MQTT user I created in the MQTT config on the Tasmota page.
I have read most of the posts in the forum in regards to this but am just plain stuck.
I am using v 0.105.2, running in an unRAID VM, with an IP of 1192.168.1.15, I am also on a Unifi network.
Let me know what other information you may need.
Thanks
carltonb

Hi there. Go to the “Console” in the “Tasmota Menu” and enter the following in the field: “setoption19 1” (without “”). Also had the problem that the sockets were not displayed in HA, so it worked. I wish you success.

The config of my “Mosqiotto Broker” addon looks like this …

Thank you for the quick reply and the help.
I have my MQTT config exactly as your set with the MQTT special user and password.
After a restart i get the following…
1581278917: New client connected from 192.168.1.15 as auto-0AEF7B43-9331-E75B-95D6-93590F48BF4A (p2, c1, k60, u’cwbmqtt’).

I then have also tried setoption 19 1, but no luck. I still get the rc -2 can not connect error.
There has to be something else I am missing.

The device was flashed with tasmota.bin since there is no more sonoff.bin.

Also I should say (forgot) that I use nabucasa.

Is there a log file to look at?
carltonb

Maybe a stupid question… but, is your mqtt broker working? It looks like your plan is to use the mqtt addon on home assistant.
Have you installed it and configured it properly? Any other mqtt device on your network using the broker successfully?
GV

Sorry the error message says nothing to me. Unfortunately I can not help, good luck and success with the solution …

What I would is install mqtt.fx on your computer and check if the mqtt broker is working

Installed mqtt.fx
Set it up with my servers hassio ip address.
Added username and password. It connected.
Subscribed to topic, published a text message, went back to subscribe and message showed up.
Based on what I can tell it seems to be working.

Anything else in mqtt.fx I should try to verify it is working?

Thanks
carltonb

Next get mqtt.fx look at one of your mqtt lights switches and u should see the messages that that cear of mqtt that’s telling me mqto broker working all good then I would double check tasmota setting

Mqtt is working but still getting the error. Going to have to look at the router and my UniFi system to see if something is being blocked.

Many thanks for the help.

Well I did figure something out after reading more posts.
My device was on a UniFi vlan of 192.168.20.1 (My IoT network)
I changed the device to my non wlan of 192.168.1.1 and the device started to work in mqtt.

Now if any one knows is this a UniFi setting or a home assistant setting.
Do I need to “allow” the vlan address in home assistant?

Any thoughts appreciated.
carltonb

I think I have the same problem could you explain what UniFi means. is it the smart connection 5g and 2.4g? please help

Sorry for the late reply I was out of town.
UniFi is a Ubiquity Unifi Controller.
I have a UniFi Security Gateway 3P router hooked up with a UniFi Cloudkey Gen 2.
After a bunch of rebooting and changing MQTT it all started working.
Now ALL of my devices are on MQTT.

By chance did you solve this problem? When I have my device on my IoT (192.168.2.0/24) network it also cannot reach the MQTT server on the default lan (192.168.1.0/24). The LAN can reach it, however.

Did two things to make it work.
I took it off my VLAN network and used the setting of “setoption 19 1”
Then everything started to work.

Strangely, and this is probably a thing, I had 3 networks setup in Unifi. Two of them were VLAN with the IDs of 2 and 3. I changed the networks to be 20 and 30 and changed from 192.168.2.0/24 and 192.168.3.0/24 and bumped them to 192.168.20.0/24 and 30.0/24 and the problem went away. I suspect because I previously had one network of 192.168.1.0/20 that there was some sort of conflict.

Either way, once these two networks were reconfigured and the devices reconnected to their own WIFI SSID, they landed where they needed to be and were able to communicate across VLANS.

i know when i was having mqtt issues, it was a firewall rule. I had a rule denying traffic from my 192.168.70.0 vlan to 192.168.10.0 lan.