Node RED - Multiple Flow,collect data,Payload


#1

Hi everyone. I have a problems about how payload collect multiple flow data?

I have tried join node and I dont know why I cannot get the information. The flow like below.

`[{"id":"55eda2de.25396c","type":"switch","z":"c1b977c7.6f56e8","name":"","property":"IntegerTag1","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":90,"y":680,"wires":[["4094b09a.5bed6","49be1e7a.982ba","c09cc593.ac4318"],[]]},{"id":"44311bb0.b22104","type":"join","z":"c1b977c7.6f56e8","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":550,"y":580,"wires":[["a6a5d5a3.c12f28"]]},{"id":"195431a5.3bc84e","type":"inject","z":"c1b977c7.6f56e8","name":"","topic":"","payload":"","payloadType":"date","repeat":"3","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":500,"wires":[[]]},{"id":"3e1f132b.b1245c","type":"debug","z":"c1b977c7.6f56e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":710,"y":580,"wires":[]},{"id":"a6a5d5a3.c12f28","type":"function","z":"c1b977c7.6f56e8","name":"last","func":"boolean = msg.IntegerTag1\nabc=msg.payload;\nvar output ={abc}\n    Activees = context.get('temporaryy');\n    if(boolean=== 1 && boolean != Activees) {\n        context.set('temporaryy', boolean);\n         msg={payload:{output}};\n    }else return null;\n\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":520,"wires":[["3e1f132b.b1245c"]]},{"id":"4094b09a.5bed6","type":"function","z":"c1b977c7.6f56e8","name":"Active or Off(main_fail)","func":"d = new Date();\nhour = d.getHours();\nminute = d.getMinutes();\nsecond = d.getSeconds();\nyear = d.getFullYear();\nmonth = d.getMonth() +1;\nday = d.getDate();\nboolean = msg.IntegerTag1;\nUp_Down = msg.decimalTag1;\nstrings = msg.stringTag1;\n\nif((strings === \"main_fail\")&&(boolean === 0 || boolean === 1)){\n    Actives = context.get('temporary');\n    if(boolean === 1 && boolean != Actives) {\n        context.set('temporary', boolean);\n         msg={payload:{index:\"101\",\n         type:\"Active\",\n             cat:\"Alarm\",\n             tag:\"main_fail\",\n             description:\"Main Power Fail\",\n             start_date:{year:year,month:('0'+month).slice(-2),day:('0'+day).slice(-2)},\n             start_time:{hour:('0'+hour).slice(-2),minute:('0'+minute).slice(-2),second:('0'+second).slice(-2)},\n             end_date:{year:-9999,month:-9999,day:-9999},\n             end_time:{hour:-9999,minute:-9999,second:-9999},\n             related_data:{on_data:{upstream:Up_Down,downstream:Up_Down},off_data:{upstream:-8888.88,downstream:-8888.88}}\n         }};\n    }else{\n        msg={payload:\"null\"}\n    }\n}else{\n        msg={payload:\"null\"}\n    }\n\nreturn msg;  ","outputs":1,"noerr":0,"x":360,"y":580,"wires":[["44311bb0.b22104"]]},{"id":"49be1e7a.982ba","type":"function","z":"c1b977c7.6f56e8","name":"Active or Off(s_estop)","func":"d = new Date();\nhour = d.getHours();\nminute = d.getMinutes();\nsecond = d.getSeconds();\nyear = d.getFullYear();\nmonth = d.getMonth() +1;\nday = d.getDate();\nboolean = msg.IntegerTag1;\nUp_Down = msg.decimalTag1;\nstrings = msg.stringTag1;\n\nif((strings === \"s_estop\")&&(boolean === 0 || boolean === 1)){\n    Active = context.get('temporarys');\n    if(boolean === 1 && boolean != Active) {\n        context.set('temporarys', boolean);\n         msg={payload:{index:\"100\",\n         type:\"Active\",\n             cat:\"Alarm\",\n             tag:\"s_estop\",\n             description:\"Gate E Stop Pressed\",\n             start_date:{year:year,month:('0'+month).slice(-2),day:('0'+day).slice(-2)},\n             start_time:{hour:('0'+hour).slice(-2),minute:('0'+minute).slice(-2),second:('0'+second).slice(-2)},\n             end_date:{year:-9999,month:-9999,day:-9999},\n             end_time:{hour:-9999,minute:-9999,second:-9999},\n             related_data:{on_data:{upstream:Up_Down,downstream:Up_Down},off_data:{upstream:-8888.88,downstream:-8888.88}}\n         }};\n    }else{\n        msg={payload:\"null\"}\n    }\n}else{\n        msg={payload:\"null\"}\n    }\n\nreturn msg;  ","outputs":1,"noerr":0,"x":361,"y":615,"wires":[["44311bb0.b22104"]]},{"id":"c09cc593.ac4318","type":"function","z":"c1b977c7.6f56e8","name":"Active or Off(upsensor_fail)","func":"d = new Date();\nhour = d.getHours();\nminute = d.getMinutes();\nsecond = d.getSeconds();\nyear = d.getFullYear();\nmonth = d.getMonth() +1;\nday = d.getDate();\nboolean = msg.IntegerTag1;\nUp_Down = msg.decimalTag1;\nstrings = msg.stringTag1;\n\nif((strings === \"upsensor_fail\")&&(boolean === 0 || boolean === 1)){\n    upsensor_fail_Active = context.get('upsensor_fail_Active_temporarys');\n    if(boolean === 1 && boolean != upsensor_fail_Active) {\n        context.set('upsensor_fail_Active_temporarys', boolean);\n         msg={payload:{index:\"130\",\n         type:\"Active\",\n             cat:\"Alarm\",\n             tag:\"upsensor_fail\",\n             description:\"Gate Upstream Sensor Fail\",\n             start_date:{year:year,month:('0'+month).slice(-2),day:('0'+day).slice(-2)},\n             start_time:{hour:('0'+hour).slice(-2),minute:('0'+minute).slice(-2),second:('0'+second).slice(-2)},\n             end_date:{year:-9999,month:-9999,day:-9999},\n             end_time:{hour:-9999,minute:-9999,second:-9999},\n             related_data:{on_data:{upstream:Up_Down,downstream:Up_Down},off_data:{upstream:-8888.88,downstream:-8888.88}}\n         }};\n    }else if(boolean === 0 && boolean != upsensor_fail_Active) {\n        context.set('upsensor_fail_Active_temporarys', boolean);\n        a = msg.upsensor_fail[0];\n        msg={payload:{index:\"130\",\n             type:\"Off\",\n             cat:\"Alarm\",\n             tag:\"upsensor_fail\",\n             description:\"Gate Upstream Sensor Fail\",\n             start_date :{year:a.start_date_year, month:a.start_date_month, day:a.start_date_day},\n             start_time :{hour:a.start_time_hour, minute:a.start_time_minute, second:a.start_time_second},\n             end_date:{year:year,month:('0'+month).slice(-2),day:('0'+day).slice(-2)},\n             end_time:{hour:('0'+hour).slice(-2),minute:('0'+minute).slice(-2),second:('0'+second).slice(-2)},\n             related_data:{on_data :{upstream:a.on_data_upstream, downstream:a.on_data_downstream},off_data:{upstream:Up_Down,downstream:Up_Down}}\n        }};\n    }else{\n        msg={payload:\"null\"}\n    }\n}else{\n        msg={payload:\"null\"}\n    }\nreturn msg;  ","outputs":1,"noerr":0,"x":382,"y":652,"wires":[["44311bb0.b22104"]]}]`

I would like the output is “null,data,null”.

Before try the join node I also has tried the array and combine all the payload together. The payload cannot collect all the data.

I’m so sorry that I will reply late.
TQVM.


#2

If I understood what you need… Try this:

[{"id":"2c4e5e86.ff371a","type":"join","z":"65fcc2b4.feed4c","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":796,"y":1160,"wires":[["9ee758c7.16ce38"]]},{"id":"4adb6381.a6a5bc","type":"http response","z":"65fcc2b4.feed4c","name":"","statusCode":"204","headers":{},"x":806,"y":1200,"wires":[]},{"id":"68ece9c9.d9f968","type":"change","z":"65fcc2b4.feed4c","name":"set payload value","rules":[{"t":"set","p":"payload","pt":"msg","to":"req.params.value","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":596,"y":1180,"wires":[["4adb6381.a6a5bc","2c4e5e86.ff371a"]]},{"id":"5e8261dc.beb0e8","type":"change","z":"65fcc2b4.feed4c","name":"set topic 1","rules":[{"t":"set","p":"topic","pt":"msg","to":"a","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":376,"y":1140,"wires":[["68ece9c9.d9f968"]]},{"id":"d1e1cc8f.7bad6","type":"change","z":"65fcc2b4.feed4c","name":"set topic 2","rules":[{"t":"set","p":"topic","pt":"msg","to":"b","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":376,"y":1180,"wires":[["68ece9c9.d9f968"]]},{"id":"6337cd25.a16f8c","type":"change","z":"65fcc2b4.feed4c","name":"set topic 3","rules":[{"t":"set","p":"topic","pt":"msg","to":"c","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":376,"y":1220,"wires":[["68ece9c9.d9f968"]]},{"id":"580339d1.47104","type":"inject","z":"65fcc2b4.feed4c","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":178,"y":1143,"wires":[["5e8261dc.beb0e8"]]},{"id":"44e1e43b.46be5c","type":"inject","z":"65fcc2b4.feed4c","name":"","topic":"","payload":"2","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":168,"y":1182,"wires":[["d1e1cc8f.7bad6"]]},{"id":"36a9d25.4dc34ae","type":"inject","z":"65fcc2b4.feed4c","name":"","topic":"","payload":"3","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":161,"y":1228,"wires":[["6337cd25.a16f8c"]]},{"id":"9ee758c7.16ce38","type":"function","z":"65fcc2b4.feed4c","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":957,"y":1158,"wires":[[]]}]

I found this on internet, but forgot where exactly I got this.

Thank you.