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

**URL:** <https://discourse.nodered.org/t/need-to-design-aflow-that-every-30-min-bursts-x-message-with-a-30ms-interval/30486>\
**Category:** General\
**Created:** [21 July 2020 14:27 UTC](https://discourse.nodered.org/t/need-to-design-aflow-that-every-30-min-bursts-x-message-with-a-30ms-interval/30486 "2020-07-21T14:27:16Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![bioshock2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bioshock2k/32/24830_2.png) [@bioshock2k](https://discourse.nodered.org/u/bioshock2k)\
**Post date:** [21 July 2020 14:27 UTC](https://discourse.nodered.org/t/need-to-design-aflow-that-every-30-min-bursts-x-message-with-a-30ms-interval/30486/1 "2020-07-21T14:27:16Z")

</div>

Hello dear forum users,

I am testing a equipment and need to make a flow that every 30 min burst Xmessages i have already saved on a variable in a 30 ms interval between them.

I can make one that sends messages every 30 ms or other that sends every 60 seconds but a dynamic one i cannot wrap my head around it.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [21 July 2020 14:36 UTC](https://discourse.nodered.org/t/need-to-design-aflow-that-every-30-min-bursts-x-message-with-a-30ms-interval/30486/2 "2020-07-21T14:36:44Z")

</div>

Use a function node that gets triggered by an inject node every 30 minutes. In the function node iterate over your variable (an array?) and use the async node.send() function [described here in the part about sending async messages](https://nodered.org/docs/user-guide/writing-functions), something like:

```auto
var myArray = [1,2,3,4,5];
myArray.forEach(item => node.send({payload:item}));
return;

```

and then put a delay node in rate limit mode behind it that only lets through a message every 30 ms.

---

<div class="post-metadata">

**Author:** ![bioshock2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bioshock2k/32/24830_2.png) [@bioshock2k](https://discourse.nodered.org/u/bioshock2k)\
**Post date:** [21 July 2020 14:46 UTC](https://discourse.nodered.org/t/need-to-design-aflow-that-every-30-min-bursts-x-message-with-a-30ms-interval/30486/3 "2020-07-21T14:46:45Z")

</div>

My "variable" maybe not well explained is a json stored in flow.X variable.  
I see the logic behind your explanation! I just don´t see how to make it stop after, let´s say 60s, ON-\>60s-\>OFF and then only 30min after does the cylce repeats for 24H.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [21 July 2020 14:51 UTC](https://discourse.nodered.org/t/need-to-design-aflow-that-every-30-min-bursts-x-message-with-a-30ms-interval/30486/4 "2020-07-21T14:51:27Z")

</div>

What format does your variable have? Are you sending the same variable again and again?

---

<div class="post-metadata">

**Author:** ![bioshock2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bioshock2k/32/24830_2.png) [@bioshock2k](https://discourse.nodered.org/u/bioshock2k)\
**Post date:** [21 July 2020 15:02 UTC](https://discourse.nodered.org/t/need-to-design-aflow-that-every-30-min-bursts-x-message-with-a-30ms-interval/30486/5 "2020-07-21T15:02:34Z")

</div>

It´s an Object with 174 variables. But i am sending the same object over and over again.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [21 July 2020 15:04 UTC](https://discourse.nodered.org/t/need-to-design-aflow-that-every-30-min-bursts-x-message-with-a-30ms-interval/30486/6 "2020-07-21T15:04:54Z")

</div>

but you don’t always want to send all of them but be able to stop sending after a certain amount of time? Because sending all 174 in 30 ms intervals will only need like 4 seconds. So do you want to start over if the 60 seconds are not passed and continue sending them again?

---

<div class="post-metadata">

**Author:** ![bioshock2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bioshock2k/32/24830_2.png) [@bioshock2k](https://discourse.nodered.org/u/bioshock2k)\
**Post date:** [21 July 2020 15:25 UTC](https://discourse.nodered.org/t/need-to-design-aflow-that-every-30-min-bursts-x-message-with-a-30ms-interval/30486/7 "2020-07-21T15:25:10Z")

</div>

My variable is like this

 ![object](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/6/66f9e05a54d87c6d3bff6c8c67f5cf71ea075dfc.png)

It goes in a whole.so i want to send the whole list every 30 ms.

Simulating a system that is sending only 1 mes a minute and every 30 mins sends a burst off messages that takes X mins.  
after the burst it retakes the one message a minute.

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [21 July 2020 15:54 UTC](https://discourse.nodered.org/t/need-to-design-aflow-that-every-30-min-bursts-x-message-with-a-30ms-interval/30486/8 "2020-07-21T15:54:20Z")

</div>

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:

 ![Screenshot 2020-07-21 at 17.46.46](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/4/249aea8ce56ccbc11c39e9e03faec15e3f4e0960.png)

```auto
[{"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:

```auto
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 😊  
Johannes

---

<div class="post-metadata">

**Author:** ![bioshock2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bioshock2k/32/24830_2.png) [@bioshock2k](https://discourse.nodered.org/u/bioshock2k)\
**Post date:** [21 July 2020 16:15 UTC](https://discourse.nodered.org/t/need-to-design-aflow-that-every-30-min-bursts-x-message-with-a-30ms-interval/30486/9 "2020-07-21T16:15:31Z")

</div>

It is exactly this!  
My understanding off javascript are far from doing this, thank you a lot!

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [21 July 2020 16:21 UTC](https://discourse.nodered.org/t/need-to-design-aflow-that-every-30-min-bursts-x-message-with-a-30ms-interval/30486/10 "2020-07-21T16:21:32Z")

</div>

You will get used to javascript and its fortunately not that hard. I really recommend you read up on the methods like setTimeout() and setInterval() i used as adding those basics to your knowledge will always be good and its good to understand the code one uses.  
I always liked the documentation by mozilla to look up things like this:

> **[JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript)**
>
> JavaScript (JS) is a lightweight, interpreted, or just-in-time compiled programming language with first-class functions. While it is most well-known as the scripting language for Web pages, many non-browser environments also use it, such as Node.js,...

---

<div class="post-metadata">

**Author:** ![bioshock2k](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bioshock2k/32/24830_2.png) [@bioshock2k](https://discourse.nodered.org/u/bioshock2k)\
**Post date:** [21 July 2020 16:30 UTC](https://discourse.nodered.org/t/need-to-design-aflow-that-every-30-min-bursts-x-message-with-a-30ms-interval/30486/11 "2020-07-21T16:30:57Z")

</div>

Thank you!  
I will

---

<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:** [4 August 2020 16:31 UTC](https://discourse.nodered.org/t/need-to-design-aflow-that-every-30-min-bursts-x-message-with-a-30ms-interval/30486/12 "2020-08-04T16:31:13Z")

</div>

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