# Getting Started with MQTT on Raspberry Pi Pico W - Connect to the Internet of Things!

**URL:** <https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673>\
**Category:** Guides\
**Created:** [21 March 2023 06:40 UTC](https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673 "2023-03-21T06:40:10Z")\
**Posts on this page:** 13\
**Page:** 2

<div class="post-metadata">

**Author:** ![Aaron](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/aaron/32/9861_2.png) [@Aaron](https://forum.core-electronics.com.au/u/Aaron)\
**Post date:** [3 October 2024 00:45 UTC](https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673/24 "2024-10-03T00:45:41Z")

</div>

Hi @Dale280804, Welcome to the forums!!!

Having a look at the [Pimoroni have an example with MQTT for this board.](https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/examples/pico_enviro#wireless-examples)

It looks like it should be simple enough to get it all working alongside this tutorial.

---

<div class="post-metadata">

**Author:** ![Dale280804](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@Dale280804](https://forum.core-electronics.com.au/u/Dale280804)\
**Post date:** [3 October 2024 14:20 UTC](https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673/25 "2024-10-03T14:20:36Z")

</div>

Hi Aaron,

Thank you for the welcome and pointing me in the right direction, however i am not sure what i need to put in for the MQTT broker details? (please see attached pic)  
I have installed mqtt on the pico and when i run the script it shows a message on the display “saying posting posting enviro+ data via mqtt wait a minute”

Any help appreciated on what details I need to add for mqtt broker settings.

> **(attachments)**
>
> ![pico project.PNG](https://canada1.discourse-cdn.com/flex028/uploads/core_electronics/original/2X/0/00deef3a15d880759f6ea6da42909b6d30ddc3f4.png)

---

<div class="post-metadata">

**Author:** ![Aaron](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/aaron/32/9861_2.png) [@Aaron](https://forum.core-electronics.com.au/u/Aaron)\
**Post date:** [4 October 2024 01:28 UTC](https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673/26 "2024-10-04T01:28:46Z")

</div>

Hi @Dale280804,

The code below is from the tutorial that shows where the Adafruit IO details need to go.  
You should be able to translate where they go in the Pimoroni code easily enough.

```auto
# Fill in your Adafruit IO Authentication and Feed MQTT Topic details
mqtt_host = "io.adafruit.com"
mqtt_username = "" # Your Adafruit IO username
mqtt_password = "" # Adafruit IO Key
mqtt_publish_topic = "" # The MQTT topic for your Adafruit IO Feed

# Enter a random ID for this MQTT Client
# It needs to be globally unique across all of Adafruit IO.
mqtt_client_id = "somethingreallyrandomandunique123"

# Initialize our MQTTClient and connect to the MQTT server
mqtt_client = MQTTClient(
        client_id=mqtt_client_id,
        server=mqtt_host,
        user=mqtt_username,
        password=mqtt_password)

```

---

<div class="post-metadata">

**Author:** ![Dale280804](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@Dale280804](https://forum.core-electronics.com.au/u/Dale280804)\
**Post date:** [4 October 2024 14:18 UTC](https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673/27 "2024-10-04T14:18:43Z")

</div>

Thanks Aaron,

I managed to get it working and connected and then something went wrong with my script on thonny and it throws up an error when trying to run with the below codes

MPY: soft reboot  
5  
5  
5  
5  
5  
[Errno 12] ENOMEM  
[Errno 12] ENOMEM  
[Errno 12] ENOMEM

---

<div class="post-metadata">

**Author:** ![Aaron](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/aaron/32/9861_2.png) [@Aaron](https://forum.core-electronics.com.au/u/Aaron)\
**Post date:** [8 October 2024 00:17 UTC](https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673/28 "2024-10-08T00:17:20Z")

</div>

Hi @Dale280804,

That is likely a running out of memory error.

There’s a lot of information out there on this issue.  
From [threads like this](https://stackoverflow.com/questions/74883568/oserror-errno-12-enomem), adding the [Garbage Collector library](https://docs.micropython.org/en/latest/library/gc.html) may work as a bandaid fix and help find where in your code the memory is getting tied up so you can try and optimise it.

---

<div class="post-metadata">

**Author:** ![Dale280804](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@Dale280804](https://forum.core-electronics.com.au/u/Dale280804)\
**Post date:** [9 October 2024 19:45 UTC](https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673/29 "2024-10-09T19:45:43Z")

</div>

That’s great, thanks Aaron I’ll take a look.

---

<div class="post-metadata">

**Author:** ![Jack](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/jack/32/9287_2.png) [@Jack](https://forum.core-electronics.com.au/u/Jack)\
**Post date:** [9 October 2024 22:42 UTC](https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673/30 "2024-10-09T22:42:43Z")

</div>

Let us know how you go!

---

<div class="post-metadata">

**Author:** ![Michael67832](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/michael67832/32/7613_2.png) [@Michael67832](https://forum.core-electronics.com.au/u/Michael67832)\
**Post date:** [22 October 2024 06:49 UTC](https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673/31 "2024-10-22T06:49:56Z")

</div>

I’ve just ran though all this with an old DHT11, attempting to replace my expensive rPI’s around here with the Pico W’s so that I can repurpose the Pi’s for bigger and better things than monitoring my reptile enclosures… it all looks good, but umqtt.simple gives me an error attempting to publish. [Errno 9] EBADF. (Bad File).

I’m running Thonny 4.1.6, and using Pico Firmware v1.23.0, micropython-umqtt.simple v1.3.4.

---

<div class="post-metadata">

**Author:** ![Zach](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/zach/32/10899_2.png) [@Zach](https://forum.core-electronics.com.au/u/Zach)\
**Post date:** [23 October 2024 00:45 UTC](https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673/32 "2024-10-23T00:45:46Z")

</div>

Hey @Michael67832,

I can think of a couple of things to check initially:

1. Make sure the socket is correctly initialised
2. Double check all of your info in the publish script (MQTT uname and password, wifi details, etc.)
3. File paths, a bad file error could come from a slightly different file path than the guide for whatever reason.
4. Make sure everything has correct admin privilege to access network resources

I would also suggest posting snippets of your code, just to have some extra eyes look over it.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Mark285907](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Mark285907](https://forum.core-electronics.com.au/u/Mark285907)\
**Post date:** [28 July 2025 02:33 UTC](https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673/33 "2025-07-28T02:33:39Z")

</div>

Post deleted. Issue fixed

---

<div class="post-metadata">

**Author:** ![Ryan](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/ryan/32/12254_2.png) [@Ryan](https://forum.core-electronics.com.au/u/Ryan)\
**Post date:** [28 July 2025 04:04 UTC](https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673/34 "2025-07-28T04:04:27Z")

</div>

Hey @Mark285907,

Feel free to post what the issue was and how you fixed it, I’m sure people facing the same problem in the future will appreciate it 🙂

---

<div class="post-metadata">

**Author:** ![Mark285907](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Mark285907](https://forum.core-electronics.com.au/u/Mark285907)\
**Post date:** [28 July 2025 05:34 UTC](https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673/35 "2025-07-28T05:34:16Z")

</div>

Thanks Ryan but I prefer to hide my “boy eyes” and stupid mistakes whenever possible!

---

<div class="post-metadata">

**Author:** ![Ryan](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/ryan/32/12254_2.png) [@Ryan](https://forum.core-electronics.com.au/u/Ryan)\
**Post date:** [28 July 2025 05:40 UTC](https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673/36 "2025-07-28T05:40:26Z")

</div>

Hey @Mark285907,

The classic “hide the evidence and pretend it never happened” strategy, tried and true! Nonetheless, glad to hear your project is up and running.

[Previous page](https://forum.core-electronics.com.au/t/getting-started-with-mqtt-on-raspberry-pi-pico-w-connect-to-the-internet-of-things/16673.md?page=1)
