Join node creates two msg objects instead of one

I am currently requesting data every second from 13 different sources using a raspberry pi. That data is then given a topic with All/ and then sent over MQTT to my computer. Using a switch node, I separate out the data, and send it to a join node where it is set to wait for 12 parts to send the message across.
The issue is that the msg gets passed on as two separate messages. This is the code I'm using:

[{"id":"3264a3dc.ef8b8c","type":"tab","label":"All","disabled":false,"info":""},{"id":"7145066a.dae008","type":"mqtt in","z":"3264a3dc.ef8b8c","name":"","topic":"All/#","qos":"2","datatype":"auto","broker":"7ac66e23.82af7","x":92.01736068725586,"y":133.0104579925537,"wires":[["db0982de.78d66"]]},{"id":"db0982de.78d66","type":"switch","z":"3264a3dc.ef8b8c","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"All/TotalVolume","vt":"str"},{"t":"eq","v":"All/OverallFlowRate","vt":"str"},{"t":"eq","v":"All/TempA","vt":"str"},{"t":"eq","v":"All/TempB","vt":"str"},{"t":"eq","v":"All/TempC","vt":"str"},{"t":"eq","v":"All/TempD1","vt":"str"},{"t":"eq","v":"All/TempD2","vt":"str"},{"t":"eq","v":"All/TempD3","vt":"str"},{"t":"eq","v":"All/TempD4","vt":"str"},{"t":"eq","v":"All/TempD5","vt":"str"},{"t":"eq","v":"All/GasBufferPressure","vt":"str"},{"t":"eq","v":"All/DewarPressure","vt":"str"}],"checkall":"true","repair":false,"outputs":12,"x":253.71094512939453,"y":132.0781593322754,"wires":[["c1423c17.32119"],["c1423c17.32119"],["c1423c17.32119"],["c1423c17.32119"],["c1423c17.32119"],["c1423c17.32119"],["c1423c17.32119"],["c1423c17.32119"],["c1423c17.32119"],["c1423c17.32119"],["c1423c17.32119"],["c1423c17.32119"]]},{"id":"9f3137d6.89d208","type":"debug","z":"3264a3dc.ef8b8c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":593.0833778381348,"y":128.53473472595215,"wires":[]},{"id":"c1423c17.32119","type":"join","z":"3264a3dc.ef8b8c","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"12","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":426.01739501953125,"y":133.01046085357666,"wires":[["9f3137d6.89d208"]]},{"id":"7ac66e23.82af7","type":"mqtt-broker","z":"","name":"","broker":"192.168.1.50","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

This seems strange, because I am using a similar code to do (what I thought) was the exact same thing in a different flow with a different flow, as shown below:

[{"id":"78e630b8.b4c73","type":"tab","label":"All User","disabled":false,"info":""},{"id":"77ea86f2.c48e48","type":"switch","z":"78e630b8.b4c73","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"AllUser/TotalVolume","vt":"str"},{"t":"eq","v":"AllUser/OverallFlowRate","vt":"str"},{"t":"eq","v":"AllUser/Time","vt":"str"},{"t":"eq","v":"AllUser/TempA","vt":"str"},{"t":"eq","v":"AllUser/TempB","vt":"str"},{"t":"eq","v":"AllUser/TempC","vt":"str"},{"t":"eq","v":"AllUser/TempD1","vt":"str"},{"t":"eq","v":"AllUser/TempD2","vt":"str"},{"t":"eq","v":"AllUser/TempD3","vt":"str"},{"t":"eq","v":"AllUser/TempD4","vt":"str"},{"t":"eq","v":"AllUser/TempD5","vt":"str"},{"t":"eq","v":"AllUser/GasBufferPressure","vt":"str"},{"t":"eq","v":"AllUser/DewarPressure","vt":"str"}],"checkall":"true","repair":false,"outputs":13,"x":302.7734489440918,"y":286.89066314697266,"wires":[["8296ff7.35204"],["8296ff7.35204"],["8296ff7.35204"],["8296ff7.35204"],["8296ff7.35204"],["8296ff7.35204"],["8296ff7.35204"],["8296ff7.35204"],["8296ff7.35204"],["8296ff7.35204"],["8296ff7.35204"],["8296ff7.35204"],["8296ff7.35204"]]},{"id":"5dfde8c.84a0418","type":"file","z":"78e630b8.b4c73","name":"","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":913.0199203491211,"y":290.7460823059082,"wires":[[]]},{"id":"7b3f3352.4169ec","type":"simpletime","z":"78e630b8.b4c73","name":"","x":627.5157127380371,"y":291.6718578338623,"wires":[["4998ac55.cd0c74"]]},{"id":"8296ff7.35204","type":"join","z":"78e630b8.b4c73","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"13","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":481.7812728881836,"y":291.5234441757202,"wires":[["7b3f3352.4169ec","b351fb51.33d928"]]},{"id":"4998ac55.cd0c74","type":"function","z":"78e630b8.b4c73","name":"","func":"var line =  \"Temp A\"+\",\"+\n            \"Temp B\"+\",\"+\n            \"Temp C\"+\",\"+\n            \"Temp D1\"+\",\"+\n            \"Temp D2\"+\",\"+\n            \"Temp D3\"+\",\"+\n            \"Temp D4\"+\",\"+\n            \"Temp D5\"+\",\"+\n            \"Total Volume\"+\",\"+\n            \"Overall Flow Rate\"+\",\"+\n            \"Dewar Pressure\"+\",\"+\n            \"Gas Buffer Pressure\"+\",\"+\n            \"Time\";\nmsg.filename = \"C:\\\\DataLogs\\\\User\\\\All\\\\\"+\"All \"+\n                msg.payload[\"AllUser/Time\"]+\".csv\";\nvar gateIsOpen = context.get(\"gateIsOpen\") || false;\n    if(msg.topic === \"gate\"){\n        gateIsOpen = msg.payload;\n        context.set(\"gateIsOpen\",gateIsOpen);\n    }\n    else{\n        if(gateIsOpen === \"true\"){\n            var firstline = context.get('firstline') || 0\n                if (firstline === 0){\n                    context.set('firstline',line);\n                    msg.payload = line;\n                    return msg;\n                }\n                else{\n                    var data =  msg.payload[\"AllUser/TempA\"]+\",\"+\n                                msg.payload[\"AllUser/TempB\"]+\",\"+\n                                msg.payload[\"AllUser/TempC\"]+\",\"+\n                                msg.payload[\"AllUser/TempD1\"]+\",\"+\n                                msg.payload[\"AllUser/TempD2\"]+\",\"+\n                                msg.payload[\"AllUser/TempD3\"]+\",\"+\n                                msg.payload[\"AllUser/TempD4\"]+\",\"+\n                                msg.payload[\"AllUser/TempD5\"]+\",\"+\n                                msg.payload[\"AllUser/TotalVolume\"]+\",\"+\n                                msg.payload[\"AllUser/OverallFlowRate\"]+\",\"+\n                                msg.payload[\"AllUser/DewarPressure\"]+\",\"+\n                                msg.payload[\"AllUser/GasBufferPressure\"]+\",\"+\n                                msg.myrawdate;\n                    msg.payload = data;\n                    return msg;\n                }\n        }\n        else{\n            context.set(\"first_line\",null);\n        }\n    }    ","outputs":1,"noerr":0,"x":776.0235462188721,"y":292.0390510559082,"wires":[["5dfde8c.84a0418"]]},{"id":"7e9bb883.8fdfc8","type":"mqtt in","z":"78e630b8.b4c73","name":"","topic":"AllUser/#","qos":"2","datatype":"auto","broker":"7ac66e23.82af7","x":130.07986450195312,"y":287.8229446411133,"wires":[["77ea86f2.c48e48"]]},{"id":"6aee2b14.a50454","type":"mqtt in","z":"78e630b8.b4c73","name":"","topic":"gate","qos":"2","datatype":"auto","broker":"7ac66e23.82af7","x":479.32951164245605,"y":131.90902709960938,"wires":[["4998ac55.cd0c74"]]},{"id":"b351fb51.33d928","type":"debug","z":"78e630b8.b4c73","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":637.0764198303223,"y":366.5278129577637,"wires":[]},{"id":"7ac66e23.82af7","type":"mqtt-broker","z":"","name":"","broker":"192.168.1.50","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

It should look like:
image
But instead it looks like:

Any help is appreciated!

What does the data coming into the switch look like?

Did you consider removing the switch node alltogether and just use the join node ? or do you get more topics ?

Are you sure you had deployed the flow before running that test? The result is exactly what would be expected if you had the number of messages set to 7 in the join node.

Otherwise, start node-red in a terminal and copy/paste the output (it should start with a Welcome to node-red message). That will show us what versions of tools you are using.

Node red running on the pi uses one timestamp node to request data from every sensor every second, and the resulting data is each put into it's own msg, then wired into the MQTT server with the topic of "All/".

I think @bakman2's point was that unless there are other All/# topics that you need to ignore then you don't need the switch node.

Seems like the switch node is superfluous, I just took it out of my working version, thanks for that tip. However, I tried removing it on the issue code and the same thing happens, the incoming messages get put into two separate msg objects.

The flows have been deployed on both my machine and the pi.
Node red running on my machine:


Node red running on the pi:
image

Does the join mis-behave on both machines?
[Edit] Could you post the full log please, also it is much better (and usually quicker) to copy/paste the text rather than doing a screenshot.

@dceejay It seems there is a serious bug in recent versions of the Join node. See this test flow.
If a join node is configured for key/value with, for example, two message parts, then it should not send anything until messages for two different topics have been received. In fact it sends after two messages of the same topic have been received. I am seeing it on 0.20.5 (as is @HYPER) but it works correctly on 0.19.4

image

[{"id":"1024679d.bef31","type":"inject","z":"4368baff.67ee0c","name":"","topic":"topic1","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":169,"y":472,"wires":[["2093efa4.5d1348"]]},{"id":"2093efa4.5d1348","type":"join","z":"4368baff.67ee0c","name":"Join two parts","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":361,"y":472,"wires":[["28af07e.1712ff8"]]},{"id":"28af07e.1712ff8","type":"debug","z":"4368baff.67ee0c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":544,"y":472,"wires":[]},{"id":"cc4aae8e.49e7c","type":"inject","z":"4368baff.67ee0c","name":"","topic":"topic2","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":169,"y":523,"wires":[["2093efa4.5d1348"]]},{"id":"b6a9f5ac.db50d","type":"comment","z":"4368baff.67ee0c","name":"Click topic1 then topic2 to see correct behaviour","info":"","x":344.5,"y":386,"wires":[]},{"id":"2e6524d0.79ef4c","type":"comment","z":"4368baff.67ee0c","name":"Keep clicking topic1 to see faulty behaviour","info":"","x":338,"y":420,"wires":[]}]

Ah, it seems to have been fixed in version 0.20.7, I must have missed that note.

@HYPER upgrade to the latest node-red and it should be ok.

1 Like

I updated both my computer and the Pi to the latest version and it fixed the issue. Thanks!