[
{
"id": "2c2aeb8b4fec5a87",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "315086cb1d9bff21",
"type": "function",
"z": "2c2aeb8b4fec5a87",
"name": "",
"func": "let msgCount = context.get(\"msgCount\") || 0;//get remembered count\nlet sendMessage = false;\n\nif (msg.payload === 1) {\n msgCount++; //increment count\n node.status(\"Count of payload 1: \" + msgCount);\n if (msgCount >= 500) {\n msgCount = 0;//reset counter\n sendMessage = true;//instruct code to send the msg\n msg.payload = \"0\"; //set payload to a string of 1 as you requested\n }\n}\n\ncontext.set(\"msgCount\", msgCount); //remember count\n\nif(sendMessage) {\n return msg;//send msg to next node\n}\n\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 680,
"y": 160,
"wires": [
[
"9bd4724dbaf29a4e",
"66a2372338a5df4e"
]
]
},
{
"id": "9bd4724dbaf29a4e",
"type": "debug",
"z": "2c2aeb8b4fec5a87",
"name": "",
"active": true,
"tosidebar": true,
"console": true,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload",
"statusType": "auto",
"x": 1100,
"y": 120,
"wires": []
},
{
"id": "7c06fe830b7a1ebf",
"type": "inject",
"z": "2c2aeb8b4fec5a87",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "0",
"payloadType": "num",
"x": 390,
"y": 260,
"wires": [
[
"315086cb1d9bff21"
]
]
},
{
"id": "efaf1d014a100842",
"type": "rpi-gpio in",
"z": "2c2aeb8b4fec5a87",
"name": "",
"pin": "10",
"intype": "tri",
"debounce": "25",
"read": false,
"bcm": true,
"x": 170,
"y": 200,
"wires": [
[
"315086cb1d9bff21"
]
]
},
{
"id": "57670cb0da43a95c",
"type": "inject",
"z": "2c2aeb8b4fec5a87",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "0.1",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "1",
"payloadType": "num",
"x": 290,
"y": 80,
"wires": [
[
"315086cb1d9bff21"
]
]
},
{
"id": "53cfe7c73f8b7a32",
"type": "ui_button",
"z": "2c2aeb8b4fec5a87",
"name": "",
"group": "85f720af4449497c",
"order": 4,
"width": 0,
"height": 0,
"passthru": false,
"label": "button",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "1",
"payloadType": "num",
"topic": "topic",
"topicType": "msg",
"x": 510,
"y": 60,
"wires": [
[
"9bd4724dbaf29a4e",
"66a2372338a5df4e"
]
]
},
{
"id": "66a2372338a5df4e",
"type": "rpi-gpio out",
"z": "2c2aeb8b4fec5a87",
"name": "",
"pin": "5",
"set": true,
"level": "0",
"freq": "",
"out": "out",
"bcm": true,
"x": 1080,
"y": 260,
"wires": []
},
{
"id": "85f720af4449497c",
"type": "ui_group",
"name": "Refill",
"tab": "643eb5c118adb915",
"order": 2,
"disp": true,
"width": "6",
"collapse": false,
"className": ""
},
{
"id": "643eb5c118adb915",
"type": "ui_tab",
"name": "Watering",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]
Background: Water flow sensor that pulls the pin high in pulses.
Counts the pulses untill it reaches a set limit then send 0 to a pin
The inject node is just simulating a pulse
I have the raspberry pi nodes installed
I have this working code but the only way i can edit the if (msgCount = 500) is by editing the function. I would like the number (500) to be editable by a slider on the UI
I am sorry if this is formatted wrong. This is my first post