create a new node from a flow

85 views
Skip to first unread message

Luigi Amalfitano

unread,
May 14, 2015, 8:06:37 PM5/14/15
to node...@googlegroups.com
node-red is fantastic.

It allows to do many things quickly.

sorry if I do trivial questions, but I have to first experience with node-red

I created my first flows and I wanted to understand how to turn them into a new Node. it's possible?

I can create a node from the json representation of the flow?
By example, I would like to create a simple new Node that connects to a tcp server and provides the packets received on a new tcp server listener.
Here's the code json

[{"id":"bf09ca3.f40f638","type":"tcp in","server":"client","host":"localhost","port":"5001","datamode":"stream","datatype":"buffer","newline":"","topic":"","name":"","base64":false,"x":153,"y":96,"z":"35e22a44.ca1dd6","wires":[["cfb2375e.304dc8"]]},{"id":"cfb2375e.304dc8","type":"tcp out","host":"","port":"6001","beserver":"server","base64":false,"end":false,"name":"","x":377,"y":96,"z":"35e22a44.ca1dd6","wires":[]}]

If it is not possible, how can I convert the flow in a Node?

I can create a new node using nodes already installed (tcpin and tcpout), but How do I connect the output of an input node (tcpin) to another (tcpout)?

Thanks

Shem Jamieson

unread,
May 15, 2015, 8:46:21 AM5/15/15
to node...@googlegroups.com
Hey Luigi,

You can't turn a flow into a node, unless you are talking about a sub-flow? You can also save flows to your library.
You can connect one out to multiple ins...

Julian Knight

unread,
May 15, 2015, 7:35:20 PM5/15/15
to node...@googlegroups.com
Hi Luigi, welcome to the world of Node-Red!

You are already part way there. You can simply drag a line from the input node to the output node and they will be connected. Not very useful though because nothing changes in-between.

If you have some complex processing to do on the input, you might start with a Function node. Add a function node to your flow. Connect the TCP input to the function and the function to the TCP output.

Now what you need to know is that, by convention, every node output is called "msg" so the input to your function is also called msg and you automatically have that as a variable. You might like to, at this point, add another useful node type, a "debug" node. Add one and draw a line from the TCP input node to the debug node's input. Now when the TCP input is triggered, you will see some output in the debug panel on the right-hand panel (select it's tab). You might like to change the settings of the debug node so that it shows the whole message rather than just msg.payload which is the default.

Now if you add something to the msg variable in your function node:
msg.mystuff = "Hi There";
for example and draw a line from the function output to the debug input. When the TCP node triggers, you will get two entries in the debug panel, one for the original msg from the TCP input and one from your function. The second should show the extra element you've added (unless the output is too long).

Does that explain things enough to get to the next stage?



On Friday, 15 May 2015 01:06:37 UTC+1, Luigi Amalfitano wrote:
node-red is fantastic.

...

Nicholas O'Leary

unread,
May 15, 2015, 7:42:34 PM5/15/15
to node...@googlegroups.com

That's very useful Julian, but in this instance, if you re-read Luigi's post, he's a bit beyond the basic wiring up of a flow.
That said, Luigi, I dont quite follow your last question - I'm assuming there's a subtlety to it that I'm missing.

As Shem said in his reply, you cannot take a flow and package it up as a redistributable node. You can create a subflow from them, which appears like a palette node, but that isn't something you could publish to npm to enable anyone to readily npm install it, as you can "regular" nodes.

But your mail, a long with a couple others we've had along similar lines does make me start to wonder how that might work....

Nick


--
http://nodered.org
---
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.
For more options, visit https://groups.google.com/d/optout.

Julian Knight

unread,
May 15, 2015, 7:45:57 PM5/15/15
to node...@googlegroups.com
Wasn't quite sure as it wasn't clear.

Luigi Amalfitano

unread,
May 19, 2015, 6:07:54 PM5/19/15
to node...@googlegroups.com
Yes,
it would be useful to automatically create nodes redistributable from the flows. The subflows are fine but redeploy a flow as a node is more comfortable and facilitates the construction of complex flows ... A little how make labview ...
Reply all
Reply to author
Forward
0 new messages