Trigger SQL INSERT

Hello there! I am using node-red-contrib-s7 v.3.1 and node-red-node-mysql v.1.0.3 to read data from a PLC and perform a INSERT on a MARIADB Database. How can I use a PLC variable to trigger the function node with the INSERT command?

I want to insert data in the SQL everytime a flag on the PLC goes TRUE.

Thanks for the help! :grinning:

Assuming that you get S7 data at regular intervals something like this will trigger a database update when the value goes true.

Thanks for your reply! Actually would be something like, if a memory address in the PLC is TRUE, run the function node....

Kinda like what I am trying to do here:

[
    {
        "id": "b17d4b93202e9c4b",
        "type": "tab",
        "label": "DB Logging",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "f1a8a57d.896448",
        "type": "inject",
        "z": "b17d4b93202e9c4b",
        "name": "CREATE",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 160,
        "y": 220,
        "wires": [
            []
        ]
    },
    {
        "id": "d8886e88.2e352",
        "type": "debug",
        "z": "b17d4b93202e9c4b",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 690,
        "y": 220,
        "wires": []
    },
    {
        "id": "565b9eff.a027b",
        "type": "inject",
        "z": "b17d4b93202e9c4b",
        "name": "TriggerTrue",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 150,
        "y": 300,
        "wires": [
            []
        ]
    },
    {
        "id": "2ac9919.fbaf86e",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "INSERT",
        "func": "\nvar values = msg.payload;\nvar topic = \"INSERT INTO beamshaper.lensstack (LeftSide_Dist, RightSide_Dist, LeftSide_Shift, RightSide_Shift, TopLens_Angle, BottomLens_Angle, LensCode, `timestamp`) VALUES(\" + values + \", current_timestamp())\";\nmsg.topic = topic; \nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 760,
        "y": 540,
        "wires": [
            [
                "7bfdc80134e445cf"
            ]
        ]
    },
    {
        "id": "7286764d.703128",
        "type": "debug",
        "z": "b17d4b93202e9c4b",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 1110,
        "y": 480,
        "wires": []
    },
    {
        "id": "16d49f4f.2f72e1",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "TABLE",
        "func": "topic = \"CREATE TABLE `access` ( \";\ntopic = topic + \"`no` INT NULL AUTO_INCREMENT,\";\ntopic = topic + \"`date` TIMESTAMP NOT NULL,\";\ntopic = topic + \"`room` INT NULL,\";\ntopic = topic + \"`id` INT NULL,\";\ntopic = topic + \"INDEX `no` (`no`)) COLLATE='latin1_swedish_ci';\";\nmsg.topic = topic;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 12,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 330,
        "y": 220,
        "wires": [
            [
                "392b8ab7.e19ac6"
            ]
        ]
    },
    {
        "id": "982a5d4d.e294f",
        "type": "inject",
        "z": "b17d4b93202e9c4b",
        "name": "CREATE",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 160,
        "y": 160,
        "wires": [
            []
        ]
    },
    {
        "id": "8f16a404.412c08",
        "type": "debug",
        "z": "b17d4b93202e9c4b",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 690,
        "y": 160,
        "wires": []
    },
    {
        "id": "3648a443.b264bc",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "DATABASE",
        "func": "var newMsg = {\n\"topic\" : \"CREATE DATABASE `test`;\"\n}\nreturn newMsg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 350,
        "y": 160,
        "wires": [
            [
                "1c79da55.f69436"
            ]
        ]
    },
    {
        "id": "fdbcc9a.f22b838",
        "type": "mysql",
        "z": "b17d4b93202e9c4b",
        "mydb": "2236dfd1.c909e",
        "name": "",
        "x": 930,
        "y": 540,
        "wires": [
            [
                "7286764d.703128"
            ]
        ]
    },
    {
        "id": "392b8ab7.e19ac6",
        "type": "mysql",
        "z": "b17d4b93202e9c4b",
        "mydb": "2236dfd1.c909e",
        "name": "",
        "x": 530,
        "y": 220,
        "wires": [
            [
                "d8886e88.2e352"
            ]
        ]
    },
    {
        "id": "1c79da55.f69436",
        "type": "mysql",
        "z": "b17d4b93202e9c4b",
        "mydb": "2236dfd1.c909e",
        "name": "",
        "x": 530,
        "y": 160,
        "wires": [
            [
                "8f16a404.412c08"
            ]
        ]
    },
    {
        "id": "74381c4e55d860ae",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "flag_DBLog",
        "diff": true,
        "name": "",
        "x": 170,
        "y": 400,
        "wires": [
            [
                "cf3bbcaba93533b8"
            ]
        ]
    },
    {
        "id": "12f4f937ddc4e1ab",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "LeftSide_Dist",
        "diff": true,
        "name": "",
        "x": 170,
        "y": 440,
        "wires": [
            [
                "450a94417c8b71f7"
            ]
        ]
    },
    {
        "id": "4609f6479ce70b29",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "RightSide_Dist",
        "diff": true,
        "name": "",
        "x": 160,
        "y": 480,
        "wires": [
            [
                "f6556b2243dac15a"
            ]
        ]
    },
    {
        "id": "0100ebfd0ebe2d25",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "LeftSide_Shift",
        "diff": true,
        "name": "",
        "x": 170,
        "y": 520,
        "wires": [
            [
                "ac80af684e1dd309"
            ]
        ]
    },
    {
        "id": "7952fc36ed071900",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "RightSide_Shift",
        "diff": true,
        "name": "",
        "x": 160,
        "y": 560,
        "wires": [
            [
                "08547bcbf3b641dd"
            ]
        ]
    },
    {
        "id": "b54836054967eff2",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "TopLens_Angle",
        "diff": true,
        "name": "",
        "x": 160,
        "y": 600,
        "wires": [
            [
                "8743a37f034305b5"
            ]
        ]
    },
    {
        "id": "a1fa113a9c974f1e",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "BottomLens_Angle",
        "diff": true,
        "name": "",
        "x": 150,
        "y": 640,
        "wires": [
            [
                "8e9ad35d97039b8c"
            ]
        ]
    },
    {
        "id": "c498b1f2926ea757",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "LensCode",
        "diff": true,
        "name": "",
        "x": 180,
        "y": 680,
        "wires": [
            [
                "fd75c103776eb7ce"
            ]
        ]
    },
    {
        "id": "df39632c02478634",
        "type": "join",
        "z": "b17d4b93202e9c4b",
        "name": "LensValues",
        "mode": "custom",
        "build": "string",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": ",",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "7",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 610,
        "y": 540,
        "wires": [
            [
                "2ac9919.fbaf86e"
            ]
        ]
    },
    {
        "id": "450a94417c8b71f7",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "LeftSide_Dist",
        "func": "var LeftSide_Dist = msg.topic;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 410,
        "y": 440,
        "wires": [
            [
                "df39632c02478634"
            ]
        ]
    },
    {
        "id": "f6556b2243dac15a",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "RightSide_Dist",
        "func": "var RightSide_Dist = msg.topic;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 400,
        "y": 480,
        "wires": [
            [
                "df39632c02478634"
            ]
        ]
    },
    {
        "id": "ac80af684e1dd309",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "LeftSide_Shift",
        "func": "var LeftSide_Shift = msg.topic;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 400,
        "y": 520,
        "wires": [
            [
                "df39632c02478634"
            ]
        ]
    },
    {
        "id": "08547bcbf3b641dd",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "RightSide_Shift",
        "func": "var RightSide_Shift = msg.topic;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 400,
        "y": 560,
        "wires": [
            [
                "df39632c02478634"
            ]
        ]
    },
    {
        "id": "8743a37f034305b5",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "TopLens_Angle",
        "func": "var TopLens_Angle = msg.topic;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 400,
        "y": 600,
        "wires": [
            [
                "df39632c02478634"
            ]
        ]
    },
    {
        "id": "8e9ad35d97039b8c",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "BottomLens_Angle",
        "func": "var BottomLens_Angle = msg.topic;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 390,
        "y": 640,
        "wires": [
            [
                "df39632c02478634"
            ]
        ]
    },
    {
        "id": "fd75c103776eb7ce",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "LensCode",
        "func": "var LensCode = msg.topic;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 410,
        "y": 680,
        "wires": [
            [
                "df39632c02478634"
            ]
        ]
    },
    {
        "id": "6258119e9a49c374",
        "type": "debug",
        "z": "b17d4b93202e9c4b",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 640,
        "y": 320,
        "wires": []
    },
    {
        "id": "7bfdc80134e445cf",
        "type": "debug",
        "z": "b17d4b93202e9c4b",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 780,
        "y": 420,
        "wires": []
    },
    {
        "id": "a4105ffbc5f18bd2",
        "type": "inject",
        "z": "b17d4b93202e9c4b",
        "name": "triggerSend",
        "props": [
            {
                "p": "complete",
                "v": "true",
                "vt": "bool"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 150,
        "y": 340,
        "wires": [
            [
                "df39632c02478634"
            ]
        ]
    },
    {
        "id": "cf3bbcaba93533b8",
        "type": "change",
        "z": "b17d4b93202e9c4b",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "complete",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 430,
        "y": 400,
        "wires": [
            [
                "df39632c02478634"
            ]
        ]
    },
    {
        "id": "2236dfd1.c909e",
        "type": "MySQLdatabase",
        "name": "",
        "host": "10.54.112.30",
        "port": "3306",
        "db": "beamshaper",
        "tz": "",
        "charset": ""
    },
    {
        "id": "be6d96b1d96d301f",
        "type": "s7 endpoint",
        "transport": "iso-on-tcp",
        "address": "10.54.40.240",
        "port": "102",
        "rack": "0",
        "slot": "1",
        "localtsaphi": "01",
        "localtsaplo": "00",
        "remotetsaphi": "01",
        "remotetsaplo": "00",
        "connmode": "rack-slot",
        "adapter": "",
        "busaddr": "2",
        "cycletime": "1000",
        "timeout": "2000",
        "name": "",
        "vartable": [
            {
                "addr": "MW10",
                "name": "prgNum"
            },
            {
                "addr": "M2.0",
                "name": "startBtn"
            },
            {
                "addr": "M2.1",
                "name": "stopBtn"
            },
            {
                "addr": "M2.2",
                "name": "clearFaultBtn"
            },
            {
                "addr": "IB68",
                "name": "ro_step"
            },
            {
                "addr": "M10.0",
                "name": "clearSequence"
            },
            {
                "addr": "M200.6",
                "name": "flag_DBLog"
            },
            {
                "addr": "DB5,REAL26356",
                "name": "LeftSide_Dist"
            },
            {
                "addr": "DB5,REAL26360",
                "name": "RightSide_Dist"
            },
            {
                "addr": "DB5,REAL26364",
                "name": "LeftSide_Shift"
            },
            {
                "addr": "DB5,REAL26368",
                "name": "RightSide_Shift"
            },
            {
                "addr": "DB5,REAL26372",
                "name": "TopLens_Angle"
            },
            {
                "addr": "DB5,REAL26376",
                "name": "BottomLens_Angle"
            },
            {
                "addr": "DB5,INT26380",
                "name": "LensCode"
            }
        ]
    }
]

Hey! I have figured it out by myself!

So, I noticed that my messages were cleared after the first cycle, so what I had to do was store every reading into a different flow and then join all together again manually using a FUNCTION node.

This way, every time that I toggled the flag a new 'reading' were pulled from the flow and inserted into the SQL.

Reference: Working with context : Node-RED

[
    {
        "id": "2ac9919.fbaf86e",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "INSERT",
        "func": "var values = msg.payload;\nvar topic = \"INSERT INTO beamshaper.lensstack (LeftSide_Dist, RightSide_Dist, LeftSide_Shift, RightSide_Shift, TopLens_Angle, BottomLens_Angle, LensCode, `timestamp`) VALUES(\" + values + \", current_timestamp())\";\nmsg.topic = topic; \nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 780,
        "y": 500,
        "wires": [
            [
                "7bfdc80134e445cf",
                "fdbcc9a.f22b838"
            ]
        ]
    },
    {
        "id": "74381c4e55d860ae",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "flag_DBLog",
        "diff": true,
        "name": "",
        "x": 170,
        "y": 400,
        "wires": [
            []
        ]
    },
    {
        "id": "12f4f937ddc4e1ab",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "LeftSide_Dist",
        "diff": true,
        "name": "",
        "x": 170,
        "y": 440,
        "wires": [
            [
                "450a94417c8b71f7"
            ]
        ]
    },
    {
        "id": "4609f6479ce70b29",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "RightSide_Dist",
        "diff": true,
        "name": "",
        "x": 160,
        "y": 480,
        "wires": [
            [
                "f6556b2243dac15a"
            ]
        ]
    },
    {
        "id": "0100ebfd0ebe2d25",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "LeftSide_Shift",
        "diff": true,
        "name": "",
        "x": 170,
        "y": 520,
        "wires": [
            [
                "ac80af684e1dd309"
            ]
        ]
    },
    {
        "id": "7952fc36ed071900",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "RightSide_Shift",
        "diff": true,
        "name": "",
        "x": 160,
        "y": 560,
        "wires": [
            [
                "08547bcbf3b641dd"
            ]
        ]
    },
    {
        "id": "b54836054967eff2",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "TopLens_Angle",
        "diff": true,
        "name": "",
        "x": 160,
        "y": 600,
        "wires": [
            [
                "8743a37f034305b5"
            ]
        ]
    },
    {
        "id": "a1fa113a9c974f1e",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "BottomLens_Angle",
        "diff": true,
        "name": "",
        "x": 150,
        "y": 640,
        "wires": [
            [
                "8e9ad35d97039b8c"
            ]
        ]
    },
    {
        "id": "c498b1f2926ea757",
        "type": "s7 in",
        "z": "b17d4b93202e9c4b",
        "endpoint": "be6d96b1d96d301f",
        "mode": "single",
        "variable": "LensCode",
        "diff": true,
        "name": "",
        "x": 180,
        "y": 680,
        "wires": [
            [
                "fd75c103776eb7ce"
            ]
        ]
    },
    {
        "id": "df39632c02478634",
        "type": "join",
        "z": "b17d4b93202e9c4b",
        "name": "LensValues",
        "mode": "custom",
        "build": "string",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": ",",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 730,
        "y": 760,
        "wires": [
            []
        ]
    },
    {
        "id": "450a94417c8b71f7",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "LeftSide_Dist",
        "func": "flow.set('LeftSide_Dist', msg.payload);\n//var LeftSide_Dist = msg.topic;\n\n//return msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 370,
        "y": 440,
        "wires": [
            [
                "83be7c8397a2a346"
            ]
        ]
    },
    {
        "id": "f6556b2243dac15a",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "RightSide_Dist",
        "func": "flow.set('RightSide_Dist', msg.payload);\n\n\n//var RightSide_Dist = msg.topic;\n\n//return msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 360,
        "y": 480,
        "wires": [
            [
                "83be7c8397a2a346"
            ]
        ]
    },
    {
        "id": "ac80af684e1dd309",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "LeftSide_Shift",
        "func": "flow.set('LeftSide_Shift', msg.payload);\n//var LeftSide_Shift = msg.topic;\n\n//return msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 360,
        "y": 520,
        "wires": [
            [
                "83be7c8397a2a346"
            ]
        ]
    },
    {
        "id": "08547bcbf3b641dd",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "RightSide_Shift",
        "func": "flow.set('RightSide_Shift', msg.payload);\n\n//var RightSide_Shift = msg.topic;\n\n//return msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 360,
        "y": 560,
        "wires": [
            [
                "83be7c8397a2a346"
            ]
        ]
    },
    {
        "id": "8743a37f034305b5",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "TopLens_Angle",
        "func": "flow.set('TopLens_Angle', msg.payload);\n//var TopLens_Angle = msg.topic;\n\n//return msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 360,
        "y": 600,
        "wires": [
            [
                "83be7c8397a2a346"
            ]
        ]
    },
    {
        "id": "8e9ad35d97039b8c",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "BottomLens_Angle",
        "func": "flow.set('BottomLens_Angle', msg.payload);\n//var BottomLens_Angle = msg.topic;\n\n//return msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 350,
        "y": 640,
        "wires": [
            [
                "83be7c8397a2a346"
            ]
        ]
    },
    {
        "id": "fd75c103776eb7ce",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "LensCode",
        "func": "flow.set('LensCode', msg.payload);\n//var LensCode = msg.topic;\n\n//return msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 370,
        "y": 680,
        "wires": [
            [
                "83be7c8397a2a346"
            ]
        ]
    },
    {
        "id": "7bfdc80134e445cf",
        "type": "debug",
        "z": "b17d4b93202e9c4b",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 780,
        "y": 420,
        "wires": []
    },
    {
        "id": "a4105ffbc5f18bd2",
        "type": "inject",
        "z": "b17d4b93202e9c4b",
        "name": "triggerSend",
        "props": [
            {
                "p": "complete",
                "v": "true",
                "vt": "bool"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 370,
        "y": 360,
        "wires": [
            [
                "83be7c8397a2a346"
            ]
        ]
    },
    {
        "id": "cf3bbcaba93533b8",
        "type": "change",
        "z": "b17d4b93202e9c4b",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "complete",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 350,
        "y": 400,
        "wires": [
            []
        ]
    },
    {
        "id": "dbf5895561bd4d9b",
        "type": "change",
        "z": "b17d4b93202e9c4b",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "insert",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 780,
        "y": 640,
        "wires": [
            []
        ]
    },
    {
        "id": "75a2c35f9adb1d33",
        "type": "change",
        "z": "b17d4b93202e9c4b",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "insert",
                "pt": "flow",
                "to": "payload",
                "tot": "msg",
                "dc": true
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 600,
        "y": 640,
        "wires": [
            [
                "dbf5895561bd4d9b"
            ]
        ]
    },
    {
        "id": "83be7c8397a2a346",
        "type": "function",
        "z": "b17d4b93202e9c4b",
        "name": "Join Flows",
        "func": "var values = [];\n\nvalues[0] = flow.get(\"LeftSide_Dist\");\nvalues[1] = flow.get(\"RightSide_Dist\");\nvalues[2] = flow.get(\"LeftSide_Shift\");\nvalues[3] = flow.get(\"RightSide_Shift\");\nvalues[4] = flow.get(\"TopLens_Angle\");\nvalues[5] = flow.get(\"BottomLens_Angle\");\nvalues[6] = flow.get(\"LensCode\");\n\n//var leftside_dist = flow.get(\"LeftSide_Dist\");\n//var rightside_dist = flow.get(\"RightSide_Dist\");\n\nmsg.payload = values.join(\",\");\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 570,
        "y": 540,
        "wires": [
            [
                "2ac9919.fbaf86e"
            ]
        ]
    },
    {
        "id": "ff02ad32766c0a54",
        "type": "trigger",
        "z": "b17d4b93202e9c4b",
        "name": "",
        "op1": "1",
        "op2": "0",
        "op1type": "val",
        "op2type": "val",
        "duration": "250",
        "extend": "false",
        "overrideDelay": "false",
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 320,
        "y": 800,
        "wires": [
            []
        ]
    },
    {
        "id": "be6d96b1d96d301f",
        "type": "s7 endpoint",
        "transport": "iso-on-tcp",
        "address": "10.54.40.240",
        "port": "102",
        "rack": "0",
        "slot": "1",
        "localtsaphi": "01",
        "localtsaplo": "00",
        "remotetsaphi": "01",
        "remotetsaplo": "00",
        "connmode": "rack-slot",
        "adapter": "",
        "busaddr": "2",
        "cycletime": "1000",
        "timeout": "2000",
        "name": "",
        "vartable": [
            {
                "addr": "MW10",
                "name": "prgNum"
            },
            {
                "addr": "M2.0",
                "name": "startBtn"
            },
            {
                "addr": "M2.1",
                "name": "stopBtn"
            },
            {
                "addr": "M2.2",
                "name": "clearFaultBtn"
            },
            {
                "addr": "IB68",
                "name": "ro_step"
            },
            {
                "addr": "M10.0",
                "name": "clearSequence"
            },
            {
                "addr": "M200.6",
                "name": "flag_DBLog"
            },
            {
                "addr": "DB5,REAL26356",
                "name": "LeftSide_Dist"
            },
            {
                "addr": "DB5,REAL26360",
                "name": "RightSide_Dist"
            },
            {
                "addr": "DB5,REAL26364",
                "name": "LeftSide_Shift"
            },
            {
                "addr": "DB5,REAL26368",
                "name": "RightSide_Shift"
            },
            {
                "addr": "DB5,REAL26372",
                "name": "TopLens_Angle"
            },
            {
                "addr": "DB5,REAL26376",
                "name": "BottomLens_Angle"
            },
            {
                "addr": "DB5,INT26380",
                "name": "LensCode"
            }
        ]
    }
]
1 Like

I'm glad you found a solution.

I am not familiar with the S7 so I don't know the format of the data it delivers.
But I do know that the 7 function nodes in your first posted flow, eg

var RightSide_Dist = msg.topic;

return msg;

do effectively nothing, which might be why your join node was not achieving what you expected, or maybe you were sending msg.complete at the wrong time.

Also your ingenious construction of the INSERT statement is not the ideal format.

But anyway, you have it working, good job. :slightly_smiling_face:

1 Like

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