• Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    clearTimeout not working ?

    Node-RED
    1
    2
    36
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      TARIK DR last edited by

      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();
      
      1 Reply Last reply Reply Quote 0
      • T
        TARIK DR last edited by TARIK DR

        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); 
              },  
              }
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post