Node-Red fast retrieval of variables

I am currently using Node-Red with the Opto22 Provided OPC pac control node, it works great, I am able to retrieve a fairly large table once per second.
I have noticed, specially when running node-red on a non-local instance, that when there is a network issue, and it gets reconnected, data starts lagging, with events where the observed data is minutes behind the real condition.
I am not sure if this is caused by the tcp nature of the request, or if the node itself has a buffer, attempting to retrieve older messages.
The issue is cleared when the node-red is restarted, or a change is deployed.

but my question is regarding the best approach when it comes to retrieving the “latest” status of the variable, in my case, I dont need the older values, I just need the latest “current” value, is the Opto22 node still a good approach? or should I look into a Modbus request instead?

Regards

For high-speed reading (less than 1s scan time) I have gotten really great results with UDP streaming configured via OptoMMP, is that something that would work for your application?

Here are some posts on how I’ve set up UDP streaming with Node-RED:

1 Like

Yes, that would actually work. the only difference is that I would need to read a pac control variable, rather than a digital input, I need to dive a little into the documentation to find out the mapping, worst case scenario I can use a PID loop and read the address from there.
I will post the results, thank you.

Just updating, I ended up using the proposed method, with a few mods, turns out the scratchpad makes the application of this method super simple.

[{"id":"5ca075183bfa0a75","type":"tab","label":"UDP Transmission","disabled":false,"info":"","env":[]},{"id":"45c76d95c34ea450","type":"inject","z":"5ca075183bfa0a75","name":"","props":[{"p":"timestamp","v":"","vt":"date"}],"repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"","x":430,"y":120,"wires":[["0700d01695aca07b"]]},{"id":"d07506ab7afabd8e","type":"udp in","z":"5ca075183bfa0a75","name":"","iface":"","port":"5001","ipv":"udp4","multicast":"false","group":"","datatype":"buffer","x":380,"y":440,"wires":[["f25ec8682c024ba2","cd4e0a10de367857"]]},{"id":"44c3872ef114e7f6","type":"inject","z":"5ca075183bfa0a75","name":"show config","props":[{"p":"timestamp","v":"","vt":"date"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":410,"y":380,"wires":[["4b5b740d8c327d57"]]},{"id":"4b5b740d8c327d57","type":"groov-io-read","z":"5ca075183bfa0a75","device":"2d72cc137285b422","dataType":"mmp-address","moduleIndex":"","channelIndex":"","mmpAddress":"0xF03FFFC0","mmpType":"int32","mmpLength":"10","mmpEncoding":"ascii","value":"","valueType":"msg.payload","itemName":"","name":"check configuration","x":610,"y":380,"wires":[["395aa9b8f9ecf40c"]]},{"id":"e7b7a5f8f38977e0","type":"groov-io-write","z":"5ca075183bfa0a75","device":"2d72cc137285b422","dataType":"mmp-address","moduleIndex":"","channelIndex":"","mmpAddress":"0xF03FFFD0","mmpType":"int32","mmpLength":"1","mmpEncoding":"ascii","value":"1","valueType":"value","name":"enable streaming","x":610,"y":320,"wires":[["4b5b740d8c327d57"]]},{"id":"395aa9b8f9ecf40c","type":"debug","z":"5ca075183bfa0a75","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":790,"y":380,"wires":[]},{"id":"47cd51ad35c31c4b","type":"groov-io-write","z":"5ca075183bfa0a75","device":"2d72cc137285b422","dataType":"mmp-address","moduleIndex":"","channelIndex":"","mmpAddress":"0xF03FFFD0","mmpType":"int32","mmpLength":"1","mmpEncoding":"ascii","value":"0","valueType":"value","name":"0xF03FFFD0 = 0","x":670,"y":560,"wires":[[]]},{"id":"d47539594853ebb2","type":"inject","z":"5ca075183bfa0a75","name":"disable streaming","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":420,"y":560,"wires":[["47cd51ad35c31c4b"]]},{"id":"0700d01695aca07b","type":"groov-io-write","z":"5ca075183bfa0a75","device":"2d72cc137285b422","dataType":"mmp-address","moduleIndex":"","channelIndex":"","mmpAddress":"0xF03FFFC8","mmpType":"int32","mmpLength":"1","mmpEncoding":"ascii","value":"-254271488","valueType":"value","name":"set starting address","x":610,"y":120,"wires":[["a52fd550be24d5f9"]]},{"id":"a52fd550be24d5f9","type":"groov-io-write","z":"5ca075183bfa0a75","device":"2d72cc137285b422","dataType":"mmp-address","moduleIndex":"","channelIndex":"","mmpAddress":"0xF03FFFCC","mmpType":"int32","mmpLength":"1","mmpEncoding":"ascii","value":"40","valueType":"value","name":"set read length","x":600,"y":160,"wires":[["54480238cf6814a1"]]},{"id":"f25ec8682c024ba2","type":"debug","z":"5ca075183bfa0a75","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":550,"y":480,"wires":[]},{"id":"54480238cf6814a1","type":"groov-io-write","z":"5ca075183bfa0a75","device":"2d72cc137285b422","dataType":"mmp-address","moduleIndex":"","channelIndex":"","mmpAddress":"0xF03FFFD4","mmpType":"int32","mmpLength":"1","mmpEncoding":"ascii","value":"500","valueType":"value","name":"set stream interval","x":610,"y":200,"wires":[["58e87c1faf646a31"]]},{"id":"58e87c1faf646a31","type":"groov-io-write","z":"5ca075183bfa0a75","device":"2d72cc137285b422","dataType":"mmp-address","moduleIndex":"","channelIndex":"","mmpAddress":"0xF03FFFE0","mmpType":"uint32","mmpLength":"1","mmpEncoding":"ascii","value":"2130706433","valueType":"value","name":"set IP address","x":600,"y":240,"wires":[["e68faded3283fd21"]]},{"id":"ce3291e311e6e745","type":"debug","z":"5ca075183bfa0a75","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":480,"wires":[]},{"id":"cd4e0a10de367857","type":"function","z":"5ca075183bfa0a75","name":"","func":"function bytesToFloat(bytes) {\n  var buf = Buffer.from(bytes);\n  return buf.readFloatBE(0);\n}\n\n// Usage:\nvar payload = msg.payload;\nvar payloadSize = payload.length;\nvar numValues = Math.floor((payloadSize - 8) / 4); // Calculate numValues based on payload size\nvar floatArray = [];\n\nfor (var i = 0; i < numValues; i++) {\n  var startIdx = i * 4 + 8;\n  var endIdx = startIdx + 4;\n  var floatValue = bytesToFloat(payload.slice(startIdx, endIdx));\n  floatArray.push(floatValue);\n}\n\nmsg.float = floatArray;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":440,"wires":[["ce3291e311e6e745","62d2cebc0fb56f94"]]},{"id":"62d2cebc0fb56f94","type":"change","z":"5ca075183bfa0a75","name":"","rules":[{"t":"set","p":"telemetry.float","pt":"global","to":"float","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":440,"wires":[[]]},{"id":"e68faded3283fd21","type":"groov-io-write","z":"5ca075183bfa0a75","device":"2d72cc137285b422","dataType":"mmp-address","moduleIndex":"","channelIndex":"","mmpAddress":"0xF03FFFE4","mmpType":"uint32","mmpLength":"1","mmpEncoding":"ascii","value":"3232236644","valueType":"value","name":"set Additional IP address ","x":630,"y":280,"wires":[["e7b7a5f8f38977e0"]]},{"id":"2d72cc137285b422","type":"groov-io-device","address":"localhost","msgQueueFullBehavior":"DROP_OLD"}]
1 Like