How to create a JSON variable to store an OPCUA value

Hello!
I'm actually working on a project to retrieve OPCUA values from a PLC and visualize them on a cloud dashboard.
I managed to get the data I wanted but I struggle to send this via http request on the cloud because I need to create a variable in which I put my value but I'm still new to JSON and I have a hard time.

This is the flow test I use :

[
    {
        "id": "f6f2187d.f17ca8",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "4f334e053634725e",
        "type": "inject",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "3",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 190,
        "y": 160,
        "wires": [
            [
                "d0c4eb982759f2ac"
            ]
        ]
    },
    {
        "id": "a62a82e24bca7c42",
        "type": "OpcUa-Client",
        "z": "f6f2187d.f17ca8",
        "endpoint": "5dc2ebaa05a6e5e7",
        "action": "read",
        "deadbandtype": "a",
        "deadbandvalue": 1,
        "time": 10,
        "timeUnit": "s",
        "certificate": "n",
        "localfile": "",
        "localkeyfile": "",
        "securitymode": "None",
        "securitypolicy": "None",
        "folderName4PKI": "",
        "name": "",
        "x": 580,
        "y": 160,
        "wires": [
            [
                "2b4511368d9eee07"
            ]
        ]
    },
    {
        "id": "d0c4eb982759f2ac",
        "type": "OpcUa-Event",
        "z": "f6f2187d.f17ca8",
        "root": "ns=4;i=4",
        "activatecustomevent": false,
        "eventtype": "i=2041",
        "customeventtype": "",
        "name": "",
        "x": 380,
        "y": 160,
        "wires": [
            [
                "a62a82e24bca7c42"
            ]
        ]
    },
    {
        "id": "2b4511368d9eee07",
        "type": "function",
        "z": "f6f2187d.f17ca8",
        "name": "function 1",
        "func": "if (msg.payload === true) {\n    var msg1 = {};\n    msg1.payload = msg.payload;\n    msg1.topic = 'opcua1';\n    return msg1;\n} \n\nelse if (msg.payload === false) {\n    var msg2 = {};\n    msg2.payload = msg.payload;\n    msg2.topic = 'opcua2';\n    return msg2;\n}\n\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 740,
        "y": 160,
        "wires": [
            [
                "0cd9518bbaaf96a9",
                "9053f13984c6be77"
            ]
        ]
    },
    {
        "id": "0cd9518bbaaf96a9",
        "type": "json",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 930,
        "y": 160,
        "wires": [
            [
                "3afd4b110eee572a",
                "4981a025e4ae097b"
            ]
        ]
    },
    {
        "id": "ea1ce0c1d90a58a6",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "debug 1",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 1300,
        "y": 160,
        "wires": []
    },
    {
        "id": "4981a025e4ae097b",
        "type": "http request",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "http://192.168.200.90:81/tdce/nodered/api",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 1130,
        "y": 160,
        "wires": [
            [
                "ea1ce0c1d90a58a6"
            ]
        ]
    },
    {
        "id": "3afd4b110eee572a",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "debug 2",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 960,
        "y": 120,
        "wires": []
    },
    {
        "id": "9053f13984c6be77",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "debug 3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 740,
        "y": 120,
        "wires": []
    },
    {
        "id": "5dc2ebaa05a6e5e7",
        "type": "OpcUa-Endpoint",
        "endpoint": "opc.tcp://192.168.200.70:4840",
        "secpol": "None",
        "secmode": "None",
        "none": true,
        "login": false,
        "usercert": false,
        "usercertificate": "",
        "userprivatekey": ""
    }
]

Welcome to the forum!

Could you please post just the data you are trying to send, your flow contains nodes that not everyone has installed, which makes it difficult to test. The output of your debug 2 node is probably what you need.

Hi Ghayne !

For my test I created in my PLC a variable OPCUA which is a boolean variable that goes from true to false at certain intervals. The Id of this variable is ns=4;i=4.
Oh and sorry for not specifying in my post but I use node-red-contrib-opcua to get my data.
This is my first post so I don't have all the right reflexes yet :sweat_smile:.

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