Hello Sara!
I’m reading the Raspberry Pi Pico module12 and I’m trying to get it to connect to my local RPI4, running a Mosquito Broker and Node-Red and it works fine, I have been using it for a few years.
I have created a config.py with the correct password and user for my local RPI4 and I got this message when I try to run the script 12_3_mqtt_publish.py:
Waiting for Wi-Fi connection…
The connection was successful!
IP address: 192.168.1.192
Error connecting to MQTT: [Errnr 104] ECONNRESET
Error: [Errnr 104] ECONNRESET
So what am I doing wrong?
Greetings
Anders
I put the port number in config.py and now I got this error:
Waiting for Wi-Fi connection…
The connection was successful!
IP address: 192.168.1.192
Error connecting to MQTT: -2
Error: -2
And of course I get no values in Node-Red
And the RPI4 is online and I can ping it and it also publishing other temperatures.
Hi.
What’s the name of the Raspberry Pi Pico as an MQTT client?
Do you have other devices on the network with the same name?
Regards,
Sara
The name is: raspberrypi_picow
and no I have not any more devices on the network with the same name.
I don`t think I should have the portnumber in the config.py file? I think the simple.py have the portnumber 1883. And if I just have the ipadress in the config.py I got this error:
MPY: soft reboot
Connection successful!
IP address: 192.168.1.192
Error connecting to MQTT: [Errno 104] ECONNRESET
Error: [Errno 104] ECONNRESET
The RPI4 is set up from your description https://randomnerdtutorials.com/how-to-install-mosquitto-broker-on-raspberry-pi/
Hi.
can you show me how does your mosquito configuration file looks like?
Regards.
Sara
pid_file /run/mosquitto/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
listener 1883
allow_anonymous true
Ok I think I understand, I don`t have to use a password or a username for my others ESP32 for temperature measurements connecting to the brooker.
So to change in simple.py would it solve this? Or what to do?
Thanks Sara
I set up another RPI5 with mosquito and Node-Red and set it up with user and password. The config for this is :
per_listener_settings true
# 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
pid_file /run/mosquitto/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
allow_anonymous false
listener 1883
password_file /etc/mosquitto/passwd
But the result was the same as before 🙁
MPY: soft reboot
Connection successful!
IP address: 192.168.1.192
Error connecting to MQTT: [Errno 104] ECONNRESET
Error: [Errno 104] ECONNRESET
Regards
Anders
The RPI5 din`t start the Mosquitto service so I took it away and took a RPI3 instead and now the service is running
Active: active (running) since Sun 2024-04-28 10:09:22 CEST; 2min 53s ago
And the config file for the RPI3:
# 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
per_listener_settings true
pid_file /run/mosquitto/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
allow_anonymous false
listener 1883
password_file /etc/mosquitto/passwd
But I got the same error on the RPI3:
MPY: soft reboot
Connection successful!
IP address: 192.168.1.192
Error connecting to MQTT: [Errno 104] ECONNRESET
Error: [Errno 104] ECONNRESET
This is from the mosquitto log file:
1714295274: mosquitto version 2.0.11 starting
1714295274: Config loaded from /etc/mosquitto/mosquitto.conf.
1714295274: Opening ipv4 listen socket on port 1883.
1714295274: Opening ipv6 listen socket on port 1883.
1714295274: mosquitto version 2.0.11 running
I took one ESP32 and DS18B20 for testing. And when I put in this it works:
mqttClient.setCredentials(“lovfall”, “password”);
So the brooker works and I get the temperatures into Node-Red.
So there is someting wrong with the pico program.
I will download the files again and try again.
Regards
Anders
I deleted all files in Pico and downloaded the files again, but no luck.
Connection successful!
IP address: 192.168.1.192
Error connecting to MQTT: [Errno 104] ECONNRESET
Error: [Errno 104] ECONNRESET
In the mosquitto log I can see that both ESP32 and the Node-Red (RPI3) is conneting.
But nothing about that the Pico is trying to connect.
Both the ESP32 and the Pico is using the same wireless network and also from the same distance.
To me it seems thath it`s not conneting at all, it goes so fast when the error code appears and you don`t get anyting in the mosquitto logfile.
Have someone manage this to work with an local brooker? Any suggestions would help. Because now I am out of any ideas.
Thanks
Hi again.
I’m sorry for the delay in my response. I’m currently out of the office with limited access to the internet.
Where do you have your config.py file located? Double-check that the config.py file is located on the right place..
Please don’t remove the b’ character from where it is located on the file… can you also double.check it?
Regards,
Sara
Hello!
When I go in the PI Pico I see a folder called umqtt and in that folder I have the 2 files robust.py and simple.py.
Outside thath folder I have 12_3_mqtt_publish.py , BME280.py and the config.py.
And in the config.py you have the ssid and password and I get that the connection is succesful and I don`t think you would have that if the config.py file would be in the wrong place. Yes the 3 files mqtt have the b’ And as I mention before I have deleted all the files in the Pi Pico and download them again to get everything “fresh”
And I always copy and past names of the files and ofcourse the code also. So I “never” type the names or code by hand.
And I have also tested, Displaying BME280 Sensor Data on OLED Display and others and all of them works.
And I have also put an incorrect password in the cofig.py to see if I will get something in the mosquitto logfile, but I don`t get anything in the log-file, that the Pi Pico is trying to connect. But both Node-Red and the ESP32 with the temperature messure is in the file.
Regards
Anders
This is my config.py for the RPI3:
wifi_ssid = ‘xxxxxx’
wifi_password = ‘xxxxxxxxxx’
mqtt_server = b’192.168.1.20′
mqtt_username = b’lovfall’
mqtt_password = b’xxxxxxxxxxxx’
The 192.168.1.20 is my temporary RPI3 with mosquitto and brooker, And you have to use username and password
I have connected one temperature measurement with an ESP32 and DS18B20 and it works I get readings in Node-Red.
And my ordernary brooker and mosquitto with 15 temperature measurements also work so they dosen`t interfering with each other.
Hi.
Thanks for the provided information.
It seems you’re doing everything right… I’m not sure what can be wrong.
Ill be back at the office next week. So, I can try to test everything when I get back, to make sure nothing has changed meanwhile….
Regards,
Sara
Hello!
I have been testing with Pico as a Web Server to be sure the wifi works. And I get the web-page where I can control the led and also the readings from the BME280 sensor. So everyting is correct with the wifi also.
Hi.
I just got back to the office and tested everything with the Mosquitto broker.
I found out the issue.
Since you’re connecting to your local mosquito broker, you’re not using SSL. So, you need to change the following line on the Raspberry Pi Pico code:
MQTT_SSL = True
to
MQTT_SSL = False
In the configuration file you should use the mosquito MQTT IP address without the port.
It is working for me this way.
Let me know if this solves your issue.
Regards,
Sara
Hello Sara!
MQTT_SSL = False solve it.
Yes it works on both on my ordenaire RPI4 and the temperary RPI3, the only thing in the config.py I hade to change was the ip to the brookers. So the issu is solved.
Regards
Anders