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

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.

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

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

Flow:

[{"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

It works perfect, thank you very much

You're welcome!

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