Combine Data / Array

Hi, everyone. I have a problems about the join node.

Example : When I interval the timestamp, all the node will run. Their will display 26 data.


image

But now the problems is sometime the join node get the duplicated data. (Example : 2 main_fail)
If I dont want using join node, How to write a function combine all the array or data?

TQVM.

Node-RED can struggle to keep things synchronized when you have multiple wires feeding into one node like this, but especially when you have so many database nodes and are forcing it to open and close a lot of connections.
Is there a reason you’re getting the data points with these separate SQL nodes? or would you be able to get all of the data with one select? That would simplify things a lot and likely help solve your synchronizing issue.

3 Likes

Since your question is more general in nature perhaps the Node-RED people have some answers on their forum?

2 Likes

The issues is that some of your database nodes are taking longer to respond then your inject interval, so the interval gets triggered a second time and the faster responding DB queries hit your join node twice.

It would be best to consider what @torchard suggests by using a single query to get your data, but if you really want to stick with this design, you could make use of Node-Red flow context to set a flag prior to your database calls and clears it after your join. You would then check that this flag is clear before running the flow again. You also may want to increase the interval of your inject node.

3 Likes

Please try this, and let me know if it helps.

[{"id":"f17abf82.120ce8","type":"join","z":"928d9b65.5f22a","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":830,"y":160,"wires":[["6676789b.2648a8"]]},{"id":"4cef14bf.99f06c","type":"change","z":"928d9b65.5f22a","name":"set topic 1","rules":[{"t":"set","p":"topic","pt":"msg","to":"a","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":120,"wires":[["f17abf82.120ce8"]]},{"id":"f1b62f14.58da2","type":"change","z":"928d9b65.5f22a","name":"set topic 2","rules":[{"t":"set","p":"topic","pt":"msg","to":"b","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":160,"wires":[["f17abf82.120ce8"]]},{"id":"452690cc.e4b968","type":"change","z":"928d9b65.5f22a","name":"set topic 3","rules":[{"t":"set","p":"topic","pt":"msg","to":"c","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":200,"wires":[["f17abf82.120ce8"]]},{"id":"e0859aba.9c11b8","type":"inject","z":"928d9b65.5f22a","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":410,"y":120,"wires":[["4cef14bf.99f06c"]]},{"id":"f32c41ac.b54678","type":"inject","z":"928d9b65.5f22a","name":"","topic":"","payload":"2","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":410,"y":160,"wires":[["f1b62f14.58da2"]]},{"id":"717ee388.87a1ac","type":"inject","z":"928d9b65.5f22a","name":"","topic":"","payload":"3","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":410,"y":200,"wires":[["452690cc.e4b968"]]},{"id":"6676789b.2648a8","type":"function","z":"928d9b65.5f22a","name":"list","func":"a = msg.payload.a\nb = msg.payload.b\nc = msg.payload.c\n\nvar list = [a,b,c]\nvar msg1 = {payload:list}\nreturn msg1;","outputs":1,"noerr":0,"x":970,"y":160,"wires":[["920e7a2f.0d4888"]]},{"id":"920e7a2f.0d4888","type":"debug","z":"928d9b65.5f22a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1130,"y":160,"wires":[]}]
1 Like

Hi torchard, philip, actually I want get all the data. The following picture is main_fail function(active) and main_fail(off).


msg.main_fail[0] is I get the data from database. Then the IntData check is 1 or 0 if it is one the run the msg.payload else return null. So my join node got 26 data or array.

If got any suggestion I will try.

okay Beno.

Hi Eugene, actually my timestamp is interval and I can get all the output but the things is sometime I will get the duplicated data. If I dont want use join node how to combine all the array data?

Thanks.

Sorry I didn’t understood the picture you send. When you say duplicate data do you mean,
The same data (26 Data is the same) is sent two times in Join Output? Have you consider to use RBE node?

RBE node will not output data, unless data becomes not the same.

This is my problems. Sorry for broken english.
Example:

Step 1: In the groov view I key in all is “0” mean they just send the Off node to the website.
Step 2 : I key in main_fail and upsensor_fail become “1”, they just send the main_fail (active), upsensor_fail (active) other send the off node.
Step 3 : I key in the upsensor_fail become “0”, they just send the main_fail(active) other send the off node.
until step 3 don’t have problems when I continue with step 4…
Step 4 : I key in the main_fail become “0”, sometime I can get the main_fail “0” sometime I get multiple s_estop.

Thanks.

Can you show us a couple of your DB queries so we can see if they can be consolidated into a single database call?

3 Likes

Sorry for reply late.

with a as
(SELECT TOP 2 *
FROM [trainee].[dbo].[Alarm] WHERE Strings=‘upsensor_fail’ ORDER BY ID DESC)
select * from a ORDER BY ID asc

This is my query and I just change the Strings name only.
image

I store all the data in here.
image

Thanks

From your screenshot, it looks like SSMS, so I am assuming MSQL/Transact SQL.

You CAN make one sql call to get the data. You will need to re-work your logic though.

I can not tell what your goals are from what you posted, but if you need the last two records for each different value in “Strings” from the database, you can send each query you are currently using separated with “union all”.

Better would be to run a query like the following which will return the same thing, but be a lot more efficient:

select top 1 with ties
Id, Integers, Strings
from a
order by case when row_number() over(partition by Strings order by Id desc) <=2 then 0 else 1 end;

Your function node would then need reworked to process the data that is returned, since you will be getting ALL the data at one time instead of two records at a time. It would be best to look at writing a loop and use a single function node instead of the 26 you have now…

2 Likes