설치할패키지 GPIO 설치
npm install node-red-node-pi-gpio
https://flows.nodered.org/node/node-red-node-pi-gpio
node-red-node-pi-gpio
The basic Node-RED node for Pi GPIO
flows.nodered.org
[
{
"id": "3084325c196ecd52",
"type": "tab",
"label": "Rpi-SwiFlow 6",
"disabled": false,
"info": "",
"env": []
},
{
"id": "60fd36521b1d5833",
"type": "rpi-gpio out",
"z": "3084325c196ecd52",
"name": "",
"pin": "4",
"set": true,
"level": "0",
"freq": "",
"out": "out",
"bcm": true,
"x": 956,
"y": 449,
"wires": []
},
{
"id": "81c2bc87c1e50621",
"type": "comment",
"z": "3084325c196ecd52",
"name": "Room Lights",
"info": "",
"x": 218,
"y": 307,
"wires": []
},
{
"id": "37f094f072954e2e",
"type": "change",
"z": "3084325c196ecd52",
"name": "set timings",
"rules": [
{
"t": "set",
"p": "lighton",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "lightoff",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "numberofblinks",
"pt": "msg",
"to": "1",
"tot": "num"
},
{
"t": "set",
"p": "delaystart",
"pt": "msg",
"to": "0",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 918,
"y": 207,
"wires": [
[
"c581c0b1523b8de0",
"2da1c674c496ed30"
]
]
},
{
"id": "c581c0b1523b8de0",
"type": "function",
"z": "3084325c196ecd52",
"name": "The Light Show",
"func": "//get the values of msg.* to var's\nvar numberofblinks = msg.numberofblinks;\nvar light_on_for_ms = msg.lighton;\nvar light_off_for_ms = msg.lightoff;\n\n//how long to wait before starting the light show\nvar time_in_ms_to_wait_before_first_execution = msg.delaystart || 0;\n\n//total run time of light on and light off\nvar time_in_ms_to_wait_between_recursive_setTimeout = (light_on_for_ms + light_off_for_ms);\n\n//set the count to 1\nvar count = 1;\n\nvar tostopit;\n\n//function to count the number of blinks and stop timmer\nfunction blinks() {\n if (numberofblinks <= count) {\n //stop the recursive setTimeout\n clearTimeout(tostopit);\n } else {\n count++;\n }\n}\n\n//function to set payload to true\nfunction payload_true() {\n //set payload to true\n msg.payload = true;\n node.send(msg);\n\n //display green dot when light is on\n node.status({fill: 'green', shape: 'dot', text: ' '});\n}\n\n//function to set payload to false\nfunction payload_false() {\n //set payload to false\n msg.payload = false;\n node.send(msg);\n\n //clear status when payload false\n node.status({});\n}\n\n//run the light show!!!!\nsetTimeout(function run() {\n //turn the light on by setting msg.payload to true\n payload_true();\n\n //turn the light off by waiting to set the payload to false by the ammount of time light is on\n setTimeout(payload_false, light_on_for_ms);\n\n //total ammount of time light can be on or off before it runs again\n tostopit = setTimeout(run, time_in_ms_to_wait_between_recursive_setTimeout);\n\n blinks();\n\n}, time_in_ms_to_wait_before_first_execution);\n\nreturn null;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 928,
"y": 267,
"wires": [
[
"60fd36521b1d5833",
"ef65fc8fa1c7704f"
]
]
},
{
"id": "2da1c674c496ed30",
"type": "debug",
"z": "3084325c196ecd52",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "lighton",
"x": 1104,
"y": 182,
"wires": []
},
{
"id": "140103baba809851",
"type": "change",
"z": "3084325c196ecd52",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "(payload*60)*1000",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 728,
"y": 227,
"wires": [
[
"37f094f072954e2e"
]
]
},
{
"id": "b31d0f602ab49404",
"type": "ui_slider",
"z": "3084325c196ecd52",
"name": "",
"label": "slider",
"tooltip": "",
"group": "2f45f695.6435ba",
"order": 0,
"width": 0,
"height": 0,
"passthru": true,
"outs": "all",
"topic": "",
"topicType": "str",
"min": "1",
"max": "20",
"step": 1,
"className": "",
"x": 197,
"y": 121,
"wires": [
[
"dc3c5df8a57176c2",
"7a9adc2dea560539"
]
]
},
{
"id": "dc3c5df8a57176c2",
"type": "change",
"z": "3084325c196ecd52",
"name": "",
"rules": [
{
"t": "set",
"p": "slider",
"pt": "flow",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 389,
"y": 102,
"wires": [
[
"14afcef11ef43861",
"f7b20565fb96f3d9"
]
]
},
{
"id": "06f89716299d976a",
"type": "ui_switch",
"z": "3084325c196ecd52",
"name": "",
"label": "switch",
"tooltip": "",
"group": "2f45f695.6435ba",
"order": 0,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "",
"topicType": "str",
"style": "",
"onvalue": "true",
"onvalueType": "bool",
"onicon": "",
"oncolor": "",
"offvalue": "false",
"offvalueType": "bool",
"officon": "",
"offcolor": "",
"animate": true,
"className": "",
"x": 438,
"y": 187,
"wires": [
[
"f1c8429db529deb2"
]
]
},
{
"id": "f1c8429db529deb2",
"type": "switch",
"z": "3084325c196ecd52",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "true"
},
{
"t": "false"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 498,
"y": 247,
"wires": [
[
"a4d800391e8373b7"
],
[
"60fd36521b1d5833",
"d773270450f3343c"
]
]
},
{
"id": "a4d800391e8373b7",
"type": "change",
"z": "3084325c196ecd52",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "slider",
"tot": "flow"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 628,
"y": 167,
"wires": [
[
"195e68991048bae2",
"140103baba809851",
"bb518e01475f753e"
]
]
},
{
"id": "195e68991048bae2",
"type": "debug",
"z": "3084325c196ecd52",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 919,
"y": 138,
"wires": []
},
{
"id": "14afcef11ef43861",
"type": "ui_text",
"z": "3084325c196ecd52",
"group": "2f45f695.6435ba",
"order": 0,
"width": 0,
"height": 0,
"name": "",
"label": "slider",
"format": "{{msg.payload}}",
"layout": "row-left",
"className": "",
"x": 583,
"y": 71,
"wires": []
},
{
"id": "7a9adc2dea560539",
"type": "change",
"z": "3084325c196ecd52",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "false",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 268,
"y": 187,
"wires": [
[
"06f89716299d976a"
]
]
},
{
"id": "d773270450f3343c",
"type": "function",
"z": "3084325c196ecd52",
"name": "msg",
"func": "node.status({text: JSON.stringify(msg)})\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 426,
"y": 502,
"wires": [
[]
]
},
{
"id": "ef65fc8fa1c7704f",
"type": "function",
"z": "3084325c196ecd52",
"name": "msg",
"func": "node.status({text: JSON.stringify(msg)})\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 916,
"y": 319,
"wires": [
[]
]
},
{
"id": "bb518e01475f753e",
"type": "function",
"z": "3084325c196ecd52",
"name": "msg",
"func": "node.status({text: JSON.stringify(msg)})\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 761,
"y": 80,
"wires": [
[]
]
},
{
"id": "f7b20565fb96f3d9",
"type": "function",
"z": "3084325c196ecd52",
"name": "msg",
"func": "node.status({text: JSON.stringify(msg)})\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 512,
"y": 20,
"wires": [
[]
]
},
{
"id": "2f45f695.6435ba",
"type": "ui_group",
"name": "row 1",
"tab": "568a2c54.1e76f4",
"order": 2,
"disp": false,
"width": "15",
"collapse": false
},
{
"id": "568a2c54.1e76f4",
"type": "ui_tab",
"name": "Deathstar",
"icon": "dashboard",
"order": 1
}
]
'NodeRed' 카테고리의 다른 글
nodered템플릿 예제 (0) | 2022.05.04 |
---|---|
nodered injec에서 YMD hhmmss구하기 $now() $moment().tz().format() (0) | 2022.05.03 |
npm 설치 사용자 설치한 패키지 리스트 검색 하는 법 (0) | 2022.02.25 |
node-red의 Flow안에서 node간에 함수를 공유 하여 사용법 (0) | 2022.02.23 |
node-red화면크게 layout (0) | 2022.02.22 |