# Inject 20 times with 1 sec intervals

**URL:** <https://discourse.nodered.org/t/inject-20-times-with-1-sec-intervals/41714>\
**Category:** General\
**Created:** [27 February 2021 13:49 UTC](https://discourse.nodered.org/t/inject-20-times-with-1-sec-intervals/41714 "2021-02-27T13:49:58Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benja](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@Benja](https://discourse.nodered.org/u/Benja)\
**Post date:** [27 February 2021 13:49 UTC](https://discourse.nodered.org/t/inject-20-times-with-1-sec-intervals/41714/1 "2021-02-27T13:49:58Z")

</div>

Is there a way to trigger an inject 20 times with 1 sec intervals?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [27 February 2021 13:54 UTC](https://discourse.nodered.org/t/inject-20-times-with-1-sec-intervals/41714/2 "2021-02-27T13:54:28Z")

</div>

yes.

One way...  
inject node set to repeat every 1s → function node (write `for` loop calling `node.send(msg)` )

* * *

Another way...

inject node set to repeat every 1s & set to send a JSON payload of [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19] → split node

---

<div class="post-metadata">

**Author:** ![Benja](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@Benja](https://discourse.nodered.org/u/Benja)\
**Post date:** [27 February 2021 14:14 UTC](https://discourse.nodered.org/t/inject-20-times-with-1-sec-intervals/41714/3 "2021-02-27T14:14:41Z")

</div>

Sorry my bad, I made the question wrong

I meant something like this but 20 times

![Captura2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ffd0f5f275a5533e96e52916f7503b15b9bb5d4c.jpeg)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [27 February 2021 14:18 UTC](https://discourse.nodered.org/t/inject-20-times-with-1-sec-intervals/41714/4 "2021-02-27T14:18:03Z")

</div>

really still not clear.

Do you want

- 20 messages spaced out over 1 second?
- 20 messages sent as fast as possible every 1 second?
- 20 messages 1 second apart? (only when triggered)
- 20 messages spaced out across one minute?

---

<div class="post-metadata">

**Author:** ![Benja](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@Benja](https://discourse.nodered.org/u/Benja)\
**Post date:** [27 February 2021 14:20 UTC](https://discourse.nodered.org/t/inject-20-times-with-1-sec-intervals/41714/5 "2021-02-27T14:20:24Z")

</div>

The first one, 20 messages spaced out over 1 sec (when triggered)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [27 February 2021 14:21 UTC](https://discourse.nodered.org/t/inject-20-times-with-1-sec-intervals/41714/6 "2021-02-27T14:21:55Z")

</div>

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

```auto
[{"id":"cc1aa912.9040b8","type":"inject","z":"b872cb4b.5a6448","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, 20]","payloadType":"json","x":810,"y":320,"wires":[["799db71.008f048"]]},{"id":"799db71.008f048","type":"split","z":"b872cb4b.5a6448","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":980,"y":320,"wires":[["23ac00a2.0181d"]]},{"id":"23ac00a2.0181d","type":"delay","z":"b872cb4b.5a6448","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"20","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1150,"y":320,"wires":[["3e92a72f.979108"]]},{"id":"3e92a72f.979108","type":"debug","z":"b872cb4b.5a6448","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1330,"y":320,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [27 February 2021 14:26 UTC](https://discourse.nodered.org/t/inject-20-times-with-1-sec-intervals/41714/7 "2021-02-27T14:26:43Z")

</div>

looking at your picture

> [@Benja](#):
>
> ![Captura2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/f/ffd0f5f275a5533e96e52916f7503b15b9bb5d4c.jpeg)

... it looks more like you want : 1 MESSAGE - EVERY 1 SEC

in which case this is better...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/3/93f89fd3bcae7fcb92ef47610095cda6af81a319.png)

```auto
[{"id":"cc1aa912.9040b8","type":"inject","z":"b872cb4b.5a6448","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, 20]","payloadType":"json","x":810,"y":320,"wires":[["799db71.008f048"]]},{"id":"799db71.008f048","type":"split","z":"b872cb4b.5a6448","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":980,"y":320,"wires":[["23ac00a2.0181d"]]},{"id":"23ac00a2.0181d","type":"delay","z":"b872cb4b.5a6448","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1140,"y":320,"wires":[["3e92a72f.979108"]]},{"id":"3e92a72f.979108","type":"debug","z":"b872cb4b.5a6448","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1330,"y":320,"wires":[]}]

```

its basically the same but the rate limiter is set to release 1 msg every 1 sec

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [27 February 2021 14:31 UTC](https://discourse.nodered.org/t/inject-20-times-with-1-sec-intervals/41714/8 "2021-02-27T14:31:35Z")

</div>

here it is via a function node...

 ![7k6mANFE8j](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/f/5fcf7c2bf573ac400acc2a09db1a79e5cc706e3e.gif)

```auto
[{"id":"cc1aa912.9040b8","type":"inject","z":"b872cb4b.5a6448","name":"send 20","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","x":1770,"y":140,"wires":[["4aef892d.e42408"]]},{"id":"4aef892d.e42408","type":"function","z":"b872cb4b.5a6448","name":"generate x messages","func":"var no_of_messages_to_send = msg.payload;\nfor (let index = 0; index < no_of_messages_to_send; index++) {\n msg.payload = index;\n node.send(msg);\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1980,"y":140,"wires":[["2f301ae3.d5eee6"]]},{"id":"2f301ae3.d5eee6","type":"delay","z":"b872cb4b.5a6448","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":2010,"y":200,"wires":[["a23ffbf4.3891e8"]]},{"id":"a23ffbf4.3891e8","type":"debug","z":"b872cb4b.5a6448","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2050,"y":260,"wires":[]},{"id":"eec3b112.30923","type":"inject","z":"b872cb4b.5a6448","name":"send 5","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5","payloadType":"num","x":1770,"y":200,"wires":[["4aef892d.e42408"]]}]

```

---

<div class="post-metadata">

**Author:** ![Benja](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@Benja](https://discourse.nodered.org/u/Benja)\
**Post date:** [27 February 2021 14:34 UTC](https://discourse.nodered.org/t/inject-20-times-with-1-sec-intervals/41714/9 "2021-02-27T14:34:09Z")

</div>

Thx that's what i needed!!

---

<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:** [13 March 2021 14:34 UTC](https://discourse.nodered.org/t/inject-20-times-with-1-sec-intervals/41714/10 "2021-03-13T14:34:29Z")

</div>

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