# How to pass a message through the MQTT IN node configured in dynamic subscription mode

**URL:** https://discourse.nodered.org/t/how-to-pass-a-message-through-the-mqtt-in-node-configured-in-dynamic-subscription-mode/66064
**Category:** General
**Tags:** mqtt
**Created:** [5 August 2022 10:29 UTC](https://discourse.nodered.org/t/how-to-pass-a-message-through-the-mqtt-in-node-configured-in-dynamic-subscription-mode/66064 "2022-08-05T10:29:07Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Josh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/josh/32/62208_2.png) [@Josh](https://discourse.nodered.org/u/Josh)
#### Post date: [5 August 2022 10:29 UTC](https://discourse.nodered.org/t/how-to-pass-a-message-through-the-mqtt-in-node-configured-in-dynamic-subscription-mode/66064/1 "2022-08-05T10:29:07Z")

</div>

Hi All,  
I am facing an issue of passing a message through the MQTT IN node configured in dynamic subscription mode. Through a function node I am setting the config parameters to the MQTT node. I am also sending a msg.key value through the node. But when I trigger a message. I aint receiving the msg.key value in my output.

Code used in the function node:

```auto
msg.broker = {"broker":"broker.hivemq.com","port":1883};
msg.action = "connect";
msg.topic = "joshworld";
msg.key = "32wf43eg";
return msg;

```

I have tried few ways but that dint turn out well. Kindly help !!

Any quick help would be appreciated !!!!

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/a/fac6150434541038f4400a0af8dbf07a101e4fe2.png)

My flow :  
[myflows.txt](https://discourse.nodered.org/uploads/short-url/9fML6dlGTMlpslWQS5bdJLF2nwT.txt) (5.1 KB)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [5 August 2022 11:09 UTC](https://discourse.nodered.org/t/how-to-pass-a-message-through-the-mqtt-in-node-configured-in-dynamic-subscription-mode/66064/2 "2022-08-05T11:09:19Z")

</div>

Works fine - just not how you think.

Here is a fully working demo...

> [@Dynamic MQTT node's "actions-\>connect" guidance needed](https://discourse.nodered.org/t/dynamic-mqtt-nodes-actions-connect-guidance-needed/58878/2):
>
> The dynamic connection does not overwrite fields. It simply connects to the broker specified in the msg you send. You just add a broker (with any settings you like) and set it to NOT auto connect [image] then you send the appropriate msg to set up and connect. Here is a working demo... [mqtt-dyn] [{"id":"a7f43be0a40d080b","type":"mqtt out","z":"8afdb9e0485c9da7","name":"mqtt out","topic":"","qos":"0","retain":"false","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","…

Here is another using your values...  
 ![chrome_6Z6vYYtxra](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/a/aabad48cd134b29fc488681eb316ab19ec840bdd.gif)

```auto
[{"id":"90c6b92a167ccfd0","type":"function","z":"ec9cf53f5ff54f3b","name":"connect action","func":"msg.broker = {\"broker\":\"broker.hivemq.com\",\"port\":1883};\nmsg.action = \"connect\";\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1140,"y":60,"wires":[["66b1ad13cb265281"]]},{"id":"66b1ad13cb265281","type":"mqtt in","z":"ec9cf53f5ff54f3b","name":"","topic":"","qos":"2","datatype":"auto-detect","broker":"87ae16f44f4c9289","nl":false,"rap":true,"rh":0,"inputs":1,"x":1370,"y":80,"wires":[["11fbaa32576de64f"]]},{"id":"3ae59f4eb19407ae","type":"inject","z":"ec9cf53f5ff54f3b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":960,"y":60,"wires":[["90c6b92a167ccfd0"]]},{"id":"11fbaa32576de64f","type":"debug","z":"ec9cf53f5ff54f3b","name":"debug 54","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1400,"y":140,"wires":[]},{"id":"7d4e46fa8e71c57a","type":"mqtt out","z":"ec9cf53f5ff54f3b","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"87ae16f44f4c9289","x":1190,"y":260,"wires":[]},{"id":"72b84df48b0acf5a","type":"inject","z":"ec9cf53f5ff54f3b","name":"{\"key\":\"32wf43eg\"}","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"joshworld","payload":"{\"key\":\"32wf43eg\"}","payloadType":"json","x":1010,"y":260,"wires":[["7d4e46fa8e71c57a"]]},{"id":"dd2ae0d3db44925e","type":"function","z":"ec9cf53f5ff54f3b","name":"subscribe action","func":"msg.action = \"subscribe\";\nmsg.topic = \"joshworld\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1140,"y":140,"wires":[["66b1ad13cb265281"]]},{"id":"41db7b3deaae2651","type":"inject","z":"ec9cf53f5ff54f3b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":960,"y":140,"wires":[["dd2ae0d3db44925e"]]},{"id":"4329193ee5bd637b","type":"inject","z":"ec9cf53f5ff54f3b","name":"{\"key\":\"32wf43eg\"}","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"joshworld","payload":"{\"key\":\"abcdef\"}","payloadType":"json","x":1010,"y":300,"wires":[["7d4e46fa8e71c57a"]]},{"id":"dea0d19eb4e1a97a","type":"inject","z":"ec9cf53f5ff54f3b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":960,"y":180,"wires":[["2a1712b5f6c429c5"]]},{"id":"2a1712b5f6c429c5","type":"function","z":"ec9cf53f5ff54f3b","name":"unsubscribe action","func":"msg.action = \"unsubscribe\";\nmsg.topic = \"joshworld\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1150,"y":180,"wires":[["66b1ad13cb265281"]]},{"id":"18c55b5aa26ca697","type":"function","z":"ec9cf53f5ff54f3b","name":"disconnect action","func":"msg.action = \"disconnect\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1150,"y":100,"wires":[["66b1ad13cb265281"]]},{"id":"3f476107531ea14f","type":"inject","z":"ec9cf53f5ff54f3b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":960,"y":100,"wires":[["18c55b5aa26ca697"]]},{"id":"87ae16f44f4c9289","type":"mqtt-broker","name":"dynamic","broker":"0.0.0.0","port":"1883","clientid":"","autoConnect":false,"usetls":false,"protocolVersion":"5","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

```

---

<div class="post-metadata">

### Author: ![Josh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/josh/32/62208_2.png) [@Josh](https://discourse.nodered.org/u/Josh)
#### Post date: [8 August 2022 11:32 UTC](https://discourse.nodered.org/t/how-to-pass-a-message-through-the-mqtt-in-node-configured-in-dynamic-subscription-mode/66064/3 "2022-08-08T11:32:51Z")

</div>

Thanks steve for the prompt reply and clear understanding.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [7 October 2022 11:32 UTC](https://discourse.nodered.org/t/how-to-pass-a-message-through-the-mqtt-in-node-configured-in-dynamic-subscription-mode/66064/4 "2022-10-07T11:32:59Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
