Hi [at]all,
so far I what have read about persistent context, I tried to solve this myself with doing the following:
though for me its not a decisive target to have my global context stored practically "realtime". and probably for many others it isnt AW.
since function nodes provide the possibility to set up a start-up and last-will routine, I did the following:
[{"id":"5d2e2929.cfe1c8","type":"function","z":"207dcb76.6bf074","name":"","func":"keys = global.keys();\nfilename = \"/config/node-red/JsonDB/globalContext.json\";\nnewobj = {};\n\nfor(var key of keys){\n newobj[String(key)] = global.get(String(key));\n}\n\nreturn {payload:newobj,filename:filename};","outputs":1,"noerr":0,"initialize":"","finalize":"// Code added here will be run when the\n// node is being stopped or re-deployed.\n\nkeys = global.keys();\nfilename = \"/config/node-red/JsonDB/globalContext.json\";\nnewobj = {};\n\nfor(var key of keys){\n newobj[String(key)] = global.get(String(key));\n}\n\nreturn {payload:newobj,filename:filename};","x":360,"y":80,"wires":[["fb1b31b3.1242c","4dc0b987.dd7a98"]]},{"id":"6dd27c6f.a97144","type":"inject","z":"207dcb76.6bf074","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":80,"wires":[["5d2e2929.cfe1c8"]]},{"id":"fb1b31b3.1242c","type":"file","z":"207dcb76.6bf074","name":"Write globalContext File","filename":"","appendNewline":false,"createDir":true,"overwriteFile":"true","encoding":"none","x":630,"y":80,"wires":[[]]},{"id":"4dc0b987.dd7a98","type":"debug","z":"207dcb76.6bf074","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":180,"wires":[]},{"id":"f6de00e2.4ad2e","type":"function","z":"207dcb76.6bf074","name":"","func":"contextFromFile = msg.payload;\n\nfor(var key in contextFromFile){\n global.set(String(key),contextFromFile[key]);\n}\n\nnode.warn(\"Reloaded GlobalContext Successfully!\")\nreturn;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":820,"y":320,"wires":[[]]},{"id":"918f5183.f6a17","type":"file in","z":"207dcb76.6bf074","name":"Read Global context File","filename":"/config/node-red/JsonDB/globalContext.json","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":370,"y":320,"wires":[["db667674.2721e8"]]},{"id":"d98139ae.7b3418","type":"inject","z":"207dcb76.6bf074","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"2","topic":"","payload":"","payloadType":"date","x":170,"y":320,"wires":[["918f5183.f6a17"]]},{"id":"db667674.2721e8","type":"json","z":"207dcb76.6bf074","name":"","property":"payload","action":"obj","pretty":false,"x":550,"y":320,"wires":[["f6de00e2.4ad2e","8118fc66.1343b"]]},{"id":"8118fc66.1343b","type":"debug","z":"207dcb76.6bf074","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":380,"wires":[]}]
which at a deploy or restart saves the context.
so far that works with everything i wanted to do so far and i have my sd card written only at restarts and global redeploys.
and reloads them at startup
Question pointing to the admins, is there any restriction in behalf of e.g. globally stored functions (which are injected) or anything? is there something I get completely wrong regarding the benefits of setting this up in settings.js by default?