Hello again,
I am now having trouble to connect tp the MQTT server installed in my Raspberry pi.
I am following the instructions in the course “Build a Home Automation System for $100”.
It all works well until Module 7 – Unit 1.
I have Node-Red and mosquitto (v. 2.011, on port 1883) installed in the RPI, all parts up to here worked well,
Putty finds the RPI and I can connect and execute commands remotelly from a windows computer.
But when I try the program on Unit 1 (page 118) I cannot manage to get a connection.
I have always a message: Connection failed rc=-2…
On Node-Red the flow shows the status of the nodes as ‘connected’, but no message is received.
What could be possibly wrong?
Thanks,
Jayme
Hi.
Did you insert the Raspberry Pi IP address on your ESP code?
Did you change anything on the code? Have you modified the topics?
Did you edit the Node-RED MQTT nodes to use the localhost as Mosquitto broker?
Regards,
Sara
Hi Sara, yes I have the same IP address in the ESP code (same IP that tested ok with Putty).
No, I have made no changes to the code, only changed the wifi data and RPI IP.
One thing seems strange to me. To access the RPI using PUTTY, I have to supply the RPI user and password. But I don’t see that on the ESP code. The rc=-2 means it failed to connect to network, right? Isn’t it because it can’t log to RPI as user/pswd is missing?
I have MQTT broker defined on Node-red nodes as localhost:1883, but nowhere I specified that the broker is Mosquitto. Is that necessary?
thanks!
Jayme
Hi again.
I’m really sorry for that issue.
I think it is related to the newest mosquito version.
It requires some additional steps during installation. That is not covered in the eBook because at the time of writing the book, mosquito was on version 1.
Can you check this tutorial and install the mosquito broker again, but following these instructions: https://randomnerdtutorials.com/how-to-install-mosquitto-broker-on-raspberry-pi/
Let me know if this solves the issue.
We really need to update the Home Automation eBook and we’ll start working on that soon.
Regards,
Sara
Hello Sara, I tried the indicated solution, but I am sorry to say that the result is still the same.
I included the 2 lines in the Mosquitto config file, saved it restarted the Pi.
I also downloaded a fresh program listing, and changed the parameters, paying attention to the correct pi IP address (confirmed once again with Putty, which connected perfectly).
I can ping and also ssh the pi from my windows desktop.
But still receive same rc=-2 error message when running the sample in page 118.
I am really confused about what could be the issue, since it does not seem to be on the Pi side, as it is responding to putty, ping and ssh.
To me it looks like something is missing in the ESP8266 program to be able to connect to the pi (even before accessing Mosquitto).
Any other ideas about what I could try?
Thanks a lot for your support!
BR
Jayme
Hi.
I tested the setup and the ESP8266 is connecting properly to the Mosquitto broker.
Are the ESP8266 and the Raspberry Pi on the same network?
How did you get the Pi IP address? Can you show me the line of code where you insert the IP address?
I think you might need to uninstall mosquito and install it again with the new instructions. Maybe the changes didn’t take effect.
Regards,
Sara
Hi Sara, thank you for your support.
just to give you a quick feedback that the issue was solved.
for some reason I was having error messages when the config file was loaded, but didn’t realize that.
I took out all lines leaving only the two added for version 2 of Mosquitto. Somehow that solved the issue.
Thanks again,
Jayme