# Double message in join node

**URL:** <https://discourse.nodered.org/t/double-message-in-join-node/78382>\
**Category:** General\
**Created:** [12 May 2023 12:35 UTC](https://discourse.nodered.org/t/double-message-in-join-node/78382 "2023-05-12T12:35:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![pcnr](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@pcnr](https://discourse.nodered.org/u/pcnr)\
**Post date:** [12 May 2023 12:35 UTC](https://discourse.nodered.org/t/double-message-in-join-node/78382/1 "2023-05-12T12:35:25Z")

</div>

Good evening everyone  
I noticed a strange behaviour with my join node, probably I misconfigured it.  
The flow gets a message with GPS data, extract latitude and longitude in two different branches and then I join them together to make a single message  
The problem is, I have no idea why but I'm getting 2 messages at the same time (with slightly different data). I tought about the flag of the 2 message parts but I think that's correct? I need both messages to get a full position  
Probably I'm doing something stupid, any help is appreciated

```auto
[
    {
        "id": "bbaab412081cb0ee",
        "type": "function",
        "z": "3af70a9829406ec3",
        "name": "NMEA to human",
        "func": "let pos = msg.payload.indexOf(\".\")\nlet minutes = msg.payload.substring(pos-2)\nlet degrees = msg.payload.substring(0, pos-2)\nlet temp = Number(degrees) + (Number(minutes)/60)\nmsg.payload = temp\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 520,
        "y": 580,
        "wires": [
            [
                "2987fe00cd334ebd"
            ]
        ]
    },
    {
        "id": "5ad5ec586f14b9ed",
        "type": "function",
        "z": "3af70a9829406ec3",
        "name": "NMEA to human",
        "func": "let pos = msg.payload.indexOf(\".\")\nlet minutes = msg.payload.substring(pos-2)\nlet degrees = msg.payload.substring(0, pos-2)\nlet temp = Number(degrees) + (Number(minutes)/60)\nmsg.payload = temp\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 520,
        "y": 540,
        "wires": [
            [
                "bf24f301c2e25934"
            ]
        ]
    },
    {
        "id": "60010beafd8ae5b9",
        "type": "string",
        "z": "3af70a9829406ec3",
        "name": "filter E",
        "methods": [
            {
                "name": "between",
                "params": [
                    {
                        "type": "str",
                        "value": "N,"
                    },
                    {
                        "type": "str",
                        "value": ",E,"
                    }
                ]
            }
        ],
        "prop": "payload",
        "propout": "payload",
        "object": "msg",
        "objectout": "msg",
        "x": 350,
        "y": 580,
        "wires": [
            [
                "bbaab412081cb0ee"
            ]
        ]
    },
    {
        "id": "640a1bbc0b9213ac",
        "type": "string",
        "z": "3af70a9829406ec3",
        "name": "filter N",
        "methods": [
            {
                "name": "between",
                "params": [
                    {
                        "type": "str",
                        "value": "+CGPSINFO:"
                    },
                    {
                        "type": "str",
                        "value": ",N,"
                    }
                ]
            }
        ],
        "prop": "payload",
        "propout": "payload",
        "object": "msg",
        "objectout": "msg",
        "x": 350,
        "y": 540,
        "wires": [
            [
                "5ad5ec586f14b9ed"
            ]
        ]
    },
    {
        "id": "2987fe00cd334ebd",
        "type": "change",
        "z": "3af70a9829406ec3",
        "name": "set topic: E",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "E",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 730,
        "y": 580,
        "wires": [
            [
                "5e6e5576958b3129"
            ]
        ]
    },
    {
        "id": "bf24f301c2e25934",
        "type": "change",
        "z": "3af70a9829406ec3",
        "name": "set topic: N",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "N",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 730,
        "y": 540,
        "wires": [
            [
                "5e6e5576958b3129"
            ]
        ]
    },
    {
        "id": "5e6e5576958b3129",
        "type": "join",
        "z": "3af70a9829406ec3",
        "name": "Join topics",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": true,
        "timeout": "",
        "count": "2",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 910,
        "y": 560,
        "wires": [
            [
                "979d4f7a4b2d18f9"
            ]
        ]
    },
    {
        "id": "979d4f7a4b2d18f9",
        "type": "function",
        "z": "3af70a9829406ec3",
        "name": "Merge to string",
        "func": "let temp = \"{ \\\"type\\\":\\\"Point\\\",\\\"coordinates\\\": [\" + msg.payload.E + \", \" + msg.payload.N + \"]}\"\nmsg.payload = temp\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1100,
        "y": 560,
        "wires": [
            [
                "225754e90cfb26c4",
                "d8efe248e1a37329"
            ]
        ]
    }
]

```

Thanks  
P

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [12 May 2023 13:06 UTC](https://discourse.nodered.org/t/double-message-in-join-node/78382/2 "2023-05-12T13:06:01Z")

</div>

You are getting two messages because you have told the join node to output every subsequent message.

---

<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:** [12 May 2023 13:08 UTC](https://discourse.nodered.org/t/double-message-in-join-node/78382/3 "2023-05-12T13:08:07Z")

</div>

> [@pcnr](#):
>
> The flow gets a message with GPS data, extract latitude and longitude in two different branches and then I join them together to make a single message

Do you mean that you start off with one message, then split it and then join it together again, or do the lat and lon come in from the source in separate messages?

---

<div class="post-metadata">

**Author:** ![pcnr](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@pcnr](https://discourse.nodered.org/u/pcnr)\
**Post date:** [12 May 2023 16:01 UTC](https://discourse.nodered.org/t/double-message-in-join-node/78382/4 "2023-05-12T16:01:10Z")

</div>

> [@E1cid](#):
>
> You are getting two messages because you have told the join node to output every subsequent message.

Oh, I tought that just meant "don't stop after 1 message but join the next 2 etc.

> [@Colin](#):
>
> Do you mean that you start off with one message, then split it and then join it together again, or do the lat and lon come in from the source in separate messages?

Correct, it comes in a single message with a lot of unnecessary stuff, so I split it to clean the message and convert it in a readable format, then join them again

---

<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:** [12 May 2023 17:02 UTC](https://discourse.nodered.org/t/double-message-in-join-node/78382/5 "2023-05-12T17:02:33Z")

</div>

> [@pcnr](#):
>
> I split it to clean the message and convert it in a readable format, then join them again

Why bother splitting and joining? Just ignore the fields that are not relevant. You are just adding overheads by removing them.

---

<div class="post-metadata">

**Author:** ![pcnr](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@pcnr](https://discourse.nodered.org/u/pcnr)\
**Post date:** [15 May 2023 12:52 UTC](https://discourse.nodered.org/t/double-message-in-join-node/78382/6 "2023-05-15T12:52:52Z")

</div>

> [@Colin](#):
>
> Why bother splitting and joining? Just ignore the fields that are not relevant. You are just adding overheads by removing them.

I receive a string as input and I need two different parts of this string (latitude and longitude). Since I'm not too skilled on working with messages I extract the 2 parts with a "between", clean them up and rejoin them with the format I need.

So if I flag "output subsequent messages" it joins message 1 and 2, 2 with 3, 3 with 4 ecc?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [15 May 2023 12:58 UTC](https://discourse.nodered.org/t/double-message-in-join-node/78382/7 "2023-05-15T12:58:06Z")

</div>

You can extract parts do maths and create output in one function node. Not sure i got the correct maths and such but this example should give you some ideas.

```auto
[{"id":"ba525be4809fb0d1","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"+CGPSINFO: 3113.393766,N,12121.176625,E,061108,075358.0,19.5,0","payloadType":"str","x":270,"y":1340,"wires":[["5ad5ec586f14b9ed"]]},{"id":"5ad5ec586f14b9ed","type":"function","z":"b9860b4b9de8c8da","name":"NMEA to human","func":"msg.payload = msg.payload.split(/[,\\.]/);\nlet north = msg.payload[1];\nlet east = msg.payload[4];\nnorth = Number(north.slice(0,-2)) + (Number(north.slice(-2)) / 60) \neast = Number(east.slice(0,-2)) + (Number(east.slice(-2)) / 60)\nmsg.payload = `{\"type\":\"Point\",\"coordinates\":[${north},${east}]}`;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":1340,"wires":[["1363d5edcc60e58a"]]},{"id":"1363d5edcc60e58a","type":"debug","z":"b9860b4b9de8c8da","name":"debug 289","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":1340,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![pcnr](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@pcnr](https://discourse.nodered.org/u/pcnr)\
**Post date:** [15 May 2023 13:19 UTC](https://discourse.nodered.org/t/double-message-in-join-node/78382/8 "2023-05-15T13:19:09Z")

</div>

> [@E1cid](#):
>
> You can extract parts do maths and create output in one function node. Not sure i got the correct maths and such but this example should give you some ideas.

Thank you very much!  
I'll try to work on your node, much cleaner

---

<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:** [14 July 2023 13:19 UTC](https://discourse.nodered.org/t/double-message-in-join-node/78382/9 "2023-07-14T13:19:51Z")

</div>

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