Need to design aflow that every 30 min bursts X message with a 30ms interval

Something like this could do it, of course you would have to adapt it to your times and circumstances as I used way shorter periods to test it and its just a basic example flow. Play with it:

[{"id":"6807ce07.123cd","type":"function","z":"35572fe7.e9aef8","name":"burst","func":"var myObj = msg.payload;\nfunction waitSixty () {\n    setTimeout(()=>{\n        flow.set(\"timeout\", false);\n    },1000);\n}\nfunction repeatThirty (variable) {\n    var interval = setInterval(()=>{\n        node.send({payload:variable});\n        var timeout = flow.get(\"timeout\");\n        if (!timeout) { clearInterval(interval) }\n    },30);\n}\nflow.set(\"timeout\",true);\nwaitSixty();\nrepeatThirty(myObj);\nreturn;","outputs":1,"noerr":0,"x":490,"y":600,"wires":[["73f59f20.280878"]]},{"id":"73f59f20.280878","type":"debug","z":"35572fe7.e9aef8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":660,"wires":[]},{"id":"dae2c46e.ee50c8","type":"inject","z":"35572fe7.e9aef8","name":"","topic":"","payload":"{\"a\":1,\"b\":2,\"c\":3,\"d\":4,\"e\":5}","payloadType":"json","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":600,"wires":[["96bdb47c.7e1b1","b7b885b3.0c9c2"]]},{"id":"96bdb47c.7e1b1","type":"delay","z":"35572fe7.e9aef8","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"10","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":320,"y":600,"wires":[["6807ce07.123cd"]]},{"id":"b7b885b3.0c9c2","type":"switch","z":"35572fe7.e9aef8","name":"","property":"timeout","propertyType":"flow","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":290,"y":660,"wires":[["73f59f20.280878"]]}]

So you have an inject which sends your var every second in this example, the var is only let through if a variable set by the burst node is false. Every ten seconds in this example flow a message is let through the delay node in rate limit mode to trigger the burst function. The burst function has two functions inside. One is setTimeout() that turns the timeout variable to true for 1 second in this case the other is a setInterval() that send the received msg.payload every 30 ms while the timeout variable is true. This is the same variable that is beeing checked in the switch node. so while the burst runs no messages will be passed there. The function node code is:

var myObj = msg.payload;
function waitSixty () {
    setTimeout(()=>{
        flow.set("timeout", false);
    },1000);
}
function repeatThirty (variable) {
    var interval = setInterval(()=>{
        node.send({payload:variable});
        var timeout = flow.get("timeout");
        if (!timeout) { clearInterval(interval) }
    },30);
}
flow.set("timeout",true);
waitSixty();
repeatThirty(myObj);
return;

Maybe you can apply some of the concepts in this example to your problem :blush:
Johannes

2 Likes