Hi,
I try to save more or one variable in the nodered file system with the same function node.
I have two different MQTT sources, one is a zyklic response with all variables at once and the other source only sends one variable onchange.
The Problem is, that only the first argument is working. I tried if, else if and else, but don´t get it, obviously.
Here is the example code, It would be great, if someone could have a look:
[
{
"id": "18c63b397ab83688",
"type": "function",
"z": "b778fbe9f2d14352",
"name": "",
"func": "if (msg.payload.hasOwnProperty(\"var01\")) {\n context.set('var01', msg.payload.var01, 'file');\n}\nelse if (msg.payload.hasOwnProperty(\"var02\")) {\n context.set('var02', msg.payload.var02, 'file');\n}\nelse if (msg.payload.hasOwnProperty(\"var03\")) {\n context.set('var03', msg.payload.var03, 'file');\n}\nelse if (msg.payload.hasOwnProperty(\"var04\")) {\n context.set('var04', msg.payload.var04, 'file');\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1840,
"y": 1560,
"wires": [
[
"aa9f002d8ad708ed"
]
]
},
{
"id": "aa9f002d8ad708ed",
"type": "debug",
"z": "b778fbe9f2d14352",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 2010,
"y": 1560,
"wires": []
},
{
"id": "af034db73782efa0",
"type": "inject",
"z": "b778fbe9f2d14352",
"name": "var01 - var04",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"var01\":\"1\",\"var02\":\"2\",\"var03\":\"3\",\"var04\":\"4\"}",
"payloadType": "json",
"x": 1650,
"y": 1560,
"wires": [
[
"18c63b397ab83688"
]
]
},
{
"id": "ad388d7199e6e134",
"type": "inject",
"z": "b778fbe9f2d14352",
"name": "{\"var01\":\"10\"}",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"var01\":\"10\"}",
"payloadType": "json",
"x": 1650,
"y": 1620,
"wires": [
[
"18c63b397ab83688"
]
]
},
{
"id": "4985b6a75870bc1a",
"type": "inject",
"z": "b778fbe9f2d14352",
"name": "{\"var02\":\"20\"}",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"var02\":\"20\"}",
"payloadType": "json",
"x": 1650,
"y": 1660,
"wires": [
[
"18c63b397ab83688"
]
]
},
{
"id": "caccf9ef63152951",
"type": "inject",
"z": "b778fbe9f2d14352",
"name": "{\"var03\":\"30\"}",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"var03\":\"30\"}",
"payloadType": "json",
"x": 1650,
"y": 1700,
"wires": [
[
"18c63b397ab83688"
]
]
},
{
"id": "37738e780b95fa2f",
"type": "inject",
"z": "b778fbe9f2d14352",
"name": "{\"var04\":\"40\"}",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"var04\":\"40\"}",
"payloadType": "json",
"x": 1650,
"y": 1740,
"wires": [
[
"18c63b397ab83688"
]
]
}
]