Cannot get ESP8266 to connect to MQTT

I’m trying to set up esp8266-midea-dehumidifier to work with Home Assistant. I’ve flashed the ESP8266 and have configured the WiFi and MQTT server details.

However, when it tries to connect to the Mosquitto broker, it says “Client disconnected, not authorised”. I’ve checked, and disabling authentication does allow it to connect correctly.

I’m not sure exactly where things could be going wrong here, as I’ve tried connecting to the broker from my PC with the same credentials, and it had no problems.

The code used for connecting to MQTT can be found here, if needed: esp8266-midea-dehumidifier/src/esp8266-midea-dehumidifier/esp8266-midea-dehumidifier.ino at 317e2295dde70d7b20d649d6f0dda061c608fb11 · Hypfer/esp8266-midea-dehumidifier · GitHub

Hello Daniel,

Specifically, don’t know… (Version 3, 3.1, 3.11, 5 thing maybe?)
Generally I would add another login and password than restart the add-on then use it for this device, just to be able to track things better in the log.
I would look at the broker independently to see what’s happening. MQTT-Explorer can help you be successful!
If you have Add-ons available, try adding this Add-on repository to your Add-on list. GitHub - GollumDom/addon-repository.
With this you can see that the broker sees and likely find the bug.

Hi again,

Apologies for the extremely late reply, as apparently attempting to disable discourse email spam I somehow managed to disable email notifications entirely!

Currently the log displays the following messages (with mosquitto verbose logging enabled), which doesn’t provide me with much information:

1766758619: New connection from redactedip:51194 on port 1883.
1766758619: Sending CONNACK to DEHUMIDIFIER-E8138C (0, 5)
1766758619: Client DEHUMIDIFIER-E8138C disconnected, not authorised.

I have tried connecting to the mosquitto broker with MQTTX, and have zero issues. Here is the mosquitto log from when I connected to test if the broker is functioning:

1766759145: New connection from redactedcomputerip:63957 on port 1883.
1766759145: New client connected from redactedcomputerip:63957 as mqttx (p5, c1, k60, u'homeassistant').
1766759145: No will message specified.
1766759145: Sending CONNACK to mqttx (0, 0)

This is causing me to be unsure of where the problem lies, as many people are using the esp8266-midea-dehumidifier project with no issues, and I have confirmed I’m able to connect to the broker successfully from my computer.


Edit: I’ve looked over the raw tcp logs of both connections and noticed that there are some differences. However I’m not experienced enough with MQTT to know exactly what to look for, and why this would be happening.

Dehumidifer (can’t connect):

07:03:48.759467 IP DEHUMIDIFIER-E8138C.iot.50298 > homeassistant.home.1883: Flags [P.], seq 1:126, ack 1, win 2144, length 125
E....i....(U..
:...
.z.[...?p...P..`B~...{..MQTT...
..DEHUMIDIFIER-E8138C.5esp8266-midea-dehumidifier/DEHUMIDIFIER-E8138C/status..offline....secretpassword

MQTTX client on computer (can connect):

07:03:12.476090 IP Testing-Laptop.home.49420 > homeassistant.home.1883: Flags [P.], seq 1:82, ack 1, win 2059, options [nop,nop,TS val 1652231867 ecr 3152942702], length 81
E.....@.@..........
...[.7O..:.l....X!.....
b{.....n.O..MQTT...<	...........mqttx..homeassistant..secretpassword