# Ask for help with debug in node red

**URL:** <https://discourse.nodered.org/t/ask-for-help-with-debug-in-node-red/73324>\
**Category:** General\
**Tags:** function-node\
**Created:** [7 January 2023 11:27 UTC](https://discourse.nodered.org/t/ask-for-help-with-debug-in-node-red/73324 "2023-01-07T11:27:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![issambfs1](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@issambfs1](https://discourse.nodered.org/u/issambfs1)\
**Post date:** [7 January 2023 11:27 UTC](https://discourse.nodered.org/t/ask-for-help-with-debug-in-node-red/73324/1 "2023-01-07T11:27:29Z")

</div>

hi evryone can anyone help me with this :  
i wana simulate code can control a system {pump-low start and stop by switch after pump-low start the pump-décolorant and pump-scalaut starting after 2 sec also pump-high start after 6 sec when switch is false all pump stoped}

but i get northing in debug any advise  
here is the code :  
\<  
// Declare variables for the pumps  
let pumpLow;  
let pumpDecolorant;  
let pumpScalaut;  
let pumpHigh;

// Declare a variable to track the status of the pumps  
let pumpStatus = "off";

// This function is called when the switch is flipped  
function startPumps(msg) {  
// Check the value of the switch  
if (msg.payload === true) {  
// If the switch is turned on, start the pump-low  
pumpLow = setInterval(function () {  
console.log("pump-low started");  
}, 1000); // Run the function every second

```
    // Set a timeout to start the pump-decolorant and pump-scalaut after 2 seconds
    setTimeout(function () {
        pumpDecolorant = setInterval(function () {
            console.log("pump-decolorant started");
        }, 1000); // Run the function every second

        pumpScalaut = setInterval(function () {
            console.log("pump-scalaut started");
        }, 1000); // Run the function every second
    }, 2000);

    // Set a timeout to start the pump-high after 6 seconds
    setTimeout(function () {
        pumpHigh = setInterval(function () {
            console.log("pump-high started");
        }, 1000); // Run the function every second
    }, 6000);

    // Update the pump status
    pumpStatus = "on";
} else {
    // If the switch is turned off, stop all pumps
    stopPumps();
}

```

}

// This function stops all pumps  
function stopPumps() {  
clearInterval(pumpLow);  
clearInterval(pumpDecolorant);  
clearInterval(pumpScalaut);  
clearInterval(pumpHigh);  
console.log("all pumps stopped");  
pumpStatus = "off";  
}

// Send the pump status to the output  
return {  
payload: pumpStatus  
};

> 

//

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/5/e56baed73c4cca413f3aff9fa772ebe635111b40.png)  
 ![inject](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/6/86cf338114af85e0fe88742ab3f1723d47bd6516.png)

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [7 January 2023 14:25 UTC](https://discourse.nodered.org/t/ask-for-help-with-debug-in-node-red/73324/2 "2023-01-07T14:25:51Z")

</div>

setTimeout functions may eventually create all kinds of problems, can I suggest a more node-red "way" of implementing this ?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/753dd949591811da6197816e409e2d92aa4caf45.png)

Try this flow:

```auto
[{"id":"1622bb3abca3940f","type":"inject","z":"31c1e2adb95d7cd8","name":"pump start","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":160,"y":60,"wires":[["b779a5bda71c5c6b"]]},{"id":"b779a5bda71c5c6b","type":"function","z":"31c1e2adb95d7cd8","name":"function 1","func":"\nif(msg.payload){\n node.status({ fill: \"green\", shape: \"dot\", text: \"Pumps started\" });\n}\nelse{\n node.status({ fill: \"red\", shape: \"dot\", text: \"Pumps stopped\" });\n}\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":275,"y":80,"wires":[["eb6dfcad89e271f5"]],"l":false},{"id":"ab2f978a43b0451d","type":"inject","z":"31c1e2adb95d7cd8","name":"pumps stop","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":150,"y":100,"wires":[["b779a5bda71c5c6b"]]},{"id":"9be737534ef39b61","type":"function","z":"31c1e2adb95d7cd8","name":"function 2","func":"if (msg.payload) {\n node.status({ fill: \"green\", shape: \"dot\", text: \"pump-decolorant started\" });\n return msg;\n}\nelse {\n node.status({ fill: \"red\", shape: \"dot\", text: \"pump-decolorant stopped\" });\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":555,"y":160,"wires":[[]],"l":false},{"id":"558eb0a27b419ae5","type":"delay","z":"31c1e2adb95d7cd8","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":420,"y":160,"wires":[["979a5e0e162278dc","9be737534ef39b61"]]},{"id":"eb6dfcad89e271f5","type":"switch","z":"31c1e2adb95d7cd8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":345,"y":80,"wires":[["979a5e0e162278dc","9be737534ef39b61","eeb91795a917d96a"],["558eb0a27b419ae5"]],"l":false},{"id":"1c4161b1161d26e6","type":"delay","z":"31c1e2adb95d7cd8","name":"","pauseType":"delay","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":680,"y":80,"wires":[["eeb91795a917d96a"]]},{"id":"eeb91795a917d96a","type":"function","z":"31c1e2adb95d7cd8","name":"function 3","func":"if (msg.payload) {\n node.status({ fill: \"green\", shape: \"dot\", text: \"pump-high started\" });\n msg.payload = {pumpstatus:\"On\"}\n return msg;\n}\nelse {\n msg.payload = { pumpstatus: \"Off\" }\n node.status({ fill: \"red\", shape: \"dot\", text: \"pump-high stopped\" });\n return msg;\n\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":785,"y":40,"wires":[["76261901fede0e36"]],"l":false},{"id":"979a5e0e162278dc","type":"function","z":"31c1e2adb95d7cd8","name":"function 4","func":"if (msg.payload) {\n node.status({ fill: \"green\", shape: \"dot\", text: \"pump-scalaut started\" });\n return msg;\n}\nelse {\n node.status({ fill: \"red\", shape: \"dot\", text: \"pump-scalaut stopped\" });\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":555,"y":100,"wires":[["1c4161b1161d26e6"]],"l":false},{"id":"76261901fede0e36","type":"debug","z":"31c1e2adb95d7cd8","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":845,"y":40,"wires":[],"l":false}]

```

---

<div class="post-metadata">

**Author:** ![issambfs1](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@issambfs1](https://discourse.nodered.org/u/issambfs1)\
**Post date:** [8 January 2023 20:20 UTC](https://discourse.nodered.org/t/ask-for-help-with-debug-in-node-red/73324/3 "2023-01-08T20:20:10Z")

</div>

thanks  
but do you know how to stop the delay in the same time  
because it remember the last msg of start

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [30 January 2023 13:14 UTC](https://discourse.nodered.org/t/ask-for-help-with-debug-in-node-red/73324/4 "2023-01-30T13:14:25Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
