A node I just made

80 views
Skip to first unread message

shykitten55

unread,
May 24, 2018, 8:14:09 AM5/24/18
to Node-RED
This node is similar to one I got help with earlier.

That node is still needed and used.

But working on my flows, it became obvious I needed another node of similar functions, but not exactly the same.


I'm not sure if I am re-inventing the wheel, but here is my effort:

Idea:
A node with 1 input and 1 output.
One set of signals is TOPIC set to ENABLE.
It can be ENABLE or DISABLE.
(I guess I can change that to boolean, but.....)

The other input/message is only passed if ENABLE is active.

[{"id":"a3d66060.812868","type":"function","z":"2d44537.f26082c","name":"EN","func":"context.message;\ncontext.mtopic = msg.topic;\nvar enable_topic = context.get('enable_topic');\nvar mpayload = msg.payload;\nvar enable_topic = 'ENABLE';\n\nif (enable_topic === 1)\n{\n    node.status({fill:\"green\",shape:\"dot\",text:\"On-line\"});\n    return msg;\n}\n\nif (context.mtopic == enable_topic)\n{\n    //\n    if (msg.payload === 'ENABLE')\n    {\n        node.status({fill:\"yellow\",shape:\"dot\",text:\"ENABLED\"});\n        context.enable = 1;\n        context.set('enable',enable_topic);\n    }\n    if (msg.payload === 'DISABLE')\n    {\n        context.enable = 0;\n        context.set('enable',enable_topic);\n        node.status({fill:\"red\",shape:\"dot\",text:\"DISABLED\"});\n    }\n}\n","outputs":1,"noerr":0,"x":720,"y":1870,"wires":[["a1219f49.a1eac8"]]}]


I seem to be missing something about how the message is passed through.

I (maybe) should learn how to have multiple inputs to a node.
But for now I am using a function node and it has only 1 input.



Nick O'Leary

unread,
May 24, 2018, 8:15:33 AM5/24/18
to Node-RED Mailing List
Please start using the Node-RED forum: https://discourse.nodered.org

This mailing list will stop accepting new messages soon.

--
http://nodered.org
 
** We're moving this mailing list over to the new Node-RED Forum: https://discourse.nodered.org **
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/b2601e5c-bd79-4254-aed5-ef3a4e93f733%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages