Write file only when button is triggered

hello guys

I am reading data from an Arduino. This data is being written into a file on the Raspi. The way it works now is that as soon as the Arduino sends anything, the Raspi immediatly writes the file. What I would like to have is that the file is only written, when a button was pushed before. So as long as the button is not pressed, no file will be written, altough data is being sent / received.
On the attached image are the basic nodes (without the buttons). Somehow the button(s) need to interfere with the connection marked in green on the image, but I don't know how to do this. I cannot just insert a button, because in fact I have two buttons and the user has to click one of them before the file should be created.


see code below:


You could use a node-red-contrib-queue-gate set to max queue size of 1 and to Keep Newest Message, with default state Closed. Make the button send it a Flush command. The node will buffer within itself the most recent message and when the button sends the flush it will release that last message.

It would be more efficient to put it earlier in flow so it is not wasting its time preparing the data only for it to be thrown away.

thx, I will try this.