In my Node-red flow, i am taking data from Siemens PLC through OPC-UA node in node-red. I'm getting data perfectly for some-time(meaning whatever changes i make in Tia portal program is also shows in node-red debug window.[Refer to screenshot -1]).
But after certain time(2-3 minutes), whatever changes i made at Tia portal program does not reflected back in node-red debug window[Refer to screenshot -2]. I don't know why?
Also, OPCUA node status is also changing from "'Active subscribing' to 'keep-alive' to 'active subscribing'.........."
I am using
- Tia portal[Siemens V16]
- PLC sim advanced V2.0
- Node-red(windows 11)
- OPCUA contrib node(but not IIOT OPCUA node)
Those who need my-node-red flow, i have pasted it here.
[
{
"id": "b5d2b5d70adc9eec",
"type": "tab",
"label": "Flow 4",
"disabled": false,
"info": "",
"env": []
},
{
"id": "06942aed7746321a",
"type": "function",
"z": "b5d2b5d70adc9eec",
"name": "NodeId Array (Static variables)",
"func": "// Tested with Prosys static variables\nmsg.topic = \"multiple\";\nmsg.payload = [];\nmsg.payload.push({ nodeId: 'ns=3;s=\\\"SQL\".\"Excel_log_bit\"'});\nmsg.payload.push({ nodeId: 'ns=3;s=\\\"SQL\".\"H_CoExtRunTime\"'});\nmsg.payload.push({ nodeId: 'ns=3;s=\\\"SQL\".\"H_TotDefDrum\"' });\nmsg.payload.push({ nodeId: 'ns=3;s=\\\"SQL\".\"H_TotProdDrum\"'});\nmsg.payload.push({ nodeId: 'ns=3;s=\\\"SQL\".\"H_Act_Length\"'});\nmsg.payload.push({ nodeId: 'ns=3;s=\\\"SQL\".\"AvgSpeed\"' });\nmsg.payload.push({ nodeId: 'ns=3;s=\\\"SQL\".\"H_AWGrm/Mtr\"'});\nmsg.payload.push({ nodeId: 'ns=3;s=\\\"SQL\".\"H_CoExtScrapAct\"'});\nmsg.payload.push({ nodeId: 'ns=3;s=\\\"SQL\".\"H_Defects\"'});\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 490,
"y": 280,
"wires": [
[
"70152a7ad43e3a4c"
]
]
},
{
"id": "4842bce434c17963",
"type": "inject",
"z": "b5d2b5d70adc9eec",
"name": "Subscribe multiple",
"props": [
{
"p": "topic",
"vt": "str"
}
],
"repeat": "1",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "multiple",
"x": 210,
"y": 280,
"wires": [
[
"06942aed7746321a"
]
]
},
{
"id": "67c900801f738564",
"type": "function",
"z": "b5d2b5d70adc9eec",
"name": "Just value",
"func": "if (msg.payload && msg.payload.value) {\n var value = msg.payload.value.value;\n msg.payload = value;\n return msg;\n}\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 920,
"y": 280,
"wires": [
[
"f06aa782df1ad63e"
]
]
},
{
"id": "a20ea5df904b241e",
"type": "debug",
"z": "b5d2b5d70adc9eec",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1510,
"y": 260,
"wires": []
},
{
"id": "f06aa782df1ad63e",
"type": "join",
"z": "b5d2b5d70adc9eec",
"name": "",
"mode": "custom",
"build": "object",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "9",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 1050,
"y": 280,
"wires": [
[
"cabe61a302bbe43b"
]
]
},
{
"id": "95dd18ccee2f5d60",
"type": "function",
"z": "b5d2b5d70adc9eec",
"name": "function 20",
"func": "msg.payload = {\n \"Excel_log_bit\": msg.payload['ns=3;s=\\\"SQL\".\"Excel_log_bit\"'] == true? 1 : 0,\n \"H_CoExtRunTime\": msg.payload['ns=3;s=\\\"SQL\".\"H_CoExtRunTime\"'],\n \"H_TotDefDrum\": msg.payload['ns=3;s=\\\"SQL\".\"H_TotDefDrum\"'],\n \"H_TotProdDrum\": msg.payload['ns=3;s=\\\"SQL\".\"H_TotProdDrum\"'],\n \"H_Act_Length\": msg.payload['ns=3;s=\\\"SQL\".\"H_Act_Length\"'],\n \"AvgSpeed\": msg.payload['ns=3;s=\\\"SQL\".\"AvgSpeed\"'],\n \"H_AWGrm/Mtr\": msg.payload['ns=3;s=\\\"SQL\".\"H_AWGrm/Mtr\"'],\n \"H_CoExtScrapAct\": msg.payload['ns=3;s=\\\"SQL\".\"H_CoExtScrapAct\"'],\n \"H_Defects\": msg.payload['ns=3;s=\\\"SQL\".\"H_Defects\"']\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1330,
"y": 280,
"wires": [
[
"a20ea5df904b241e"
]
]
},
{
"id": "c44ead5f3ce4f08e",
"type": "comment",
"z": "b5d2b5d70adc9eec",
"name": "Try-5",
"info": "",
"x": 170,
"y": 240,
"wires": []
},
{
"id": "70152a7ad43e3a4c",
"type": "OpcUa-Client",
"z": "b5d2b5d70adc9eec",
"endpoint": "3ec188ec73ca536f",
"action": "subscribe",
"deadbandtype": "a",
"deadbandvalue": 1,
"time": "100",
"timeUnit": "ms",
"certificate": "n",
"localfile": "",
"localkeyfile": "",
"securitymode": "None",
"securitypolicy": "None",
"folderName4PKI": "",
"maxChunkCount": "",
"maxMessageSize": "",
"receiveBufferSize": "",
"sendBufferSize": "",
"name": "",
"x": 740,
"y": 280,
"wires": [
[
"67c900801f738564"
]
]
},
{
"id": "8b05d8891b583116",
"type": "comment",
"z": "b5d2b5d70adc9eec",
"name": "chat-gpt corrected program",
"info": "what i wrote:\nmsg.payload = {\n \"Excel_log_bit\": if(msg.payload['ns=3;s=\\\"SQL\".\"Excel_log_bit\"'] == true){\n return 1;\n else{\n return 0;\n },\n\n \"H_CoExtRunTime\": msg.payload['ns=3;s=\\\"SQL\".\"H_CoExtRunTime\"'],\n \"H_TotDefDrum\": msg.payload['ns=3;s=\\\"SQL\".\"H_TotDefDrum\"'],\n \"H_TotProdDrum\": msg.payload['ns=3;s=\\\"SQL\".\"H_TotProdDrum\"'],\n \"H_Act_Length\": msg.payload['ns=3;s=\\\"SQL\".\"H_Act_Length\"'],\n \"AvgSpeed\": msg.payload['ns=3;s=\\\"SQL\".\"AvgSpeed\"'],\n \"H_AWGrm/Mtr\": msg.payload['ns=3;s=\\\"SQL\".\"H_AWGrm/Mtr\"'],\n \"H_CoExtScrapAct\": msg.payload['ns=3;s=\\\"SQL\".\"H_CoExtScrapAct\"'],\n \"H_Defects\": msg.payload['ns=3;s=\\\"SQL\".\"H_Defects\"']\n}\nreturn msg;\n\n\ni was getting error, so i pasted the incorrect program as it is into microsoft bing chat gpt, to which it gave me :\nmsg.payload = {\n \"Excel_log_bit\": msg.payload['ns=3;s=\\\"SQL\".\"Excel_log_bit\"'] == true? 1 : 0,\n \"H_CoExtRunTime\": msg.payload['ns=3;s=\\\"SQL\".\"H_CoExtRunTime\"'],\n \"H_TotDefDrum\": msg.payload['ns=3;s=\\\"SQL\".\"H_TotDefDrum\"'],\n \"H_TotProdDrum\": msg.payload['ns=3;s=\\\"SQL\".\"H_TotProdDrum\"'],\n \"H_Act_Length\": msg.payload['ns=3;s=\\\"SQL\".\"H_Act_Length\"'],\n \"AvgSpeed\": msg.payload['ns=3;s=\\\"SQL\".\"AvgSpeed\"'],\n \"H_AWGrm/Mtr\": msg.payload['ns=3;s=\\\"SQL\".\"H_AWGrm/Mtr\"'],\n \"H_CoExtScrapAct\": msg.payload['ns=3;s=\\\"SQL\".\"H_CoExtScrapAct\"'],\n \"H_Defects\": msg.payload['ns=3;s=\\\"SQL\".\"H_Defects\"']\n}\nreturn msg;\n\nRESULT = It worked\n\n\n\n\n\n\nThen i asked him => correct this program and use if/else statement if required:\nmsg.payload = {\n \"Excel_log_bit\": if(msg.payload['ns=3;s=\\\"SQL\".\"Excel_log_bit\"'] == true){\n return 1;\n else{\n return 0;\n },\n\n \"H_CoExtRunTime\": msg.payload['ns=3;s=\\\"SQL\".\"H_CoExtRunTime\"'],\n \"H_TotDefDrum\": msg.payload['ns=3;s=\\\"SQL\".\"H_TotDefDrum\"'],\n \"H_TotProdDrum\": msg.payload['ns=3;s=\\\"SQL\".\"H_TotProdDrum\"'],\n \"H_Act_Length\": msg.payload['ns=3;s=\\\"SQL\".\"H_Act_Length\"'],\n \"AvgSpeed\": msg.payload['ns=3;s=\\\"SQL\".\"AvgSpeed\"'],\n \"H_AWGrm/Mtr\": msg.payload['ns=3;s=\\\"SQL\".\"H_AWGrm/Mtr\"'],\n \"H_CoExtScrapAct\": msg.payload['ns=3;s=\\\"SQL\".\"H_CoExtScrapAct\"'],\n \"H_Defects\": msg.payload['ns=3;s=\\\"SQL\".\"H_Defects\"']\n}\n\n\n\nto which it replied:\n\nvar Excel_log_bit_value;\nif (msg.payload['ns=3;s=\\\"SQL\".\"Excel_log_bit\"'] == true) {\n Excel_log_bit_value = 1;\n} else {\n Excel_log_bit_value = 0;\n}\n\nmsg.payload = {\n \"Excel_log_bit\": Excel_log_bit_value,\n \"H_CoExtRunTime\": msg.payload['ns=3;s=\\\"SQL\".\"H_CoExtRunTime\"'],\n \"H_TotDefDrum\": msg.payload['ns=3;s=\\\"SQL\".\"H_TotDefDrum\"'],\n \"H_TotProdDrum\": msg.payload['ns=3;s=\\\"SQL\".\"H_TotProdDrum\"'],\n \"H_Act_Length\": msg.payload['ns=3;s=\\\"SQL\".\"H_Act_Length\"'],\n \"AvgSpeed\": msg.payload['ns=3;s=\\\"SQL\".\"AvgSpeed\"'],\n \"H_AWGrm/Mtr\": msg.payload['ns=3;s=\\\"SQL\".\"H_AWGrm/Mtr\"'],\n \"H_CoExtScrapAct\": msg.payload['ns=3;s=\\\"SQL\".\"H_CoExtScrapAct\"'],\n \"H_Defects\": msg.payload['ns=3;s=\\\"SQL\".\"H_Defects\"']\n}\n\n\nResult - It also worked",
"x": 1310,
"y": 240,
"wires": []
},
{
"id": "cabe61a302bbe43b",
"type": "rbe",
"z": "b5d2b5d70adc9eec",
"name": "",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"septopics": false,
"property": "payload",
"topi": "topic",
"x": 1190,
"y": 280,
"wires": [
[
"95dd18ccee2f5d60"
]
]
},
{
"id": "4d2cdd99499bac90",
"type": "comment",
"z": "b5d2b5d70adc9eec",
"name": "",
"info": "If you ever get problem with changes not being reflected in debug node for subsequent changing in tia portal, then you should refer to this link.\n\n\ntype in gooogle -> opcua node interval in node red\n\n\nor directlly - https://support.industry.siemens.com/forum/in/en/posts/using-opc-ua-sampling-intervals-with-flow-creator-node-red/263016\n",
"x": 720,
"y": 240,
"wires": []
},
{
"id": "3ec188ec73ca536f",
"type": "OpcUa-Endpoint",
"endpoint": "opc.tcp://192.168.0.1:4840",
"secpol": "None",
"secmode": "None",
"none": true,
"login": false,
"usercert": false,
"usercertificate": "",
"userprivatekey": ""
}
]
[![Screenshot 1]
[![Screenshot 2]