# Help Required with passing payload and topic

**URL:** <https://discourse.nodered.org/t/help-required-with-passing-payload-and-topic/8070>\
**Category:** General\
**Created:** [17 February 2019 11:50 UTC](https://discourse.nodered.org/t/help-required-with-passing-payload-and-topic/8070 "2019-02-17T11:50:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mako](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@mako](https://discourse.nodered.org/u/mako)\
**Post date:** [17 February 2019 11:50 UTC](https://discourse.nodered.org/t/help-required-with-passing-payload-and-topic/8070/1 "2019-02-17T11:50:04Z")

</div>

Hello you awesome folks.

Having some trouble with this, please can someone tell me what im doing wrong.  
I have been through writing nodes and working with messages Node-Red docs and a few JavaScript informative sites.

I have a status node checking the status of of another node. Depending on the status it returns a payload of "Close" else "open" additional to this it needs a topic of "Control" its function is to control a gate node.

Here is a pic of the setup and the message coming from the debug.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/cef7d33a655ac28c6a70f096d439473d78867c01.png)

Here is the flow

```auto
[{"id":"36595d31.ac5c6a","type":"status","z":"60367313.e04cac","name":"","scope":["abae7ff5.f68b88"],"x":800,"y":1320,"wires":[["959d5020.312ce"]]},{"id":"f35207e9.031418","type":"debug","z":"60367313.e04cac","name":"full message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1270,"y":1220,"wires":[]},{"id":"959d5020.312ce","type":"function","z":"60367313.e04cac","name":"test Message","func":"msg.topic =\"control\"\nif (msg.status.text === \"closed\") \n{\nmsg.payload = \"close\";\nreturn [msg, null];\n} \nelse \n{\nmsg.payload = \"open\";\nreturn [msg, null];\n}","outputs":1,"noerr":0,"x":1060,"y":1320,"wires":[["f35207e9.031418","2798b304.43e8dc"]]},{"id":"2798b304.43e8dc","type":"gate","z":"60367313.e04cac","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1290,"y":1320,"wires":[[]]}]

```

My issue is is the Gate node is not recognizing the payload or the topic.  
I used 2 inject nodes, used string"open" topic control & string "closed" topic control, worked OK.

Can you advise me what I'm doing wrong. This weekend i have completed the internet.

Thank you

---

<div class="post-metadata">

**Author:** ![mako](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@mako](https://discourse.nodered.org/u/mako)\
**Post date:** [17 February 2019 12:08 UTC](https://discourse.nodered.org/t/help-required-with-passing-payload-and-topic/8070/2 "2019-02-17T12:08:57Z")

</div>

Did some further testing and it appears it picks up the "open" payload and changes the status of the gate node.  
The "close" payload has no effect. Tried msg.status.payload.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [17 February 2019 12:11 UTC](https://discourse.nodered.org/t/help-required-with-passing-payload-and-topic/8070/3 "2019-02-17T12:11:15Z")

</div>

use the tool tips to confirm the location as described here [https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 February 2019 14:41 UTC](https://discourse.nodered.org/t/help-required-with-passing-payload-and-topic/8070/4 "2019-02-17T14:41:41Z")

</div>

Is it node-red-contrib-simple-gate that you are using? This works ok for me.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b2c68120fc2d6f1d5d293e7c5f2fbb259bd48d99.png)

```auto
[{"id":"4f9819ab.0472d8","type":"debug","z":"514a90a5.c7bae8","name":"full message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":565,"y":267,"wires":[]},{"id":"763c2212.f60844","type":"function","z":"514a90a5.c7bae8","name":"test Message","func":"msg.topic =\"control\"\nif (msg.status.text === \"closed\") \n{\nmsg.payload = \"close\";\nreturn [msg, null];\n} \nelse \n{\nmsg.payload = \"open\";\nreturn [msg, null];\n}","outputs":1,"noerr":0,"x":355,"y":367,"wires":[["4f9819ab.0472d8","657dc65b.59c1a8"]]},{"id":"657dc65b.59c1a8","type":"gate","z":"514a90a5.c7bae8","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":585,"y":367,"wires":[[]]},{"id":"286435d7.53353a","type":"inject","z":"514a90a5.c7bae8","name":"","topic":"","payload":"open","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":103,"y":467,"wires":[["977c9e57.6f698"]]},{"id":"ad2970d8.cc1dd","type":"inject","z":"514a90a5.c7bae8","name":"","topic":"","payload":"closed","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":101,"y":509,"wires":[["977c9e57.6f698"]]},{"id":"977c9e57.6f698","type":"change","z":"514a90a5.c7bae8","name":"Set msg.status.text","rules":[{"t":"move","p":"payload","pt":"msg","to":"status.text","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":277.5,"y":490,"wires":[["763c2212.f60844"]]}]

```

---

<div class="post-metadata">

**Author:** ![mako](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@mako](https://discourse.nodered.org/u/mako)\
**Post date:** [17 February 2019 15:49 UTC](https://discourse.nodered.org/t/help-required-with-passing-payload-and-topic/8070/5 "2019-02-17T15:49:38Z")

</div>

Thanks for getting back Colin. That flow you have shown also works for me. i posted that just as an example on how it works and what i needed to achieve.  
I'm still working on the problem now. It seems the Modbus Response node maybe the issue.  
It will detect if a Modbus device has been re-connected to the bus. But when a device disconnects it wont change status until the flow has had a re-deploy.  
I'm gonna play a little more, if no joy ill message the author.

Cheers again Sir

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 February 2019 16:48 UTC](https://discourse.nodered.org/t/help-required-with-passing-payload-and-topic/8070/6 "2019-02-17T16:48:30Z")

</div>

OK, your post read as if you were saying the gate node was not responding correctly.
