Hi All, Please disregard this question, I think I figured out the solution. It's much easier than I was thinking to allow the creation of a new msg object and have it saved properly on the pass through of another node.
Hi All,
New to Node Red here have a question on how we handle pass through values. The specific example I'm trying to solve is to create a OPC monitor which pulls selected nodes from a SQL Server then passes those nodes to OPCUA which retrieves the value then stores back into SQL Server. I have the base working fine however, I'm struggling in how to handle the id of my nodes. In the below example I pull a list of ID's and Nodes from a given table. I then loop through this list and pass the Node id to the OPCUA client. How can I pass the ID to the OPCUA client without it trying to use it as a node? Instead I only want to match the id with the value returned from the OPCUA client.
Thanks!
Craig
[{"id":"4011d7fc.c791d8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"d81df181.aec6b","type":"inject","z":"4011d7fc.c791d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"15","topic":"ns=4;s=Demo.BoilerDemo.Boiler1.FillLevelSensor.FillLevel;datatype=Double","payload":"","payloadType":"date","x":120,"y":580,"wires":[["9c040248.fd76e"]]},{"id":"95fce55d.7fb628","type":"inject","z":"4011d7fc.c791d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"30","topic":"ns=4;s=Demo.BoilerDemo.Boiler1.TemperatureSensor.Temperature;datatype=Double","payload":"","payloadType":"date","x":120,"y":740,"wires":[["9c040248.fd76e"]]},{"id":"2ed79708.c13f68","type":"template","z":"4011d7fc.c791d8","name":"SQL Script","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"INSERT INTO OPC_Test(Node, Value) VALUES ('Test',{{payload}});","output":"str","x":770,"y":600,"wires":[["50a0c33e.c2116c","1a5124e8.0d35eb"]]},{"id":"50a0c33e.c2116c","type":"MSSQL","z":"4011d7fc.c791d8","mssqlCN":"e7d03fe4.833fd","name":"MSSQL","query":"","outField":"payload","x":1100,"y":600,"wires":[[]]},{"id":"381a7f3e.2cb6e","type":"inject","z":"4011d7fc.c791d8","name":"Get Automation Channel","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"SELECT ADDRESS FROM [Automation_Channel] WHERE AUTO_CHANNEL_ID = 1","payloadType":"str","x":150,"y":140,"wires":[["2740156.d82a1ea"]]},{"id":"1a5124e8.0d35eb","type":"debug","z":"4011d7fc.c791d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1090,"y":680,"wires":[]},{"id":"9c040248.fd76e","type":"OpcUa-Client","z":"4011d7fc.c791d8","endpoint":"21ab681f.beedd8","action":"read","deadbandtype":"a","deadbandvalue":1,"time":10,"timeUnit":"s","certificate":"n","localfile":"","localkeyfile":"","securitymode":"None","securitypolicy":"None","name":"","x":480,"y":660,"wires":[["2ed79708.c13f68","7c99da2e.b19844"]]},{"id":"3cb401cd.9b27ee","type":"inject","z":"4011d7fc.c791d8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"20","topic":"ns=4;s=Demo.BoilerDemo.Boiler1.TemperatureSetPoint;datatype=Double","payload":"","payloadType":"date","x":120,"y":660,"wires":[["9c040248.fd76e"]]},{"id":"7c99da2e.b19844","type":"ui_gauge","z":"4011d7fc.c791d8","name":"","group":"d44d4f44.3219e8","order":2,"width":0,"height":0,"gtype":"gage","title":"gauge","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":750,"y":680,"wires":[]},{"id":"2740156.d82a1ea","type":"MSSQL","z":"4011d7fc.c791d8","mssqlCN":"e7d03fe4.833fd","name":"MSSQL","query":"","outField":"payload","x":380,"y":140,"wires":[["e3ae48f4.f33928"]]},{"id":"e9a73b84.b437f8","type":"debug","z":"4011d7fc.c791d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":140,"wires":[]},{"id":"e3ae48f4.f33928","type":"function","z":"4011d7fc.c791d8","name":"","func":"for (var i = 0; i < msg.payload.length; i++) {\n var newMsg = {};\n newMsg.payload = msg.payload[i].ADDRESS;\n node.send(newMsg);\n}\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":560,"y":140,"wires":[["e9a73b84.b437f8"]]},{"id":"f237291f.39a1c8","type":"inject","z":"4011d7fc.c791d8","name":"Get Automation Channel","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"600","crontab":"","once":false,"onceDelay":"10","topic":"","payload":"SELECT AUTO_NODE_INST_PARAM_ID, ADDRESS FROM [Automation_Node_Instance_Param] WHERE AUTO_CHANNEL_ID = 1","payloadType":"str","x":150,"y":260,"wires":[["59064002.2d732"]]},{"id":"59064002.2d732","type":"MSSQL","z":"4011d7fc.c791d8","mssqlCN":"e7d03fe4.833fd","name":"MSSQL","query":"","outField":"payload","x":380,"y":260,"wires":[["6396af62.6276c"]]},{"id":"6396af62.6276c","type":"function","z":"4011d7fc.c791d8","name":"Loop Function","func":"for (var i = 0; i < msg.payload.length; i++) {\n var newMsg = {};\n newMsg.id = msg.payload[i].AUTO_NODE_INST_PARAM_ID;\n newMsg.topic = msg.payload[i].ADDRESS;\n node.send(newMsg);\n}\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":580,"y":260,"wires":[["ee26c60f.9914b8"]]},{"id":"ee26c60f.9914b8","type":"OpcUa-Client","z":"4011d7fc.c791d8","endpoint":"21ab681f.beedd8","action":"read","deadbandtype":"a","deadbandvalue":1,"time":10,"timeUnit":"s","certificate":"n","localfile":"","localkeyfile":"","securitymode":"None","securitypolicy":"None","name":"","x":800,"y":260,"wires":[["ea1de054.fdf46","11b9d45f.cc126c"]]},{"id":"ea1de054.fdf46","type":"template","z":"4011d7fc.c791d8","name":"SQL Script","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"INSERT INTO OPC_Test(Node, Value) VALUES ('Test',{{payload}});","output":"str","x":1010,"y":260,"wires":[["c00f4241.a868"]]},{"id":"ab6918de.cc4298","type":"MSSQL","z":"4011d7fc.c791d8","mssqlCN":"e7d03fe4.833fd","name":"MSSQL","query":"","outField":"payload","x":580,"y":360,"wires":[[]]},{"id":"fa022176.f3f0b","type":"debug","z":"4011d7fc.c791d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":390,"y":440,"wires":[]},{"id":"8c106f4.164bd9","type":"delay","z":"4011d7fc.c791d8","name":"SQL Delay","pauseType":"queue","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":390,"y":360,"wires":[["ab6918de.cc4298"]]},{"id":"c00f4241.a868","type":"join","z":"4011d7fc.c791d8","name":"Join SQL Statements","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"10","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":160,"y":360,"wires":[["fa022176.f3f0b","8c106f4.164bd9"]]},{"id":"968912e2.ac10c","type":"OpcUa-Browser","z":"4011d7fc.c791d8","endpoint":"21ab681f.beedd8","item":"","datatype":"","topic":"","items":[],"name":"","x":130,"y":40,"wires":[["807d7dec.4b8d"]]},{"id":"807d7dec.4b8d","type":"ui_template","z":"4011d7fc.c791d8","group":"d44d4f44.3219e8","name":"","order":3,"width":"6","height":"10","format":"<div layout=\"row\" layout-align=\"space-between\">\n <select ng-model=\"item\" ng-options=\"items.item.displayName.txt for items in msg.payload\">\n <option value=\"\">-- Objects Root --</option>\n </select>\n</div>\nPress to update:\n<div layout=\"row\" layout-align=\"space-between\">\n <button ng-clivk=\"send({payload: {actiontype: 'browse', root: item}})\">\n Browse\n </button>\n</div>\n<div layout=\"row\" layout-align=\"space-between\">\n <ul>\n <li ng-repeat=\"items in msg.payload\">\n {{items.item.displayName.text}}: {{items.item.nodeId}}\n </li>\n </ul>\n</div>","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","x":340,"y":40,"wires":[["968912e2.ac10c"]]},{"id":"11b9d45f.cc126c","type":"debug","z":"4011d7fc.c791d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1010,"y":400,"wires":[]},{"id":"e7d03fe4.833fd","type":"MSSQL-CN","name":"SQL_Express","server":"CRAIG-DESKTOP\\SQLEXPRESS","encyption":false,"database":"OCD"},{"id":"21ab681f.beedd8","type":"OpcUa-Endpoint","endpoint":"opc.tcp://CRAIG-DESKTOP:48020","secpol":"None","secmode":"None","login":false},{"id":"d44d4f44.3219e8","type":"ui_group","name":"Sensors","tab":"34054411.bf9404","order":1,"disp":true,"width":"12","collapse":false},{"id":"34054411.bf9404","type":"ui_tab","name":"Home","icon":"dashboard"}]