Hello,
I am creating a graph and want to store value for long period of time and for that I want to store the value in a database- doesn't want to loose it even if the PC got turned off which will most likely happen.
Since its only one number, I would like to store it in text formal using write node.
Everything goes well_ it stores a number and reads the same number from file until node -red is restarted. When it restarted it initializes with one.
Any suggestion how to overcome this??
[
{
"id": "d3e1163e876f1c6f",
"type": "inject",
"z": "146ab432f501375f",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payload": "true",
"payloadType": "bool",
"x": 90,
"y": 620,
"wires": [
[
"efcea3e48f367448"
]
]
},
{
"id": "efcea3e48f367448",
"type": "function",
"z": "146ab432f501375f",
"name": "",
"func": "\n\nif(msg.payload== true)\n{\n var count=global.get('assembly')||0;\n count = count+1;\n msg.payload= count;\n \nreturn msg;\n}\nelse\n{\n return null;\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 300,
"y": 620,
"wires": [
[
"161417918f469518"
]
]
},
{
"id": "161417918f469518",
"type": "file",
"z": "146ab432f501375f",
"name": "",
"filename": "D:\\Node_red_write\\hello.txt",
"appendNewline": true,
"createDir": false,
"overwriteFile": "true",
"encoding": "none",
"x": 520,
"y": 620,
"wires": [
[
"166fefa7d7af0e67"
]
]
},
{
"id": "166fefa7d7af0e67",
"type": "debug",
"z": "146ab432f501375f",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 850,
"y": 620,
"wires": []
},
{
"id": "db04ca1b12942cb4",
"type": "file in",
"z": "146ab432f501375f",
"name": "",
"filename": "D:\\Node_red_write\\hello.txt",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "none",
"allProps": false,
"x": 320,
"y": 760,
"wires": [
[
"853ca13cc3889c1f"
]
]
},
{
"id": "0673468542d63908",
"type": "inject",
"z": "146ab432f501375f",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "1",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 110,
"y": 760,
"wires": [
[
"db04ca1b12942cb4"
]
]
},
{
"id": "853ca13cc3889c1f",
"type": "json",
"z": "146ab432f501375f",
"name": "",
"property": "payload",
"action": "",
"pretty": false,
"x": 510,
"y": 760,
"wires": [
[
"12d82746689c6c5c"
]
]
},
{
"id": "12d82746689c6c5c",
"type": "rbe",
"z": "146ab432f501375f",
"name": "",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"septopics": true,
"property": "payload",
"topi": "topic",
"x": 650,
"y": 760,
"wires": [
[
"83e5d9a9e3807bbe"
]
]
},
{
"id": "83e5d9a9e3807bbe",
"type": "function",
"z": "146ab432f501375f",
"name": "",
"func": "\nglobal.set('assembly',msg.payload);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 800,
"y": 760,
"wires": [
[
"09269eb007ac8fa1"
]
]
},
{
"id": "09269eb007ac8fa1",
"type": "debug",
"z": "146ab432f501375f",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 970,
"y": 760,
"wires": []
},
{
"id": "8657f45eee6aad19",
"type": "comment",
"z": "146ab432f501375f",
"name": "Simulating with boolean- true",
"info": "",
"x": 140,
"y": 580,
"wires": []
},
{
"id": "8761750981b161ed",
"type": "comment",
"z": "146ab432f501375f",
"name": "Extracting value from a pc and setting into global variable",
"info": "",
"x": 230,
"y": 720,
"wires": []
}
]