# Send a predifined payload via a interval

**URL:** <https://discourse.nodered.org/t/send-a-predifined-payload-via-a-interval/83404>\
**Category:** General\
**Created:** [3 December 2023 15:11 UTC](https://discourse.nodered.org/t/send-a-predifined-payload-via-a-interval/83404 "2023-12-03T15:11:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![plekke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/plekke/32/81640_2.png) [@plekke](https://discourse.nodered.org/u/plekke)\
**Post date:** [3 December 2023 15:11 UTC](https://discourse.nodered.org/t/send-a-predifined-payload-via-a-interval/83404/1 "2023-12-03T15:11:53Z")

</div>

i use in node red a 'trigger node'  
every second its sends a trigger to my function node.  
and my function sends a global out via 'node.send' .

i want to update my flow , and i want to store a list of values .  
now i want nodered to send out , every second the next element of my list

how can i achieve this ?

```auto
global.set("adresscanner2",['v' , 'i' , 'g' , 'h']);

```

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [3 December 2023 15:18 UTC](https://discourse.nodered.org/t/send-a-predifined-payload-via-a-interval/83404/2 "2023-12-03T15:18:22Z")

</div>

Hi @plekke

Sorry I cant quite grasp the requirement.  
What do you mean by `"my function sends a global out via 'node.send'"`

You don't send a global  
You can send a value retrieved from a global if that is what you mean? but the concept of sending a global is invalid.

Do you mean you have a global list of values and want to send each 1 in sequence through the flow every 1 second?

**EDIT**

Example

1s..... v  
2s..... I  
3s..... g  
4s..... h  
5s..... v  
6s..... I  
7s..... g  
8s..... h

---

<div class="post-metadata">

**Author:** ![plekke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/plekke/32/81640_2.png) [@plekke](https://discourse.nodered.org/u/plekke)\
**Post date:** [3 December 2023 15:30 UTC](https://discourse.nodered.org/t/send-a-predifined-payload-via-a-interval/83404/3 "2023-12-03T15:30:56Z")

</div>

> [@marcus-j-davies](#):
>
> Example
> 
> 1s..... v  
> 2s..... I  
> 3s..... g  
> 4s..... h  
> 5s..... v  
> 6s..... I  
> 7s..... g  
> 8s..... h

yes , thats what i want , to adshieve

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [3 December 2023 15:34 UTC](https://discourse.nodered.org/t/send-a-predifined-payload-via-a-interval/83404/4 "2023-12-03T15:34:17Z")

</div>

Ok...

On the basis you have a global variable called `adresscanner2` and its an array of values.

Setup an `inject` node to insert every 1s, attached to a `function` node with the below  
this will send through each value in sequence, and will wrap around once it's at the end of the array

this stores the index in the node's context - but nothing stopping you using the global context either

```auto
const myArray = global.get("adresscanner2")
let index = context.get("index") || 0;

const Message = {
    payload: myArray[index]
}

index ++;
if(index > myArray.length-1){
    index = 0;
}

context.set("index", index)

return Message

```

---

<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:** [3 December 2023 15:44 UTC](https://discourse.nodered.org/t/send-a-predifined-payload-via-a-interval/83404/5 "2023-12-03T15:44:18Z")

</div>

![chrome_SgiiDWyxv8](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f6bdf64d48ee51cd3e31ac284dd56eb5b4b94099.gif)

```auto
[{"id":"e0529fb22a197e5b","type":"inject","z":"f3c2b0a8769a5230","name":"[\"x\" , \"y\" , \"z\"]","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"x\" , \"y\" , \"z\"]","payloadType":"json","x":2530,"y":380,"wires":[["cbf0c464610bc833"]]},{"id":"cbf0c464610bc833","type":"change","z":"f3c2b0a8769a5230","name":"set adresscanner2","rules":[{"t":"set","p":"adresscanner2","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2770,"y":360,"wires":[[]]},{"id":"48b058c02e019c17","type":"inject","z":"f3c2b0a8769a5230","name":"get adresscanner2","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"adresscanner2","payloadType":"global","x":2550,"y":440,"wires":[["aa0c1acb2f20a0c0"]]},{"id":"56c7a71dbc137da5","type":"delay","z":"f3c2b0a8769a5230","name":"","pauseType":"rate","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":2850,"y":440,"wires":[["f1a920153fca9b95"]]},{"id":"aa0c1acb2f20a0c0","type":"split","z":"f3c2b0a8769a5230","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":2710,"y":440,"wires":[["56c7a71dbc137da5"]]},{"id":"f1a920153fca9b95","type":"debug","z":"f3c2b0a8769a5230","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2850,"y":520,"wires":[]},{"id":"81fd3ee31e224ad3","type":"inject","z":"f3c2b0a8769a5230","name":"[\"v\" , \"i\" , \"g\" , \"h\"]","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"[\"v\" , \"i\" , \"g\" , \"h\"]","payloadType":"json","x":2550,"y":340,"wires":[["cbf0c464610bc833"]]}]

```

---

<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:** [3 December 2023 15:45 UTC](https://discourse.nodered.org/t/send-a-predifined-payload-via-a-interval/83404/6 "2023-12-03T15:45:11Z")

</div>

Or, send the whole array out as an array. Feed it through a Split node which will split the array into individual messages, then through a Delay node set to Rate Limit mode at one per second.

---

<div class="post-metadata">

**Author:** ![plekke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/plekke/32/81640_2.png) [@plekke](https://discourse.nodered.org/u/plekke)\
**Post date:** [3 December 2023 15:45 UTC](https://discourse.nodered.org/t/send-a-predifined-payload-via-a-interval/83404/7 "2023-12-03T15:45:40Z")

</div>

works like a sharm !  
thx

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [3 December 2023 15:46 UTC](https://discourse.nodered.org/t/send-a-predifined-payload-via-a-interval/83404/8 "2023-12-03T15:46:31Z")

</div>

The above by @Steve-Mcl & @Colin removes the need for the `function` node if you prefer

---

<div class="post-metadata">

**Author:** ![plekke](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/plekke/32/81640_2.png) [@plekke](https://discourse.nodered.org/u/plekke)\
**Post date:** [3 December 2023 15:47 UTC](https://discourse.nodered.org/t/send-a-predifined-payload-via-a-interval/83404/9 "2023-12-03T15:47:21Z")

</div>

i gonna check this out to ,  
im never to old to learn and check these solutions

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [3 December 2023 16:23 UTC](https://discourse.nodered.org/t/send-a-predifined-payload-via-a-interval/83404/10 "2023-12-03T16:23:22Z")

</div>

> [@Colin](#):
>
> Or, send the whole array out as an array. Feed it through a Split node which will split the array into individual messages, then through a Delay node set to Rate Limit mode at one per second.

I often forget about the core nodes for stuff like this - I think the penny will drop at some point (he says after 4 years 😅)

My only excuse is being a .NET/JS developer for the company I work for - so tend to spend a lot of time using javascript exclusively for solutions.

---

<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:** [17 December 2023 16:23 UTC](https://discourse.nodered.org/t/send-a-predifined-payload-via-a-interval/83404/11 "2023-12-17T16:23:46Z")

</div>

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