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

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?


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.

1 Like

No worries.

I know the feeling.

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

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.

[{"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":[]}]



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

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.

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

Ah, oops.

(Early morning just woke up.)


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