# How to receive MQTT data using Subscribe and callback

**URL:** <https://discourse.nodered.org/t/how-to-receive-mqtt-data-using-subscribe-and-callback/86596>\
**Category:** Hardware\
**Tags:** python\
**Created:** [20 March 2024 16:10 UTC](https://discourse.nodered.org/t/how-to-receive-mqtt-data-using-subscribe-and-callback/86596 "2024-03-20T16:10:24Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![badflash](https://avatars.discourse-cdn.com/v4/letter/b/d6d6ee/32.png) [@badflash](https://discourse.nodered.org/u/badflash)\
**Post date:** [20 March 2024 16:10 UTC](https://discourse.nodered.org/t/how-to-receive-mqtt-data-using-subscribe-and-callback/86596/1 "2024-03-20T16:10:24Z")

</div>

I am have trouble figuring out how to implement the subscribe and callback feature of MQTT in micropython. The examples I've found aren't helping me figure out how to do it. I'm a new guy.

I am using a Pi Pico W, HiveMQ and Node-Red. I can send data to node-red and display it on a guage, but I can't seem to get data like a switch toggle back. The MQTT send node says its connected. I see the data coming through HiveMQ and something is getting back to the Pi Pico, but it crashes the program with the following error:

```auto
Traceback (most recent call last):
  File "<stdin>", line 77, in <module>
  File "umqtt/simple.py", line 216, in check_msg
  File "umqtt/simple.py", line 202, in wait_msg
TypeError: function takes 1 positional arguments but 2 were given

```

Line 77 is client.check\_msg()

The callback is:

````auto
def sub_cb(topic):
    print(topic)
    ```

````

client.set\_callback(sub\_cb)  
client.subscribe(SUBSCRIBE\_TOPIC)

```auto
SUBSCRIBE_TOPIC = "badflash.picow/onoff"

Help!
```

---

_[View the full topic](https://discourse.nodered.org/t/how-to-receive-mqtt-data-using-subscribe-and-callback/86596)._
