- Schneider Electric PLC: TM251MESE
- Firmware: V5.2.11.24
- PLC Software: Machine Expert V2.2.2 (Codesys based)
- OPC UA Browser: UA Expert 1.7.1
- node-red nodes: node-red-contrib-opcua 0.2.339 / @opcua/for-node-red 3.8.0
- Node Red: V4.0.9
Hello,
I'm running into an issue with reading strings out of the OPC UA server in my PLC. Often the string value in the PLC don't match in the couple of node-red nodes I've tried so far. Using UA Expert, the string values always match the PLC.
What happens is that the strings in node-red can sometimes have garbage characters or remnants of the last message read from the PLC.
This picture shows the values not matching between the three software's. I had set the string to be empty in the PLC and remnant values stayed in the node-red.
This one shows remnants being attached to the end of the null in the message. It should be AAA1 and that's it.
I've attached my flow to see if I could get assistance with this.
[
{
"id": "e8a37527a489be6a",
"type": "tab",
"label": "Debug Flow",
"disabled": false,
"info": "",
"env": []
},
{
"id": "c64e272d41a2adad",
"type": "comment",
"z": "e8a37527a489be6a",
"name": "Read the tag values from PLC over OPC UA",
"info": "",
"x": 210,
"y": 80,
"wires": []
},
{
"id": "aa7eff6a65a94761",
"type": "OpcUa-Item",
"z": "e8a37527a489be6a",
"item": "ns=2;s=Memory_Words.CODES[0]",
"datatype": "String",
"value": "",
"name": "codes",
"x": 370,
"y": 120,
"wires": [
[
"1efbb414347444f3"
]
]
},
{
"id": "d51ce7ac3affe287",
"type": "function",
"z": "e8a37527a489be6a",
"name": "String Clean",
"func": "if (typeof msg.payload === \"string\") {\n // Split at the first null character (if any) and trim any extra spaces.\n let cleaned = msg.payload.split(\"\\0\")[0].trim();\n msg.payload = cleaned;\n}\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 890,
"y": 100,
"wires": [
[
"d57c8cf01f98280a"
]
]
},
{
"id": "d57c8cf01f98280a",
"type": "debug",
"z": "e8a37527a489be6a",
"name": "Cleaned",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1080,
"y": 200,
"wires": []
},
{
"id": "db4e604075f499b6",
"type": "debug",
"z": "e8a37527a489be6a",
"name": "Payload",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 800,
"y": 200,
"wires": []
},
{
"id": "1efbb414347444f3",
"type": "OpcUa-Client",
"z": "e8a37527a489be6a",
"endpoint": "a3af1c676fc10c9c",
"action": "subscribe",
"deadbandtype": "a",
"deadbandvalue": 1,
"time": "200",
"timeUnit": "ms",
"certificate": "n",
"localfile": "",
"localkeyfile": "",
"securitymode": "None",
"securitypolicy": "None",
"useTransport": false,
"maxChunkCount": 1,
"maxMessageSize": 8192,
"receiveBufferSize": 8192,
"sendBufferSize": 8192,
"setstatusandtime": false,
"keepsessionalive": false,
"name": "",
"x": 620,
"y": 120,
"wires": [
[
"db4e604075f499b6",
"d51ce7ac3affe287"
],
[],
[]
]
},
{
"id": "6f6ee340ec4eaf29",
"type": "inject",
"z": "e8a37527a489be6a",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 140,
"y": 120,
"wires": [
[
"aa7eff6a65a94761"
]
]
},
{
"id": "a3af1c676fc10c9c",
"type": "OpcUa-Endpoint",
"endpoint": "opc.tcp://110.8.34.2:4840",
"secpol": "None",
"secmode": "None",
"none": true,
"login": false,
"usercert": false,
"usercertificate": "",
"userprivatekey": ""
}
]