Split an Array of 150 values into shorter 15 Arrays of 10 values

Hi Everyone!

I am new to node-red. I am receiving an array of 150 values from PLC via OPC UA in node-red. Now I have to upload these to the Thingspeak MATLAB cloud. The cloud has limitations; the channels in the cloud update after every 15 seconds and maximum values that can be uploaded on a channel are 12.

I need to split the Array of 150 values into shorter arrays of 10 values each and also send each shorter array after 15 seconds delay. This is because if I send the values before the 15 second delay, the values get over-ridden.

In short: Split a large Array of 150 values into 15 shorter Arrays of 10 values each after the delay of 15 seconds.

Thank You.

So where is the problem? Take a split node and specify 10 in the len field, which creates arrays with 10 elements.

[
    {
        "id": "bb68ecc0093a7092",
        "type": "split",
        "z": "7e6af0015415146d",
        "name": "split Array",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": "10",
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 620,
        "y": 1240,
        "wires": [
            [
                "117ade0db50aca7c"
            ]
        ]
    },
    {
        "id": "117ade0db50aca7c",
        "type": "delay",
        "z": "7e6af0015415146d",
        "name": "",
        "pauseType": "delay",
        "timeout": "15",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 810,
        "y": 1240,
        "wires": [
            []
        ]
    }
]

I think the delay should be rate limit 1 per 15 seconds, not delay
e.g.

[{"id":"5b2879f291e75a35","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":4680,"wires":[["395a7600299bef98"]]},{"id":"395a7600299bef98","type":"function","z":"da8a6ef0b3c9a5c8","name":"create test array","func":"let count = 0;\nmsg.payload = [...Array(150)].map(() => {\n    count++;\n    return count;\n});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":4680,"wires":[["a47d1a71fb835c99"]]},{"id":"a47d1a71fb835c99","type":"split","z":"da8a6ef0b3c9a5c8","name":"","splt":"\\n","spltType":"str","arraySplt":"10","arraySpltType":"len","stream":false,"addname":"","x":430,"y":4680,"wires":[["4fdf9ca73fc4af33"]]},{"id":"4fdf9ca73fc4af33","type":"delay","z":"da8a6ef0b3c9a5c8","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"15","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":580,"y":4680,"wires":[["930b846aad428369"]]},{"id":"930b846aad428369","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 233","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":4680,"wires":[]}]
1 Like

Thanks for the reply.

I used the split node before but I would need to upload the shorter arrays after 15 seconds each. The split node would split the large array into shorter arrays but I was unable to add a delay of 15 seconds. The shorter arrays need to finally end up in the following node: 'node-red-contrib-thingspeak42'.

I want the 'Thingspeak42' node to receive a shorter array of 10 values from the previous nodes (which split the larger array) after a delay of 15 seconds.

Did you try a delay node in Rate Limit mode as suggested by @E1cid.
If that doesn't work for you please explain better what you need.

No, I have not been able to test it out yet, will do it on Monday. However, I have already tried adding the delay node in the Rate Limit mode but it did not work at that time. Maybe I did not configure it correctly. I will try @E1cid's method and let you guys know afterward.

I have another question regarding this: Can I use the python-function node and write a code that could take the Array of 150 values, split it into shorter 15 arrays of 10 values each, and send each shorter array after a 15-second delay? Will the python-function node work like this?

Why bother? The Delay node in Rate Limit mode configured for 1 message every 15 seconds will only pass 1 message every 15 seconds, which is exactly what you want isn't it? If it doesn't work then show us how you have configured it. Test the node first with an Inject, Delay and Debug and play with the settings so you can see what it does.

@E1cid It worked, however I had to add the join with split node.

@Colin Yes, you were right. I did not actually have to use the python function block. I did it with Join and Split nodes.

That is because you Array of 150 is actually an object, missed that in your OP photo. Happy you found a solution.

1 Like

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