Help creating re-usable subflows (or nodes ?)

Hi folks,

I'm looking for a little advice, I'm trying to make some re-usable code for a project I'm working on, it's a RS485 comms library which is used to talk to a bespoke bit of hardware The comms takes the form of a 4 letter ID and can be a read, write or read-write to read and write various parameters.

I've done something similar to talk to this hardware using LabVIEW, I put the IDs into a Typedef so they can be selected/picked from a list.

Is there anything similar I can do with Node Red ?

I have over 100 ID, with maybe a common use subset of 20, I don't really want to create a subflow for each of these 20 IDs if I can help it. I could just type the ID in each time I use a subflow . . . but if I have a typo and don't realise it I'll end up tearing my hair out . . .

Suggestions ?

How do you want to choose the id? Is it entered via a dashboard field or something similar? Is this a run-time choice (in which case you could use a dropdown in the dashboard) or design time (so in the editor).

Hi Colin,

no it's not a runtime thing, it's a development thing. I'd really like to be able to pick it from a list in a node . . . but can't see a way of doing that.

You can enter all id's in a select box in the subflow properties, then when you use the subflow you can select the id. The id can the be retrieved using env.get().

[{"id":"a7cac120.69305","type":"subflow","name":"","info":"","category":"","in":[{"x":50,"y":30,"wires":[{"id":"e3ded4f.d786628"}]}],"out":[{"x":560,"y":100,"wires":[{"id":"e3ded4f.d786628","port":0}]}],"env":[{"name":"id","type":"str","value":"asdf","ui":{"type":"select","opts":{"opts":[{"l":{"en-US":"qwer"},"v":"qwer"},{"l":{"en-US":"asdf"},"v":"asdf"}]}}}],"color":"#DDAA99"},{"id":"e3ded4f.d786628","type":"function","z":"a7cac120.69305","name":"","func":"msg.payload=env.get(\"id\") || 0;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":160,"wires":[[]]},{"id":"77534080.a19b78","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":3960,"wires":[["5062b101.f16c58"]]},{"id":"5062b101.f16c58","type":"subflow:a7cac120.69305","z":"c74669a0.6a34f8","name":"","env":[],"x":320,"y":4000,"wires":[["861a6d98.3f33"]]},{"id":"861a6d98.3f33","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":3980,"wires":[]}]

I entered two id's which you can select when you edit the subflow when you want to use it.

Terrific, exactly what I need, thank you. :smiley:

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