clearTimeout not working ?
-
the code must start 2 actuator with delay 3 s in between en every actuator use 2 relays to change diriction
the problem that i can not reset the timeout to close or open the cleartimeout is not working any help plz
function init() { function func_delay(myfunction,circuit,value,timer) { this.timer1 = setTimeout(function(){ this.timer2 = myfunction; node.send({payload: cmd_build(circuit,value)}); }.bind(this), timer); } function stop() { node.warn(this.timer1); node.warn(this.timer2); clearTimeout(this.timer2); clearTimeout(this.timer2); } function router(data ){ switch(data) { case triggers["START_ZONE1"] : node.warn("Zone 1 status Started "); stop(); func_delay(func_delay(null,relays["zone1v2_open"],actions["on"],3000),relays["zone1v1_open"],actions["on"],1000); node.send({payload: cmd_build(relays["zone1v1_close"],actions["off"])}); node.done(); node.send({payload: cmd_build(relays["zone1v2_close"],actions["off"])}); node.done(); msg={topic: "zone1/valves/opening",payload:{"notif":"notif_v1_stat", "message":"zone 1 started"}} node.send(msg) node.done(); // return [null,msg] ; // } // node.warn(msg); break ; case triggers["STOP_ZONE1"] : stop(); func_delay(func_delay(null,relays["zone1v2_close"],actions["on"],3000) ,relays["zone1v1_close"],actions["on"],1000); node.send({payload: cmd_build(relays["zone1v1_open"],actions["off"])}); node.done(); node.send({payload: cmd_build(relays["zone1v2_open"],actions["off"])}); node.done(); msg={topic: "zone1/valves/closing",payload:{"notif":"n1", "message":"Zone 1 stoped"}} // return [null,msg] ; node.send(msg) node.done(); // } break ; default : } } init(); -
after many trys i fund the solution i created the object that contain the timer and the 2 methods start and stop
var newLocal = null; const myAction = { timer: newLocal, start : function (timerr) { return this.timer = setTimeout(function(){ node.warn (cmd_build("circuit",1)); }, timerr); }, stop : function (timer) { return clearTimeout(timer); }, }
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login