Write values to excel from two real variable, when a boolean is true

Hello,

I am trying to write an CSV, with the data from two real variables, but only when a boolean is true or when I change a variable status. It doesn't work. If I put in the flow a boolean, it will write but with the status of that variable (TRUE).

Also, If I have the function, I don't understand why I have 2 duplicated rows, every time (most probably because on debugging node I have same - but i don't know how to make to have only one).

Is this any ideas? Thanks very much for help.


image

And the flow:

{
        "id": "e5b093538a456090",
        "type": "group",
        "z": "a0e25e7b2fd00f38",
        "name": "Sending data to excel",
        "style": {
            "label": true
        },
        "nodes": [
            "23e6ea12df7a314d",
            "52ebb1c6b9acdf44",
            "df291718238d71f6",
            "a38814e8796ddb63",
            "1e4b079df1a96814",
            "311bae7ef5f785ed",
            "dbfa625dd2195017",
            "99a275c7dddca3f3"
        ],
        "x": 14,
        "y": 2439,
        "w": 992,
        "h": 162
    },
    {
        "id": "23e6ea12df7a314d",
        "type": "s7 in",
        "z": "a0e25e7b2fd00f38",
        "g": "e5b093538a456090",
        "endpoint": "4f6c10e39b6f89f4",
        "mode": "single",
        "variable": "rVibrationForward",
        "diff": true,
        "name": "",
        "x": 130,
        "y": 2480,
        "wires": [
            [
                "1e4b079df1a96814"
            ]
        ]
    },
    {
        "id": "52ebb1c6b9acdf44",
        "type": "s7 in",
        "z": "a0e25e7b2fd00f38",
        "g": "e5b093538a456090",
        "endpoint": "4f6c10e39b6f89f4",
        "mode": "single",
        "variable": "rVibrationReverse",
        "diff": true,
        "name": "",
        "x": 130,
        "y": 2560,
        "wires": [
            [
                "99a275c7dddca3f3"
            ]
        ]
    },
    {
        "id": "df291718238d71f6",
        "type": "debug",
        "z": "a0e25e7b2fd00f38",
        "g": "e5b093538a456090",
        "name": "debug 16",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 760,
        "y": 2480,
        "wires": []
    },
    {
        "id": "a38814e8796ddb63",
        "type": "function",
        "z": "a0e25e7b2fd00f38",
        "g": "e5b093538a456090",
        "name": "function 3",
        "func": "var vibrfw = flow.get(\"rVibrationForward\");\nvar vibrrev = flow.get(\"rVibrationReverse\");\nvar d=new Date();\nvar time=d.toLocaleTimeString();\nvar m = { 'Time': time, 'Forward': vibrfw, 'Reverse': vibrrev};\nreturn {payload:m};",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 580,
        "y": 2520,
        "wires": [
            [
                "df291718238d71f6",
                "dbfa625dd2195017"
            ]
        ]
    },
    {
        "id": "1e4b079df1a96814",
        "type": "change",
        "z": "a0e25e7b2fd00f38",
        "g": "e5b093538a456090",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "rVibrationForward",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 370,
        "y": 2480,
        "wires": [
            [
                "a38814e8796ddb63"
            ]
        ]
    },
    {
        "id": "311bae7ef5f785ed",
        "type": "file",
        "z": "a0e25e7b2fd00f38",
        "g": "e5b093538a456090",
        "name": "excel_output",
        "filename": "D:\\Personal\\NodeREd\\excel_output.csv",
        "filenameType": "str",
        "appendNewline": true,
        "createDir": true,
        "overwriteFile": "false",
        "encoding": "utf8",
        "x": 910,
        "y": 2560,
        "wires": [
            []
        ]
    },
    {
        "id": "dbfa625dd2195017",
        "type": "csv",
        "z": "a0e25e7b2fd00f38",
        "g": "e5b093538a456090",
        "name": "",
        "sep": ",",
        "hdrin": true,
        "hdrout": "none",
        "multi": "one",
        "ret": "\\n",
        "temp": "Time, Forward, Reverse",
        "skip": "1",
        "strings": true,
        "include_empty_strings": "",
        "include_null_values": "",
        "x": 750,
        "y": 2560,
        "wires": [
            [
                "311bae7ef5f785ed"
            ]
        ]
    },
    {
        "id": "99a275c7dddca3f3",
        "type": "change",
        "z": "a0e25e7b2fd00f38",
        "g": "e5b093538a456090",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "rVibrationReverse",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 370,
        "y": 2560,
        "wires": [
            [
                "a38814e8796ddb63"
            ]
        ]
    },
    {
        "id": "4f6c10e39b6f89f4",
        "type": "s7 endpoint",
        "transport": "iso-on-tcp",
        "address": "192.168.0.1",
        "port": "102",
        "rack": "0",
        "slot": "1",
        "localtsaphi": "01",
        "localtsaplo": "00",
        "remotetsaphi": "01",
        "remotetsaplo": "00",
        "connmode": "rack-slot",
        "adapter": "",
        "busaddr": "2",
        "cycletime": "200",
        "timeout": "2000",
        "name": "",
        "vartable": [
            {
                "addr": "M151.0",
                "name": "b_OK_parts"
            },
            {
                "addr": "M151.1",
                "name": "b_NOK_parts"
            },
            {
                "addr": "MW2",
                "name": "int_OK_parts"
            },
            {
                "addr": "MW6",
                "name": "int_NOK_parts"
            },
            {
                "addr": "M0.1",
                "name": "Light_ON"
            },
            {
                "addr": "M0.6",
                "name": "b_InitializeInProcess"
            },
            {
                "addr": "M0.4",
                "name": "b_StartLinePressed"
            },
            {
                "addr": "M1.3",
                "name": "b_DeinitializeInProcess"
            },
            {
                "addr": "M0.5",
                "name": "b_StopLinePressed"
            },
            {
                "addr": "MW7",
                "name": "intState"
            },
            {
                "addr": "MW10",
                "name": "intState2"
            },
            {
                "addr": "MW9",
                "name": "inTemperature"
            },
            {
                "addr": "MW12",
                "name": "intHumidity"
            },
            {
                "addr": "M14.0",
                "name": "bLed"
            },
            {
                "addr": "DB5,X312.0",
                "name": "bStartLW"
            },
            {
                "addr": "DB5,R0",
                "name": "bFrequencyLW"
            },
            {
                "addr": "DB5,R298",
                "name": "rPTEmtyingTimeoutLW"
            },
            {
                "addr": "DB5,X4.0",
                "name": "bStopLW"
            },
            {
                "addr": "DB5,X302.1",
                "name": "bStartedFW"
            },
            {
                "addr": "DB5,WORD6",
                "name": "intStateFW"
            },
            {
                "addr": "DB5,X302.2",
                "name": "bFreezeState"
            },
            {
                "addr": "DB5,R308",
                "name": "rVibrationForward"
            },
            {
                "addr": "DB5,R304",
                "name": "rVibrationReverse"
            }
        ]
    }
]

The function receives two messages, so creates two rows, you may be better off joining the two messages into one and add filter node to check for changes. eg.

[{"id":"c8249857f4e7905f","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"200","payloadType":"num","x":110,"y":2720,"wires":[["1e4b079df1a96814"]]},{"id":"1e4b079df1a96814","type":"change","z":"65617ffeb779f51c","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Forward","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":2760,"wires":[["a74991b46ea248ec"]]},{"id":"f64e31c8e40d9ea5","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"100","payloadType":"num","x":110,"y":2760,"wires":[["1e4b079df1a96814"]]},{"id":"a74991b46ea248ec","type":"join","z":"65617ffeb779f51c","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":410,"y":2800,"wires":[["c6b8467dd98f2c2b"]]},{"id":"99a275c7dddca3f3","type":"change","z":"65617ffeb779f51c","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Reverse","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":2840,"wires":[["a74991b46ea248ec"]]},{"id":"c6b8467dd98f2c2b","type":"rbe","z":"65617ffeb779f51c","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":470,"y":2720,"wires":[["a38814e8796ddb63"]]},{"id":"12bab85d9cde53c9","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"200","payloadType":"num","x":110,"y":2840,"wires":[["99a275c7dddca3f3"]]},{"id":"76e9198b8ec24f42","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"100","payloadType":"num","x":110,"y":2880,"wires":[["99a275c7dddca3f3"]]},{"id":"a38814e8796ddb63","type":"function","z":"65617ffeb779f51c","name":"function 3","func":"const d=new Date();\nmsg.payload.Time = d.toLocaleTimeString();\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":2800,"wires":[["dbfa625dd2195017"]]},{"id":"dbfa625dd2195017","type":"csv","z":"65617ffeb779f51c","name":"","sep":",","hdrin":true,"hdrout":"none","multi":"one","ret":"\\n","temp":"Time, Forward, Reverse","skip":"1","strings":true,"include_empty_strings":"","include_null_values":"","x":720,"y":2840,"wires":[["df291718238d71f6"]]},{"id":"df291718238d71f6","type":"debug","z":"65617ffeb779f51c","name":"debug 16","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":2760,"wires":[]}]

you may want to check "and every subsequent message" in the join node to.

Thank you very much.
Now is much better :slight_smile:

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