# Problems writing data from node s7 to csv every time we get a boolean true signal

**URL:** https://discourse.nodered.org/t/problems-writing-data-from-node-s7-to-csv-every-time-we-get-a-boolean-true-signal/32080
**Category:** General
**Created:** [27 August 2020 07:28 UTC](https://discourse.nodered.org/t/problems-writing-data-from-node-s7-to-csv-every-time-we-get-a-boolean-true-signal/32080 "2020-08-27T07:28:52Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)
#### Post date: [27 August 2020 07:28 UTC](https://discourse.nodered.org/t/problems-writing-data-from-node-s7-to-csv-every-time-we-get-a-boolean-true-signal/32080/1 "2020-08-27T07:28:52Z")

</div>

Hi, see if you can help me, it turns out that so far as I show you in the flow image I am able to register well a series of variables type int or Dint in a csv file with its stamp time, all this every 5 seconds so Automatic, the problem I have is that I do not want it to be registered automatically I want that data to be registered when one of the 3 boolean signals that you see in the image is true and I have tried a few ways but there is no way, any suggestions?

The connection appears in the S7 nodes as disconnected because right now I do not have the plc.

 ![PN1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/3/f375449766c08e813c2c17dde1929c87ffc4b513.png)

---

<div class="post-metadata">

### Author: ![ArneR](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/arner/32/95658_2.png) [@ArneR](https://discourse.nodered.org/u/ArneR)
#### Post date: [27 August 2020 09:22 UTC](https://discourse.nodered.org/t/problems-writing-data-from-node-s7-to-csv-every-time-we-get-a-boolean-true-signal/32080/2 "2020-08-27T09:22:53Z")

</div>

Hey!

You can use a "gate" (node-red-contrib-simple-gate).

In the flow below I simulate the boolean of the PLC by injecting a "true" or "false". (boolean).

Set the gate as follows:

- Control topic: "control"
- Open: "true"
- Close "false"

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/3/a37aa14b3f43bbe980eb90a808059f79f7a443bd.png)  
You can also place the delay after the gate if desired.

Note that you need a topic, if you don't set it via the PLC node, you can add it via the change node.

Arne

---

<div class="post-metadata">

### Author: ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)
#### Post date: [27 August 2020 09:24 UTC](https://discourse.nodered.org/t/problems-writing-data-from-node-s7-to-csv-every-time-we-get-a-boolean-true-signal/32080/3 "2020-08-27T09:24:26Z")

</div>

ok, I try it and let you know how it works, thanks.

---

<div class="post-metadata">

### Author: ![ArneR](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/arner/32/95658_2.png) [@ArneR](https://discourse.nodered.org/u/ArneR)
#### Post date: [27 August 2020 09:30 UTC](https://discourse.nodered.org/t/problems-writing-data-from-node-s7-to-csv-every-time-we-get-a-boolean-true-signal/32080/4 "2020-08-27T09:30:39Z")

</div>

**Flow:**

```auto
[{"id":"b547cf96.056ee","type":"gate","z":"90af3ff8.12c38","name":"","controlTopic":"control","defaultState":"closed","openCmd":"true","closeCmd":"false","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":950,"y":4380,"wires":[["5c666fdc.2eb2e","861b9315.c94d8"]]},{"id":"c93c82dd.53a28","type":"inject","z":"90af3ff8.12c38","name":"Boolean 2 (true)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"true","payloadType":"bool","x":600,"y":4540,"wires":[["b547cf96.056ee"]]},{"id":"7495c612.68d4d8","type":"inject","z":"90af3ff8.12c38","name":"Boolean 2 (false)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"false","payloadType":"bool","x":600,"y":4580,"wires":[["b547cf96.056ee"]]},{"id":"d9ae4233.58c7a","type":"delay","z":"90af3ff8.12c38","name":"1 msg/5s","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":780,"y":4380,"wires":[["b547cf96.056ee"]]},{"id":"5c666fdc.2eb2e","type":"debug","z":"90af3ff8.12c38","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1090,"y":4300,"wires":[]},{"id":"5aefc719.74e888","type":"change","z":"90af3ff8.12c38","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":4640,"wires":[["b547cf96.056ee"]]},{"id":"ecd0df9.42dcc2","type":"s7 in","z":"90af3ff8.12c38","endpoint":"","mode":"single","variable":"","diff":true,"name":"","x":630,"y":4640,"wires":[["5aefc719.74e888"]]},{"id":"f7074c41.888a1","type":"inject","z":"90af3ff8.12c38","name":"Boolean 1 (true)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"true","payloadType":"bool","x":600,"y":4440,"wires":[[]]},{"id":"bb72b6c8.fcb848","type":"inject","z":"90af3ff8.12c38","name":"Boolean 1 (false)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"false","payloadType":"bool","x":600,"y":4480,"wires":[[]]},{"id":"c0480be8.ad28b8","type":"s7 in","z":"90af3ff8.12c38","endpoint":"","mode":"single","variable":"","diff":true,"name":"","x":630,"y":4380,"wires":[["d9ae4233.58c7a"]]},{"id":"861b9315.c94d8","type":"function","z":"90af3ff8.12c38","name":"Add time","func":"var date;\ndate = new Date(); \ndate = (date.getDate() + '-' + (date.getMonth()+1) + '-' + date.getFullYear() + ' om ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds());\nmsg.payload.date = date; \nreturn msg;\n\n// Your other function needs to be added. ","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1120,"y":4380,"wires":[["2e300b1d.62e874"]]},{"id":"2e300b1d.62e874","type":"csv","z":"90af3ff8.12c38","name":"Create CSV","sep":";","hdrin":false,"hdrout":"none","multi":"one","ret":"\\r\\n","temp":"Set it up like you want.","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":false,"x":1310,"y":4380,"wires":[[]]}]

```

This still needs adjustments, such as the csv node, your function and PLC nodes.

Arne

---

<div class="post-metadata">

### Author: ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)
#### Post date: [27 August 2020 12:14 UTC](https://discourse.nodered.org/t/problems-writing-data-from-node-s7-to-csv-every-time-we-get-a-boolean-true-signal/32080/5 "2020-08-27T12:14:22Z")

</div>

It works perfect, thank you very much

---

<div class="post-metadata">

### Author: ![ArneR](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/arner/32/95658_2.png) [@ArneR](https://discourse.nodered.org/u/ArneR)
#### Post date: [27 August 2020 12:20 UTC](https://discourse.nodered.org/t/problems-writing-data-from-node-s7-to-csv-every-time-we-get-a-boolean-true-signal/32080/6 "2020-08-27T12:20:56Z")

</div>

You're welcome!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [26 October 2020 12:20 UTC](https://discourse.nodered.org/t/problems-writing-data-from-node-s7-to-csv-every-time-we-get-a-boolean-true-signal/32080/7 "2020-10-26T12:20:58Z")

</div>

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