Good day all,
First up, my Node Red Environment stats, Node Red v1.0.4, running on Windows 10, with node.js v12.16.1 and npm v6.13.4
I am at a complete lost on trying to do something simple with my first sub flow.
Here is my sub flow (which will cache data if Node Red Catches a Communication Error and resume sending out the cached data when communication is re-established)
For each Sub Flow that I use in my flow, I'd like each one of them to have its own flow.cached_data_temp_repository. This is to avoid writing the wrong cached data into the wrong database table if I only had one common flow.cached_data_temp_repository for all of my 10 separate database tables.
I came across this settings in the sub flow "edit properties" tab
How can I make use of this feature, so that all 10 of my sub-flows will have its own individual flow.cached_data_temp_repository respectively... like this
sub-flow no.1 will write to flow.cached_data_temp_repository_no1
sub flow no.2 will write to flow.cached_data_temp_repository_no2
sub flow no.3 will write to flow.cached_data_temp_repository_no3
... etc
Could I use the Environment Variables feature to assign different flow.cached_data_temp_repository_noX for each of my sub-flows to achieve this?
IF YES, how do I setup my function node and my change node to make use of this input that I have defined in my Environment Variables?
Here is my function node...
Here is one of my change node
Here is the other change Node
Below is my sub flow as you see in the screenshots above
[{"id":"1799862e.08b0aa","type":"switch","z":"926f6f3.0148b9","name":"","property":"network_link","propertyType":"flow","rules":[{"t":"eq","v":"Network OK","vt":"str"},{"t":"neq","v":"Network OK","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":130,"y":220,"wires":[["720d7cd9.f1f934"],["46285185.bb43e"]]},{"id":"720d7cd9.f1f934","type":"switch","z":"926f6f3.0148b9","name":"","property":"payload","propertyType":"msg","rules":[{"t":"hask","v":"Timestamp","vt":"str"}],"checkall":"false","repair":false,"outputs":1,"x":270,"y":200,"wires":[["cd164951.37ec98"]]},{"id":"cd164951.37ec98","type":"trigger","z":"926f6f3.0148b9","op1":"true","op2":"false","op1type":"bool","op2type":"bool","duration":"1","extend":true,"units":"s","reset":"","bytopic":"all","name":"","x":400,"y":200,"wires":[["f4aaac97.6ee29"]]},{"id":"f4aaac97.6ee29","type":"rbe","z":"926f6f3.0148b9","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":410,"y":160,"wires":[["2d6e622a.77c7ae"]]},{"id":"2d6e622a.77c7ae","type":"switch","z":"926f6f3.0148b9","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"}],"checkall":"false","repair":false,"outputs":1,"x":410,"y":120,"wires":[["ff8a264c.9d7e08"]]},{"id":"ff8a264c.9d7e08","type":"change","z":"926f6f3.0148b9","name":"feed latest cache","rules":[{"t":"set","p":"payload","pt":"msg","to":"what_Var_do_I_put_IN_HERE?","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":120,"wires":[["b02dfcc5.e375d"]]},{"id":"b02dfcc5.e375d","type":"function","z":"926f6f3.0148b9","name":"send one object out at a time from array","func":"var cached_data_array = msg.payload;\nvar msg1 = {};\n\nfor(var i=0; i < cached_data_array.length ;i++)\n{\nmsg.payload = cached_data_array[i];\nmsg1.payload = ((i+1) === cached_data_array.length)? \"cache_data_sent\" : null;\n\nnode.send([msg, msg1]);\n}\n\n\n\n\n","outputs":2,"noerr":0,"x":720,"y":160,"wires":[["1ce9caa7.7f85d5"],["db84beee.a6391"]]},{"id":"1ce9caa7.7f85d5","type":"delay","z":"926f6f3.0148b9","name":"","pauseType":"rate","timeout":"1","timeoutUnits":"seconds","rate":"3","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":850,"y":100,"wires":[[]]},{"id":"db84beee.a6391","type":"switch","z":"926f6f3.0148b9","name":"Check cache sent completed","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"cache_data_sent","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":680,"y":220,"wires":[["5f2c1b31.22edd4"]]},{"id":"5f2c1b31.22edd4","type":"change","z":"926f6f3.0148b9","name":"reset flow.latest_cache to \"empty\"","rules":[{"t":"set","p":"what_Var_do_I_put_IN_HERE?","pt":"flow","to":"[]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":260,"wires":[[]]},{"id":"46285185.bb43e","type":"function","z":"926f6f3.0148b9","name":"Write data to flow.latest_cache","func":"var feed = msg.payload;\nvar cn = env.get(\"what_Var_do_I_put_IN_HERE?\");\n\nvar data_cache = flow.get(cn);\n\ndata_cache.push(feed);\n\nmsg.payload = data_cache;\n\nflow.set(cn,data_cache);\n\nreturn msg;\n\n/*\nif (Array.isArray(array) && array.length) {\n // code\n}\n*/","outputs":1,"noerr":0,"x":350,"y":240,"wires":[[]]}]
I am really looking forward to get any feedback from the Node Red experts here on resolving this simple problem of mine.