I have dumbed down the nodes to the following (theres a bunch of nodes after this, but this is the confusing part):
For testing puporses, the tag checked is "Runtime", so it changes every second.
The change msg function is written as follows:
var newMsg = {};
newMsg.addressSpaceItems = [];
var nodeObj = {};
newMsg.topic = "";
newMsg.nodetype = "inject";
newMsg.injectType = "inject";
newMsg.payload = "";
nodeObj.name = "Test_Read";
nodeObj.nodeId = msg.payload.nodeId;
nodeObj.datatypeName = "Boolean";
newMsg.addressSpaceItems[0]= nodeObj;
return newMsg;
And these are the debug node responses:
So as far as i understand it, it ditches all the values and works as a glorified "If value changes, then run this node", aka a specific inject. Which the function seems to support, but what i dont understand is why anyone might do it this way?
Is that a valid understanding? Or is "Complete msg object" in debug nodes not telling me the full story?
For anyone daring enough to attempt to understand, here's the whole flow:
[{"id":"f4b229ea.02e898","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"438467b3.1e5f48","type":"function","z":"f4b229ea.02e898","name":"Change msg","func":"var newMsg = {};\nnewMsg.addressSpaceItems = [];\nvar nodeObj = {};\n\nnewMsg.topic = \"\";\nnewMsg.nodetype = \"inject\";\nnewMsg.injectType = \"inject\";\nnewMsg.payload = \"\";\nnodeObj.name = \"Test_Read\";\nnodeObj.nodeId = msg.payload.nodeId;\nnodeObj.datatypeName = \"Boolean\";\nnewMsg.addressSpaceItems[0]= nodeObj;\nreturn newMsg;\n","outputs":1,"noerr":0,"x":730,"y":220,"wires":[["9d8e679.cb3c298"]]},{"id":"76361182.89d29","type":"OPCUA-IIoT-Response","z":"f4b229ea.02e898","name":"","compressStructure":true,"showStatusActivities":false,"showErrors":false,"activateUnsetFilter":false,"activateFilters":false,"negateFilter":false,"filters":[],"x":530,"y":220,"wires":[["438467b3.1e5f48"]]},{"id":"9d8e679.cb3c298","type":"OPCUA-IIoT-Read","z":"f4b229ea.02e898","attributeId":"0","maxAge":1,"depth":1,"connector":"595a49ba.9ae0a8","name":"","justValue":true,"showStatusActivities":false,"showErrors":true,"parseStrings":false,"historyDays":1,"serverMaxItemsToRead":"","x":930,"y":220,"wires":[["20297ae1.a590b6"]]},{"id":"885d19ef.df46a8","type":"template","z":"f4b229ea.02e898","name":"html table","field":"payload","fieldType":"msg","format":"html","syntax":"mustache","template":"<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n\n <tr>\n <th>Name</th>\n <th>Status</th>\n <th>Date & Time</th>\n\n </tr>\n {{#payload}}\n <tr class=\"\">\n <td style=\"min-width:100px\">{{name}}</td> \n <td><font color=\"red\">{{stat}}</font></td>\n <td>{{localTime}}</td>\n </tr>\n {{/payload}}\n</table>\n","output":"str","x":1200,"y":640,"wires":[[]]},{"id":"fdd05af8.adfab8","type":"function","z":"f4b229ea.02e898","name":"topic & 10","func":"var arr = msg.payload ;\n\nvar i = 10;\nif(typeof arr === undefined) {\n return ;\n} else {\n msg.payload = arr.slice(0, 10); \n msg.topic = 'HMI recording messages :';\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":980,"y":640,"wires":[["885d19ef.df46a8"]]},{"id":"da2c3d5f.685d2","type":"change","z":"f4b229ea.02e898","name":"sort","rules":[{"t":"set","p":"payload","pt":"msg","to":"($sort(payload,function($l , $r){$l.timestamp < $r.timestamp }) )","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":640,"wires":[["fdd05af8.adfab8"]]},{"id":"b1e0c92c.8799b8","type":"function","z":"f4b229ea.02e898","name":"Create/Update msg_events","func":"var msg_obj = msg.payload ;\nvar arr_msgs = flow.get(\"msg_events\", 'memoryOnly')\nvar debug = [];\nvar arrayObj = {};\nvar obj = {};\nvar temp = {};\nvar text=\"\";\nvar foundInArray = false;\nvar index = -1;\n\nif (arr_msgs===undefined ) {\n arr_msgs = [];\n}\n\n//Start script\ntext+=\"Start - \";\nfor(i=0;i<arr_msgs.length;i++){\n arrayObj = arr_msgs[i];\n \n if(arrayObj.name == msg_obj.name){\n foundInArray = true;\n index = i;\n }\n\n}\n\nif(foundInArray){\n if(msg.payload.value){\n //remove from array\n text+=\"Splice \" + i + \" - \";\n arr_msgs.splice(index,1);\n }\n text+=\"Already present - \";\n}\nelse{\n if(!msg.payload.value){\n //add to array\n text+=\"Push \" + i + \" - \";\n arr_msgs.push(msg_obj);\n }\n text+=\"Not yet present - \";\n text+=msg.payload.value + \" - \";\n}\n\ntext+=\"Klaar\";\n\nflow.set(\"msg_events\",arr_msgs, 'memoryOnly');\n\ntemp.payload = arr_msgs;\ntemp.debug = text;\nreturn temp;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":640,"wires":[["da2c3d5f.685d2"]]},{"id":"f0cecf36.134e4","type":"function","z":"f4b229ea.02e898","name":"Add timestamp","func":"msg_obj = msg.payload;\n\nvar d = new Date();\nvar jstime = d.getTime();\nmsg_obj.utc = jstime;\n\nmsg.payload = msg_obj ;\n\nreturn msg;\n\n","outputs":1,"noerr":0,"x":820,"y":340,"wires":[["2f7220dd.889ab"]]},{"id":"2f7220dd.889ab","type":"moment","z":"f4b229ea.02e898","name":"DST","topic":"","input":"payload.utc","inputType":"msg","inTz":"Europe/Brussels","adjAmount":0,"adjType":"days","adjDir":"add","format":"DD/MM/YYYY - HH:mm:ss","locale":"","output":"payload.localTime","outputType":"msg","outTz":"Europe/Brussels","x":990,"y":340,"wires":[["5896c30e.fbef9c","ef2c71d5.8702"]]},{"id":"5896c30e.fbef9c","type":"function","z":"f4b229ea.02e898","name":"Msg logic","func":"new_msg={};\n\nnew_msg.topic=msg.payload.name;\nif(!msg.payload.value){\n new_msg.payload=msg.payload;\n}\nelse{\n new_msg.reset=true;\n}\nreturn new_msg;\n\n\n\n\n\n\n","outputs":1,"noerr":0,"x":940,"y":460,"wires":[["269fc8a3.cf8158","400d9246.d12c6c"]]},{"id":"269fc8a3.cf8158","type":"trigger","z":"f4b229ea.02e898","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":true,"overrideDelay":false,"units":"min","reset":"","bytopic":"topic","topic":"topic","outputs":1,"x":1130,"y":460,"wires":[["459af677.e1eaa8"]]},{"id":"459af677.e1eaa8","type":"trigger","z":"f4b229ea.02e898","name":"","op1":"","op2":"","op1type":"pay","op2type":"pay","duration":"-1","extend":false,"overrideDelay":false,"units":"hr","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1370,"y":460,"wires":[["52a3917a.a1b3b"]]},{"id":"400d9246.d12c6c","type":"function","z":"f4b229ea.02e898","name":"ResetResend","func":"msg.reset = true;\nreturn msg;","outputs":1,"noerr":0,"x":1140,"y":520,"wires":[["459af677.e1eaa8"]]},{"id":"ef2c71d5.8702","type":"function","z":"f4b229ea.02e898","name":"Logic","func":"var msg_obj = msg.payload ;\nvar arr_msgs = flow.get(\"msg_events\")\nvar debug = [];\nvar arrayObj = {};\nvar temp = {};\nvar foundInArray = false;\n\nif (arr_msgs===undefined ) {\n arr_msgs = [];\n}\n\n//Start script\nfor(i=0;i<arr_msgs.length;i++){\n arrayObj = arr_msgs[i];\n \n if(arrayObj.node == msg_obj.node){\n arr_msgs[i] = msg_obj;\n foundInArray = true;\n index = i;\n }\n}\n\nif(!foundInArray){\n arr_msgs.push(msg_obj);\n}\n\nflow.set(\"msg_events\",arr_msgs);\n\ntemp.payload = arr_msgs;\nreturn temp;","outputs":1,"noerr":0,"x":1150,"y":340,"wires":[["bf67fe20.cd2c3"]]},{"id":"bf67fe20.cd2c3","type":"change","z":"f4b229ea.02e898","name":"sort","rules":[{"t":"set","p":"payload","pt":"msg","to":"($sort(payload,function($l , $r){$l.stat > $r.stat }) )","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":340,"wires":[["e1eee8fd.5e5838"]]},{"id":"20297ae1.a590b6","type":"function","z":"f4b229ea.02e898","name":"New simple message","func":"var new_msg = {};\nvar new_obj = {};\nnew_obj.node = msg.payload[0].node;\nnew_obj.name = msg.payload[0].displayName.text;\nnew_obj.value = msg.payload[0].value;\nif(msg.payload[0].value){\n new_obj.stat = \"Recording\"\n new_obj.icon = \"fa-thumbs-up fa-1x\"\n new_obj.color = \"green\"\n}\nelse{\n new_obj.stat = \"Stopped\"\n new_obj.icon = \"fa-ambulance fa-1x fa-spin\"\n new_obj.color = \"red\"\n}\n\nnew_msg.payload = new_obj ;\n\nreturn new_msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":340,"wires":[["f0cecf36.134e4"]]},{"id":"e1eee8fd.5e5838","type":"template","z":"f4b229ea.02e898","name":"html table","field":"payload","fieldType":"msg","format":"html","syntax":"mustache","template":"<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n\n <tr>\n <th>Name</th>\n <th></th>\n <th>Status</th>\n <th>Date & Time</th>\n\n </tr>\n {{#payload}}\n <tr class=\"\">\n <td style=\"min-width:100px\">{{name}}</td> \n <td><i class=\"fa {{icon}}\"></i></td>\n <td>{{stat}}</td>\n <td>{{localTime}}</td>\n </tr>\n {{/payload}}\n</table>\n","output":"str","x":1440,"y":340,"wires":[["44873f7.19424c"]]},{"id":"ab5d20d5.8a47","type":"comment","z":"f4b229ea.02e898","name":"Hier server instellen","info":"","x":970,"y":180,"wires":[]},{"id":"40606e16.66a62","type":"OPCUA-IIoT-Inject","z":"f4b229ea.02e898","injectType":"listen","payloadType":"json","topic":"","repeat":"","crontab":"","once":true,"startDelay":"3","name":"Tags","payload":"{\"interval\":1000,\"queueSize\":10,\"options\":{\"requestedPublishingInterval\":500,\"requestedLifetimeCount\":2400,\"requestedMaxKeepAliveCount\":10,\"maxNotificationsPerPublish\":10,\"publishingEnabled\":true,\"priority\":2}}","addressSpaceItems":[{"name":"AC","nodeId":"ns=3;s=V:0.3.505.1.15","datatypeName":"Boolean"},{"name":"E2R2_WisselCab","nodeId":"ns=3;s=V:0.3.505.1.16","datatypeName":"Boolean"},{"name":"R2_Wisselpup_Lokaal","nodeId":"ns=3;s=V:0.3.505.1.23","datatypeName":"Boolean"},{"name":"Ontlaadcabine","nodeId":"ns=3;s=V:0.3.505.1.18","datatypeName":"Boolean"}],"x":110,"y":220,"wires":[["c16ff454.e42e38"]]},{"id":"c16ff454.e42e38","type":"OPCUA-IIoT-Listener","z":"f4b229ea.02e898","connector":"595a49ba.9ae0a8","action":"subscribe","queueSize":10,"name":"","topic":"","justValue":true,"useGroupItems":false,"showStatusActivities":true,"showErrors":true,"x":340,"y":220,"wires":[["76361182.89d29"]]},{"id":"52a3917a.a1b3b","type":"function","z":"f4b229ea.02e898","name":"Mail VW","func":"msg.to = //Redacted\nmsg.from = //Redacted\nreturn msg;","outputs":1,"noerr":2,"initialize":"","finalize":"","libs":[],"x":1560,"y":460,"wires":[[]]},{"id":"44873f7.19424c","type":"ui_template","z":"f4b229ea.02e898","group":"","name":"Webpagina VW","order":0,"width":0,"height":0,"format":"<div ng-bind-html=\"msg.payload\" height=\"500\" style=\"height: 350px;\"></div>","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"local","x":1620,"y":340,"wires":[[]]},{"id":"595a49ba.9ae0a8","type":"OPCUA-IIoT-Connector","discoveryUrl":"","endpoint":"opc.tcp://ws71633:48080/","keepSessionAlive":true,"loginEnabled":false,"securityPolicy":"None","securityMode":"NONE","name":"WSJD","showErrors":false,"individualCerts":false,"publicCertificateFile":"","privateKeyFile":"","defaultSecureTokenLifetime":"","endpointMustExist":false,"autoSelectRightEndpoint":false,"strategyMaxRetry":"","strategyInitialDelay":"","strategyMaxDelay":"","strategyRandomisationFactor":"","requestedSessionTimeout":"","connectionStartDelay":"","reconnectDelay":"","maxBadSessionRequests":"10"}]