Closed WongGendheng closed 4 years ago
If you have already created the user you're trying to login with, there's no need for "logins": [] in your broker config. In fact, I believe it's a list of users that you want the add on to create for you. Try removing it, restart the broker and login again wirh your nodemcu to see if that helps.
@johanson Thank you very much for bothering with my post. In fact, a user on Reddit spotted the mistake and - I feel ashamed just writing this - it was a wrong IP adress.
192.168.0.106 used to be my Home Assistant instance before I made a full whipe on the SDcard and reinstalled Home Assistant. While 192.168.0.106 was up, the code was not working properly, hence I focused on getting it to work. Somewhere around that time my code didn't work I made the clean install of Home Assistant. My mistake was to keep copying the header part of the code from the old sketch to the new one - for convenience.
Now, everything works as expected - except for my ego, which is a bit fragile at the moment from not spotting this easy mistake.
Closing now.
My problem was that the WiFi was not in the channel the ESP like. So changing the WiFi AP to channel 6 made it work right away. Thanks for the sample code
Hey there,
I searched far and wide for a solution to connect my NodeMcu to my Hass.io Mosquitto broker, yet I'm always receiving the "Connecting to MQTT...failed with state -2" error message. Connecting to test.mosquitto.org works just fine. I hope to gain new insights from this post; anything that could help me is highly appreciated.
My setup:
--Home Assistant-- I have a fresh install of Home Assistant 0.104.2 running on a Raspberry Pi 3B. I installed Home Assistant with the latest image I flashed with Etcher - nothing fancy. I installed the Mosquitto broker through the official add-on store. Apart from that I installed the Configurator and SSH server add-ons through the official store.
--NodeMcu-- I programmed my NodeMcu with version 1.8.9 of the Arduino IDE. It can connect to the test.mosquitto.org server without username and password. Which makes me confident that my code actually works.
My MQTT setup:
1) The MQTT config in the add-on is configured as follows:
2) Ports are configured like this:
3) Here are the current logs I found in the add-on:
4) Under configuration --> user, I created the user "dustinmqtt" with "dustinmqtt" as password. It has administrator privileges.
5) Under configuration --> integrations, the "MQTT: Mosquitto broker" is listed .
6) My configuration.yaml is fresh and nothing has been added.
Testing MQTT broker succesful:
I have several reasons to assume my MQTT broker is working correctly: 1) Under developer tools --> MQTT, I can publish packages and listen to topics. 2) With MQTT.fx 1.7.1, I can connect to my MQTT broker through port 1883, with the IP of Home Assistant and the username and password "dustinmqtt". Messages I publish in MQTT.fx can be seen in the developer tools of Home Assistant and vice versa. 3) I can run the following commands and see the expected results:
My code on the NodeMcu:
The code compiles perfectly and does connect to test.mosquitto.org. All I needed to do was to comment out the parts of the code that deal with mqttUser and mqttPassword. This is why I think the problem lies somewhere along the lines of "logging into my MQTT broker with username and password". What confuses me is that I can connect to my MQTT broker with my username and password just fine while using MQTT.fx.
My questions: 1) Is there anything I can do to troubleshoot? Im losing my mind here. 2) The username and password are passed to client.connect() as const char*. Could there be a problem with that in connection with using Mosquitto on Home Assistant? Though according to the pupsubclient documentation this is the correct way to do it: boolean connect (clientID, username, password) 3) Are there any known issues of pubsubclient not working with Mosquitto broker that I might be missing? 4) Is there anything I could add to my configuration.yaml to make this problem go away? I tried adding the following, but several sources said I do not actually need to add this. Either way, it didnt affect my situation:
Cheers Dustin