write file conditionally

181 views
Skip to first unread message

Lawrence Griffiths

unread,
Jun 10, 2014, 12:46:41 PM6/10/14
to node...@googlegroups.com
Hi I've searched for this.
I've got a file write wired to a function and only want to write when a certain state is true.
I can't see a way doing this?

I'm currently changing the file name when condition is false so can preserve correct data.
But this means an unnecessary write each time I get an input from a sensor.

Thanks in advance for any help.
Lawrence

Edward Vielmetti

unread,
Jun 10, 2014, 12:58:48 PM6/10/14
to node...@googlegroups.com
Lawrence,

Can you put another node downstream from your function (like a switch) that takes care of the conditional? E.g. if your function returns msg.payload and also msg.flag with a result from 0 or 1 and you only want to write when msg.flag is 1, you could have a switch that is wired to your file write function only when the flag is set.

Two screen captures attached!




--
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.



--
Edward Vielmetti +1 734 330 2465

Screen shot 2014-06-10 at 12.56.48 PM.png
Screen shot 2014-06-10 at 12.57.00 PM.png

Andrew Lindsay

unread,
Jun 10, 2014, 1:02:33 PM6/10/14
to node...@googlegroups.com
Can you not use a function node with 2 outputs. One out up is to a file node, the second to a debug or other non file node.

In your function you would set the output msg to be null for first value if you didn't want to write the output to a file. When you need to write you have the first value as the msg and the second as null. This way you could direct the flow around a file node if needed.

Not got access to NR at present so can't verify exact details.

Regards

Andrew

Lawrence Griffiths

unread,
Jun 10, 2014, 2:53:27 PM6/10/14
to node...@googlegroups.com
Edward/Andrew thanks for the prompt replies.
I'm still in newbi mode and not thinking in a node-red like way.
I keep forgetting you can have multiple in/out.

Lawrence

Dave C-J

unread,
Jun 10, 2014, 3:59:23 PM6/10/14
to node...@googlegroups.com
Yes - see multiple outputs section of http://nodered.org/docs/writing-functions.html


--
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.



--
regards

Dave Conway-Jones

Reply all
Reply to author
Forward
0 new messages