NodeRed OpcUa PLC - READ MULTIPLE Can't split after OpcUaClient

Hello
As a lot of others topic, I hope I will get my answer here :slight_smile:
I would like to read data from a plc. I tried with the node 'Read' but it need an OpcUa-Client for each variable I want to read, and my plc is limited at 15 sessions so... not good anymore...

So I have found that I could use 'Read multiple' and then I could use a function or a commuter to split 3 variables that I putted in my 'Read multiple'

the version 1 is working properly but in the limit of X sessions

And here the V2 with a Read multiple that is reading in entrance but not splitting in ouput !

I can see my 3 variables being read via OpcUaClient but I cant split them in 3 after.... I tried with a function that will look for the msg.topic and then separate it in 3 output but I have in output a msg.topic : undefined

So..... I try with a switch and in my switch, I look if msg.topic got 'In_Counter' or 'out_Counter' or 'Status'. it is supposed to be very simple in my head but it is very diffcult to find a working solution on the internet.

I tried a lot of different things in function or switch node, but nothing works ! I will give a tip via Paypal to the person that has the working solution :saluting_face: :innocent:

code :

[
    {
        "id": "d85dd4e7.e244b",
        "type": "tab",
        "label": "read_multiple",
        "disabled": false,
        "info": ""
    },
    {
        "id": "ed421a9.d6319e8",
        "type": "OpcUa-Client",
        "z": "d85dd4e7.e244b",
        "endpoint": "dd0eae807bd57326",
        "action": "readmultiple",
        "deadbandtype": "a",
        "deadbandvalue": 1,
        "time": 10,
        "timeUnit": "s",
        "certificate": "n",
        "localfile": "",
        "localkeyfile": "",
        "folderName4PKI": "",
        "useTransport": false,
        "maxChunkCount": "",
        "maxMessageSize": "",
        "receiveBufferSize": "",
        "sendBufferSize": "",
        "name": "Automate L10",
        "x": 640,
        "y": 220,
        "wires": [
            [
                "2421fd9c16519628",
                "f993fd12.db5e98",
                "d7e4749671b4c569",
                "3e33934d3307dbda"
            ]
        ]
    },
    {
        "id": "2c050a3d.91f496",
        "type": "inject",
        "z": "d85dd4e7.e244b",
        "name": "Read multiple items",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": "1",
        "topic": "readmultiple",
        "payload": "",
        "payloadType": "str",
        "x": 340,
        "y": 80,
        "wires": [
            [
                "ed421a9.d6319e8"
            ]
        ]
    },
    {
        "id": "690e4f9f.faeca",
        "type": "inject",
        "z": "d85dd4e7.e244b",
        "name": "Clear nodeId array",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "clearitems",
        "payload": "",
        "payloadType": "str",
        "x": 350,
        "y": 120,
        "wires": [
            [
                "ed421a9.d6319e8"
            ]
        ]
    },
    {
        "id": "b71fa7364ff1958f",
        "type": "OpcUa-Item",
        "z": "d85dd4e7.e244b",
        "item": "ns=3;s=\"570PR10\".\"SCROLL\".\"2_Out_Counter_1\"",
        "datatype": "Int32",
        "value": "",
        "name": "MACHINE 1 COMPTEUR OUT",
        "x": 330,
        "y": 220,
        "wires": [
            [
                "ed421a9.d6319e8"
            ]
        ]
    },
    {
        "id": "2e63235fd8f881ad",
        "type": "OpcUa-Item",
        "z": "d85dd4e7.e244b",
        "item": "ns=3;s=\"570PR10\".\"SCROLL\".\"1_IN_Counter_1\"",
        "datatype": "Int32",
        "value": "",
        "name": "MACHINE 1 COMPTEUR IN",
        "x": 340,
        "y": 180,
        "wires": [
            [
                "ed421a9.d6319e8"
            ]
        ]
    },
    {
        "id": "dd2605ecf1540a19",
        "type": "OpcUa-Item",
        "z": "d85dd4e7.e244b",
        "item": "ns=3;s=\"570PR10\".\"SCROLL\".\"3_STATE\"",
        "datatype": "Int16",
        "value": "",
        "name": "MACHINE 1 STATUS",
        "x": 360,
        "y": 260,
        "wires": [
            [
                "ed421a9.d6319e8"
            ]
        ]
    },
    {
        "id": "ed3864b67fc24355",
        "type": "inject",
        "z": "d85dd4e7.e244b",
        "name": "Add item",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "Scroll_Cpt_in1",
        "payload": "",
        "payloadType": "str",
        "x": 120,
        "y": 180,
        "wires": [
            [
                "2e63235fd8f881ad"
            ]
        ]
    },
    {
        "id": "c6127a988e62fe8e",
        "type": "inject",
        "z": "d85dd4e7.e244b",
        "name": "Add item",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "Scroll_Cpt_out1",
        "payload": "",
        "payloadType": "str",
        "x": 120,
        "y": 220,
        "wires": [
            [
                "b71fa7364ff1958f"
            ]
        ]
    },
    {
        "id": "20ba81a2288b98fd",
        "type": "inject",
        "z": "d85dd4e7.e244b",
        "name": "Add item",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "Scroll_status",
        "payload": "",
        "payloadType": "str",
        "x": 120,
        "y": 260,
        "wires": [
            [
                "dd2605ecf1540a19"
            ]
        ]
    },
    {
        "id": "2421fd9c16519628",
        "type": "function",
        "z": "d85dd4e7.e244b",
        "name": "function 11",
        "func": "var msg1={};\nvar msg2={};\nvar msg3={};\n\nvar topic = msg.topic;\nvar payload = msg.payload;\nvar msgid = msg._msgid;\n\nif (topic == \"ns=3;s=570PR10.SCROLL.1_IN_Counter_1\") {\n    msg1.payload = payload;\n    msg1.topic = topic;\n    msg1._msgid = msgid;\n}\n\nif (topic == \"ns=3;s=570PR10.SCROLL.2_OUT_Counter_1\") \n{ \n    msg2.payload = payload;\n    msg2.topic = topic;\n   msg2._msgid = msgid;\n}\n\nif (topic == \"ns=3;s=570PR10.SCROLL.3_STATE\") \n{\n    msg3.payload = payload;\n    msg3.topic = topic;\n    msg3._msgid = msgid;\n}\n\nreturn [msg1,msg2,msg3];",
        "outputs": 3,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 950,
        "y": 220,
        "wires": [
            [
                "42531b6b5c221518",
                "716f4370cd731f2f"
            ],
            [
                "68b60247e9835922",
                "fd343c19f2876a1c"
            ],
            [
                "14860ad822a61216",
                "6ba368b395d3950b"
            ]
        ]
    },
    {
        "id": "3e33934d3307dbda",
        "type": "switch",
        "z": "d85dd4e7.e244b",
        "name": "",
        "property": "responseTopic",
        "propertyType": "msg",
        "rules": [
            {
                "t": "cont",
                "v": "1_IN",
                "vt": "flow"
            },
            {
                "t": "cont",
                "v": "2_Out",
                "vt": "flow"
            },
            {
                "t": "cont",
                "v": "3_STATE",
                "vt": "flow"
            }
        ],
        "checkall": "true",
        "repair": true,
        "outputs": 3,
        "x": 940,
        "y": 620,
        "wires": [
            [],
            [],
            []
        ]
    },
    {
        "id": "f993fd12.db5e98",
        "type": "debug",
        "z": "d85dd4e7.e244b",
        "name": "entrée Topic",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "topic",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 950,
        "y": 80,
        "wires": []
    },
    {
        "id": "d7e4749671b4c569",
        "type": "debug",
        "z": "d85dd4e7.e244b",
        "name": "entree_payload",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 960,
        "y": 120,
        "wires": []
    },
    {
        "id": "716f4370cd731f2f",
        "type": "ui_gauge",
        "z": "d85dd4e7.e244b",
        "name": "",
        "group": "9be63bcf027d9dce",
        "order": 4,
        "width": 0,
        "height": 0,
        "gtype": "gage",
        "title": "Compteur Entrée",
        "label": "units",
        "format": "{{value}}",
        "min": 0,
        "max": "4500",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "x": 1250,
        "y": 260,
        "wires": []
    },
    {
        "id": "68b60247e9835922",
        "type": "ui_gauge",
        "z": "d85dd4e7.e244b",
        "name": "",
        "group": "9be63bcf027d9dce",
        "order": 4,
        "width": 0,
        "height": 0,
        "gtype": "gage",
        "title": "Compteur Sortie",
        "label": "units",
        "format": "{{value}}",
        "min": 0,
        "max": "4500",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "x": 1240,
        "y": 360,
        "wires": []
    },
    {
        "id": "42531b6b5c221518",
        "type": "debug",
        "z": "d85dd4e7.e244b",
        "name": "Sortie TT 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "topic",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1230,
        "y": 220,
        "wires": []
    },
    {
        "id": "fd343c19f2876a1c",
        "type": "debug",
        "z": "d85dd4e7.e244b",
        "name": "Sortie TT 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "topic",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1230,
        "y": 400,
        "wires": []
    },
    {
        "id": "14860ad822a61216",
        "type": "function",
        "z": "d85dd4e7.e244b",
        "name": "function 10",
        "func": "var payload = msg.payload;\nif (payload == \"0\") {\n    msg.payload = \"UNKNOWN\";\n} else if (payload == \"1\") {\n    msg.payload = \"RUNNING\";\n} else if (payload == \"2\") {\n    msg.payload = \"Slow Down\";\n} else if (payload == \"3\") {\n    msg.payload = \"Waiting \";\n} else if (payload == \"4\") {\n    msg.payload = \"Block : Saturation\";\n   \n} else if (payload == \"5\") {\n    msg.payload = \"mACHINE REASON CODE \";\n\n\n    msg.payload = String(payload);\n}\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1230,
        "y": 500,
        "wires": [
            [
                "7502e8207a815ab4"
            ]
        ]
    },
    {
        "id": "7502e8207a815ab4",
        "type": "ui_text",
        "z": "d85dd4e7.e244b",
        "group": "48d21401497a0d52",
        "order": 1,
        "width": 0,
        "height": 0,
        "name": "",
        "label": "Status",
        "format": "{{msg.payload}}",
        "layout": "row-spread",
        "x": 1390,
        "y": 500,
        "wires": []
    },
    {
        "id": "6ba368b395d3950b",
        "type": "debug",
        "z": "d85dd4e7.e244b",
        "name": "Sortie TT 3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "topic",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1230,
        "y": 540,
        "wires": []
    },
    {
        "id": "dd0eae807bd57326",
        "type": "OpcUa-Endpoint",
        "endpoint": "opc.tcp://5.123.12.127:4840",
        "secpol": "None",
        "secmode": "None",
        "none": false,
        "login": false,
        "usercert": false,
        "usercertificate": "",
        "userprivatekey": ""
    },
    {
        "id": "9be63bcf027d9dce",
        "type": "ui_group",
        "name": "Compteurs",
        "tab": "766c1938589028f0",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "48d21401497a0d52",
        "type": "ui_group",
        "name": "Etat Scroll",
        "tab": "766c1938589028f0",
        "order": 2,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "766c1938589028f0",
        "type": "ui_tab",
        "name": "SCROLL",
        "icon": "dashboard",
        "order": 2,
        "disabled": false,
        "hidden": false
    }
]```
1 Like

maybe - switch node set to look at msg.topic.nodeId
contains [String] 1_IN
contains [String] 2_Out
contains [String] 3_STATE

1 Like

Hello, I have try topic.nodeid but it is topic.nodeId .... all this for synthax of i/I
what is your paypal dceejay I send you some credits :smiley:

1 Like

No worries, just pay it forwards by helping someone else out round here :slight_smile:

5 Likes

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