# Inject node - repeat. Stuck if it can be set externally

**URL:** <https://discourse.nodered.org/t/inject-node-repeat-stuck-if-it-can-be-set-externally/3601>\
**Category:** General\
**Created:** [1 October 2018 22:41 UTC](https://discourse.nodered.org/t/inject-node-repeat-stuck-if-it-can-be-set-externally/3601 "2018-10-01T22:41:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [1 October 2018 22:41 UTC](https://discourse.nodered.org/t/inject-node-repeat-stuck-if-it-can-be-set-externally/3601/1 "2018-10-01T22:41:59Z")

</div>

Probably dumb, but here goes:

Is there a way to edit/change/set the repeat interval with flow or global variables?

What I am wanting to do:  
As is, I have an inject node running injects every 10 seconds.

To change that, I have to edit the node and deploy.

I would like to be able to adjust the time. Am I missing a better suited node, or can I control the INJECT node with global. or flow. variables?

Thanks.

---

<div class="post-metadata">

**Author:** ![JayDickson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jaydickson/32/90592_2.png) [@JayDickson](https://discourse.nodered.org/u/JayDickson)\
**Post date:** [1 October 2018 23:54 UTC](https://discourse.nodered.org/t/inject-node-repeat-stuck-if-it-can-be-set-externally/3601/2 "2018-10-01T23:54:25Z")

</div>

Not sure if you can do anything of the sort with the inject node, but you could probably get something lik eyou describe working with a function node using the setTimeout() or setInterval() function in a loop. Don't have a working example at the moment because I'm crap at javascript still, and lazy to boot.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [2 October 2018 02:53 UTC](https://discourse.nodered.org/t/inject-node-repeat-stuck-if-it-can-be-set-externally/3601/3 "2018-10-02T02:53:13Z")

</div>

No worries.

I know the feeling.

I'll look into it soon. But thanks for the suggestions.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [2 October 2018 14:52 UTC](https://discourse.nodered.org/t/inject-node-repeat-stuck-if-it-can-be-set-externally/3601/4 "2018-10-02T14:52:37Z")

</div>

Something like this should do it.  
It starts with the repeat interval set in the delay node and the delay can then be changed by passing in a message with topic "interval" and payload the new interval in milliseconds, as in the inject nodes in bottom left. This could come from dashboard or similar. The new interval starts when the previous one completes.

```auto
[{"id":"ef7b4377.66962","type":"delay","z":"6dc690a3.1abc88","name":"Variable delay","pauseType":"delayv","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":453,"y":334,"wires":[["8790fde9.bfac7","b8cdb4ce.27604"]]},{"id":"acd865a2.21a378","type":"inject","z":"6dc690a3.1abc88","name":"Message to inject repeatedly","topic":"","payload":"Some value","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":167,"y":333,"wires":[["ef7b4377.66962","8790fde9.bfac7"]]},{"id":"8790fde9.bfac7","type":"debug","z":"6dc690a3.1abc88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":671,"y":492,"wires":[]},{"id":"b8cdb4ce.27604","type":"function","z":"6dc690a3.1abc88","name":"Implement variable repeat interval","func":"if (msg.topic === \"interval\") {\n context.set(\"interval\", msg.payload);\n msg = null;\n} else {\n var interval = context.get(\"interval\");\n if (interval) msg.delay = interval;\n}\nreturn msg;","outputs":1,"noerr":0,"x":486,"y":387,"wires":[["ef7b4377.66962"]]},{"id":"852fbaa7.f7223","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"interval","payload":"5000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":128,"y":600,"wires":[["b8cdb4ce.27604"]]},{"id":"11ab25e3.39c59a","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"interval","payload":"2000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":128,"y":558,"wires":[["b8cdb4ce.27604"]]},{"id":"5d7bc46a.fa6a24","type":"comment","z":"6dc690a3.1abc88","name":"Set the repeat interval using msg with topic \"interval\" and value in payload in milliseconds","info":"","x":346,"y":644,"wires":[]},{"id":"4e44f7fc.2d7ff","type":"comment","z":"6dc690a3.1abc88","name":"Repeated message here","info":"","x":654,"y":534,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 October 2018 20:55 UTC](https://discourse.nodered.org/t/inject-node-repeat-stuck-if-it-can-be-set-externally/3601/6 "2018-10-03T20:55:51Z")

</div>

Colin,

THANKS.

I don't know how I didn't think of that. But it is not unknown for me to miss things.  
Looks good.

DrMibell,  
Thanks also.

(Rhetorical) But this has to repeat forever...... I am not sure how I am going to enter infinity in the" max count" field.

But I have installed that node and it may be handy for other things.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [3 October 2018 21:09 UTC](https://discourse.nodered.org/t/inject-node-repeat-stuck-if-it-can-be-set-externally/3601/7 "2018-10-03T21:09:54Z")

</div>

> [@Trying\_to\_learn](#):
>
> (Rhetorical) But this has to repeat forever...... I am not sure how I am going to enter infinity in the" max count" field.

Actually, not rhetorical (see docs). Just set the `max count` to zero.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [3 October 2018 21:10 UTC](https://discourse.nodered.org/t/inject-node-repeat-stuck-if-it-can-be-set-externally/3601/8 "2018-10-03T21:10:31Z")

</div>

Ah, oops.

(Early morning just woke up.)

Thanks.

---

<div class="post-metadata">

**Author:** ![fishman](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@fishman](https://discourse.nodered.org/u/fishman)\
**Post date:** [9 February 2020 12:12 UTC](https://discourse.nodered.org/t/inject-node-repeat-stuck-if-it-can-be-set-externally/3601/9 "2020-02-09T12:12:41Z")

</div>

Hi Colin. Thank you for the flow. I needed to control a polling interval set from a slider. Your flow was just what I needed. I don't think you can change the delay in node-red-contrib-msg-resend with a variable like you can in your flow, but I might be wrong
