Send a predifined payload via a interval

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 ?

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

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

yes , thats what i want , to adshieve

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

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

chrome_SgiiDWyxv8

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

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.

1 Like

works like a sharm !
thx

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

1 Like

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

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 :sweat_smile:)

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.

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