NodeRed
nodered flow내 변수 flowContext 사용법 count 예문
아이티제어1998
2022. 5. 6. 21:15
j: $flowContext("count")+1
function 노드내에서 context.get(), .set() 을 이용시 참고
if (context.get("counter") === undefined) {
context.set("counter", 0)
}
압축형식 전체소스
[{"id":"6ecac54d.c43ffc","type":"comment","z":"048afcf96de5b555","name":"Set flow context","info":"Change node can set flow context.","x":240,"y":1940,"wires":[]},{"id":"80e966d3.9d7a78","type":"inject","z":"048afcf96de5b555","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":420,"y":2020,"wires":[["abaee298.2d77e"]]},{"id":"abaee298.2d77e","type":"change","z":"048afcf96de5b555","name":"j: $flowContext(\"count\")+1","rules":[{"t":"set","p":"count","pt":"flow","to":"$flowContext(\"count\")+1\t","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"count","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":2000,"wires":[["597b63cd.b3218c"]]},{"id":"2de2bb38.f20ff4","type":"inject","z":"048afcf96de5b555","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":420,"y":1940,"wires":[["7b96521e.a3cb0c"]]},{"id":"597b63cd.b3218c","type":"debug","z":"048afcf96de5b555","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":850,"y":1960,"wires":[]},{"id":"7b96521e.a3cb0c","type":"change","z":"048afcf96de5b555","name":"set count to 0","rules":[{"t":"set","p":"count","pt":"flow","to":"0","tot":"num"},{"t":"set","p":"payload","pt":"msg","to":"count","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":1940,"wires":[["597b63cd.b3218c"]]},{"id":"d8069121.80de7","type":"comment","z":"048afcf96de5b555","name":"↓ Count up","info":"","x":420,"y":1980,"wires":[]}]
전체소스
[
{
"id": "6ecac54d.c43ffc",
"type": "comment",
"z": "048afcf96de5b555",
"name": "Set flow context",
"info": "Change node can set flow context.",
"x": 240,
"y": 1940,
"wires": []
},
{
"id": "80e966d3.9d7a78",
"type": "inject",
"z": "048afcf96de5b555",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 420,
"y": 2020,
"wires": [
[
"abaee298.2d77e"
]
]
},
{
"id": "abaee298.2d77e",
"type": "change",
"z": "048afcf96de5b555",
"name": "j: $flowContext(\"count\")+1",
"rules": [
{
"t": "set",
"p": "count",
"pt": "flow",
"to": "$flowContext(\"count\")+1\t",
"tot": "jsonata"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "count",
"tot": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 630,
"y": 2000,
"wires": [
[
"597b63cd.b3218c"
]
]
},
{
"id": "2de2bb38.f20ff4",
"type": "inject",
"z": "048afcf96de5b555",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 420,
"y": 1940,
"wires": [
[
"7b96521e.a3cb0c"
]
]
},
{
"id": "597b63cd.b3218c",
"type": "debug",
"z": "048afcf96de5b555",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload",
"statusType": "auto",
"x": 850,
"y": 1960,
"wires": []
},
{
"id": "7b96521e.a3cb0c",
"type": "change",
"z": "048afcf96de5b555",
"name": "set count to 0",
"rules": [
{
"t": "set",
"p": "count",
"pt": "flow",
"to": "0",
"tot": "num"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "count",
"tot": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 600,
"y": 1940,
"wires": [
[
"597b63cd.b3218c"
]
]
},
{
"id": "d8069121.80de7",
"type": "comment",
"z": "048afcf96de5b555",
"name": "↓ Count up",
"info": "",
"x": 420,
"y": 1980,
"wires": []
}
]