【发布时间】:2018-01-23 15:51:58
【问题描述】:
我已经编写了代码来更新 node-red 中的文件,该文件可以按我的意愿工作。我不太确定它是否可行。当按下注入按钮时,当前值通过上下文存储,读取文件并将存储的数据添加到其中。 (a-)同步性怎么样?如果存储的数据变大了怎么办?也许数据还没有被存储,但旧数据被写入文件?这是可能的吗?我可以通过某种方式使用某种回调函数来解决这个问题吗?
这是节点红色代码:
[{"id":"ff428878.2bf0d8","type":"inject","z":"33a0c3f0.5ad66c","name":"","topic":"","payload" :"","payloadType":"date","repeat":"","crontab":"","once":false,"x":140,"y":80,"wires":[[ "d97f4731.48f508"]]},{"id":"aff66bbc.653048","type":"file in","z":"33a0c3f0.5ad66c","name":"","filename": "examplefile.txt","format":"utf8","chunk":false,"sendError":false,"x":380,"y":240,"wires":[["82b889ff.4e5f18"] ]},{"id":"216dc166.5c79be","type":"file","z":"33a0c3f0.5ad66c","name":"","filename":"examplefile.txt"," appendNewline":true,"createDir":false,"overwriteFile":"true","x":900,"y":80,"wires":[]},{"id":"9238c649.dac2e8", "type":"function","z":"33a0c3f0.5ad66c","name":"merge","func":"if(msg.topic == \"new\"){\n context.set ('shortterm', msg.payload);\n return [null,msg];\n}\n\nif(msg.topic == \"old\"){\n msg.payload.push(context.get ('shortterm'));\n return [msg,null];\n}\n\n","outputs":"2","noerr":0,"x":611,"y":80 ,"电线":[["216dc166.5c79be"],["aff66bbc.653048"]]},{"id":"d97f4731.48f508","t ype":"function","z":"33a0c3f0.5ad66c","name":"mark as new","func":"msg.topic = \"new\";\nreturn msg;","outputs ":1,"noerr":0,"x":400,"y":80,"wires":[["9238c649.dac2e8"]]},{"id":"10b8938f.1cddfc","type ":"function","z":"33a0c3f0.5ad66c","name":"标记为旧","func":"msg.topic = \"old\";\nreturn msg;","outputs" :1,"noerr":0,"x":810,"y":240,"wires":[["9238c649.dac2e8"]]},{"id":"82b889ff.4e5f18","type" :"function","z":"33a0c3f0.5ad66c","name":"JSON 解析","func":"if(msg.payload){\n msg.payload = JSON.parse(msg.payload) ;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":610,"y":240,"wires":[["10b8938f.1cddfc"]]} ,{"id":"7572637c.0a25ac","type":"file","z":"33a0c3f0.5ad66c","name":"","filename":"examplefile.txt","appendNewline" :true,"createDir":false,"overwriteFile":"true","x":510,"y":480,"wires":[]},{"id":"1f6b9043.ff153","type ":"inject","z":"33a0c3f0.5ad66c","name":"","topic":"","payload":"[]","payloadType":"json","repeat" :"","crontab":"25 22 * * *","once":false,"x":210,"y":460,"wires":[["7572637c .0a25ac"]]}]
【问题讨论】:
标签: node-red