Comments on: Raspberry Pi Pico W: Getting Started with MQTT (MicroPython) https://randomnerdtutorials.com/raspberry-pi-pico-w-mqtt-micropython/ Learn ESP8266, ESP32, Arduino, and Raspberry Pi Thu, 03 Apr 2025 23:52:15 +0000 hourly 1 https://wordpress.org/?v=6.8.2 By: DG https://randomnerdtutorials.com/raspberry-pi-pico-w-mqtt-micropython/#comment-1022902 Thu, 03 Apr 2025 23:52:15 +0000 https://randomnerdtutorials.com/?p=151437#comment-1022902 In reply to Kay.

What generates this error? “Error connecting to MQTT: -2”

How do you fix it.. the config is clearly correct

Using mosquitto version 2.0.11 starting as the broker in ‘anonymous’ mode

]]>
By: BrewGeek https://randomnerdtutorials.com/raspberry-pi-pico-w-mqtt-micropython/#comment-1022844 Thu, 03 Apr 2025 18:01:38 +0000 https://randomnerdtutorials.com/?p=151437#comment-1022844 In reply to Kay.

Got the same problem.. What is the solution?

]]>
By: Sara Santos https://randomnerdtutorials.com/raspberry-pi-pico-w-mqtt-micropython/#comment-1012815 Mon, 03 Mar 2025 08:55:20 +0000 https://randomnerdtutorials.com/?p=151437#comment-1012815 In reply to Paul Newland.

Hi.
You just need to create the files explained in the procedure.
That name is the name I gave to the file with the main code to be saved on my computer.
You don’t need to create any file with that name. That is just the main file.
Regards,
Sara

]]>
By: Paul Newland https://randomnerdtutorials.com/raspberry-pi-pico-w-mqtt-micropython/#comment-1012196 Sat, 01 Mar 2025 17:28:08 +0000 https://randomnerdtutorials.com/?p=151437#comment-1012196 I really like the detail of this tutorial. Well done!

However, I’m having a bit of a problem following your procedure. With the right side scroll bar adjusted to go about 40% down the page, a screen capture is shown of the Thonny window. In that widow are several tabs with associated file names. It appears in that screenshot that the displayed code is for a tab with filename “publish-MTQQ.py”, but I don’t see anywhere in the tutorial text where you told the reader to create a file called “publish-MTQQ.py” and where you told the reader what to put in that file. I realize that there’s a lot of code discussed in the tutorial that’s probably intended to go into file “publish-MTQQ.py”, but I don’t think you told the reader to put that code in that file. So I’m sorta stuck at this point. Perhaps for someone not starting from scratch as I am would be obvious what to do, but I’m just starting with Thonny, Python and MQTT, so I need a little more detail. Thank you.

]]>
By: Jose Barbosa https://randomnerdtutorials.com/raspberry-pi-pico-w-mqtt-micropython/#comment-1010725 Mon, 24 Feb 2025 23:03:35 +0000 https://randomnerdtutorials.com/?p=151437#comment-1010725 Hi , thanks again for a great tutorial on such an important topic.
I got it to work, using a pico with this code and a Pi with Mosquitto and the code to pub/sub that talks to this one.
Took me quite some time to get the MQTT version errors to go away… but that seems solved
Now I need to try QoS and set it to 2. I have too many errors on subscribing at the Pico when the Pi loops through publish messages even with a good delay between them (1 sec)
Where do I need to change QoS ? I see it referred several times in simple.py. Not sure if I need to change ALL QoS=0 to 2
THANK YOU

]]>
By: Kay https://randomnerdtutorials.com/raspberry-pi-pico-w-mqtt-micropython/#comment-989343 Fri, 06 Dec 2024 22:03:05 +0000 https://randomnerdtutorials.com/?p=151437#comment-989343 Hi,

Thanks for all your great tutorials!
But can you please help me with errormessage: “Error connecting to MQTT: -2”? I checked all config.py
I have a broker running on another Rpi, on the same WiFi network.

Thanks al lot!
Kay

]]>
By: Sara Santos https://randomnerdtutorials.com/raspberry-pi-pico-w-mqtt-micropython/#comment-989205 Fri, 06 Dec 2024 10:26:58 +0000 https://randomnerdtutorials.com/?p=151437#comment-989205 In reply to Iain.

Hi.
Please read the instructions carefully about uploading the libraries.
Please note that you should create a file called umqtt, and then upload the files robust.py and simple.py to that folder.
https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2024/03/umqtt-modules-installed-successfully-thonny-ide.png?w=750&quality=100&strip=all&ssl=1
Regards,
Sara

]]>
By: Iain https://randomnerdtutorials.com/raspberry-pi-pico-w-mqtt-micropython/#comment-988761 Wed, 04 Dec 2024 17:33:48 +0000 https://randomnerdtutorials.com/?p=151437#comment-988761 Thanks for the Tutorial.
I am getting the error
MPY: soft reboot
Traceback (most recent call last):
File “”, line 7, in
File “umqtt/simple.py”, line 6, in
AttributeError: ‘module’ object has no attribute ‘MQTTClient’
Where should the file publich_MQTT.py be located on the raspberry pi pico?

Thanks
Regards
Iain

]]>
By: Sara Santos https://randomnerdtutorials.com/raspberry-pi-pico-w-mqtt-micropython/#comment-984062 Mon, 18 Nov 2024 18:13:04 +0000 https://randomnerdtutorials.com/?p=151437#comment-984062 In reply to George.

Hi.
That’s probably because the credentials are not correct or the broker URL.
Regards,
Sara

]]>
By: George https://randomnerdtutorials.com/raspberry-pi-pico-w-mqtt-micropython/#comment-984019 Mon, 18 Nov 2024 12:18:24 +0000 https://randomnerdtutorials.com/?p=151437#comment-984019 Hi
I tried your code
only difference is I use a simple dht11 sensor instead of BME280

I use a free hivemq.cloud cluster

when getting to the
client = connect_mqtt()
part, I get the following error

Error connecting to MQTT: [Errno 104] ECONNRESET
Error: [Errno 104] ECONNRESET

any advice

]]>