Join node - how to define order

Hello,

I am having issues with a join node, I cannot find a possibility to sort the parts which I combine into an array.

[
    {
        "id": "9bd5b323.cd419",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "950cb5ae.264438",
        "type": "inject",
        "z": "9bd5b323.cd419",
        "name": "Fronius-P-Average",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            },
            {
                "p": "payload"
            }
        ],
        "repeat": "60",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "Fronius-P-Average",
        "payload": "",
        "payloadType": "date",
        "x": 140,
        "y": 40,
        "wires": [
            [
                "c76562d1.ed33e",
                "fff9a1a3.f312f",
                "bb0c856b.effcc8"
            ]
        ]
    },
    {
        "id": "bb0c856b.effcc8",
        "type": "delay",
        "z": "9bd5b323.cd419",
        "name": "",
        "pauseType": "delay",
        "timeout": "800",
        "timeoutUnits": "milliseconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 110,
        "y": 80,
        "wires": [
            [
                "60862aa1.2cfa54"
            ]
        ]
    },
    {
        "id": "fff9a1a3.f312f",
        "type": "delay",
        "z": "9bd5b323.cd419",
        "name": "",
        "pauseType": "delay",
        "timeout": "1",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "x": 100,
        "y": 120,
        "wires": [
            [
                "cf395317.c971e"
            ]
        ]
    },
    {
        "id": "cf395317.c971e",
        "type": "http request",
        "z": "9bd5b323.cd419",
        "name": "MeterRealtimeData",
        "method": "GET",
        "ret": "obj",
        "paytoqs": false,
        "url": "http://192.168.0.249/solar_api/v1/GetMeterRealtimeData.cgi?Scope=Device&DeviceId=0",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 270,
        "y": 120,
        "wires": [
            [
                "c76562d1.ed33e"
            ]
        ]
    },
    {
        "id": "60862aa1.2cfa54",
        "type": "http request",
        "z": "9bd5b323.cd419",
        "name": "PowerFlowRealtimeData",
        "method": "GET",
        "ret": "obj",
        "paytoqs": false,
        "url": "http://192.168.0.249/solar_api/v1/GetPowerFlowRealtimeData.fcgi",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 330,
        "y": 80,
        "wires": [
            [
                "c76562d1.ed33e"
            ]
        ]
    },
    {
        "id": "c76562d1.ed33e",
        "type": "join",
        "z": "9bd5b323.cd419",
        "name": "",
        "mode": "custom",
        "build": "array",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "3",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 430,
        "y": 120,
        "wires": [
            []
        ]
    }
]

I try to combine two http responses and the timestamp when the inject node fires.

From time to time this chanin stops working, because the inject node "comes too late" with its timestamp. then, atfer the join node, I cannot parse the needed data because the order is mixed up. :frowning:

what I have to do (or did in this case at 10:34:28) is I have to restart or redeploy the affected inject node and all works well afterwards again for weeks ...

I do not know what happens until it stops working. but it always looks the same, the inject timestamp is then on position 2 instead of 1. I am using node red 1.2.9 on a RPI.

As I am not sure at all if I use it as it is thought to use - what do I need to change or what do I need to use to achieve the same in a cleaner, always working flow?

I am doing two HTTP requests to the same host, different API, I need there in total 3 values which I parse afterwards in a function - I guess there is a simplier solution for that.

var e_total = parseInt(msg.payload[1].Body.Data.Site.E_Total) || 0;
var e_importtotal = parseInt(msg.payload[2].Body.Data.EnergyReal_WAC_Plus_Absolute) || 0;
var e_exporttotal = parseInt(msg.payload[2].Body.Data.EnergyReal_WAC_Minus_Absolute) || 0;

Thanks!

BR
Alois

There are two solutions that I can see.

The first is to change the Join node to use key/value pairs. You need to set topic values on the messages going in and then the order does not matter as they will be identifiable by the topic you used. See this article in the cookbook for an example of how to do this.

The second is not to use the Join node at all, but to perform the http requests in series rather than in parallel. To do this perform the first request them move the data you need into a msg property, msg.realtimeData for example. Then feed that message on to perform the second request. After that the data from the first should still be in msg.realtimeData so you will have access to both.

thank you. I made the second option. :slight_smile:

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