I can't get the all my data to join after setting the same topic for each payload.
My payload has three types. Temperature, Humidity and Pressure.
Ideally I would like a result of one payload with:
{
"Fri Feb 10 2023 12:00:00 GMT-0700 (Mountain Standard Time)": {
"ATMOSPHERIC_PRESSURE": 853,
"TEMPERATURE": 65,
"HUMIDITY": 74
},
"Fri Feb 10 2023 12:30:00 GMT-0700 (Mountain Standard Time)": {
"ATMOSPHERIC_PRESSURE": 752,
"TEMPERATURE": 198,
"HUMIDITY": 72
},
"Fri Feb 10 2023 13:00:00 GMT-0700 (Mountain Standard Time)": {
"ATMOSPHERIC_PRESSURE": 817,
"TEMPERATURE": 64.1,
"HUMIDITY": 17
},
"Fri Feb 10 2023 13:30:00 GMT-0700 (Mountain Standard Time)": {
"ATMOSPHERIC_PRESSURE": 773,
"TEMPERATURE": 227,
"HUMIDITY": 27
}
}
The result I'm getting only outputs one of the sensors.
{"payload":{"Fri Feb 10 2023 12:00:00 GMT-0700 (Mountain Standard Time)":{"ATMOSPHERIC_PRESSURE":853},"Fri Feb 10 2023 12:30:00 GMT-0700 (Mountain Standard Time)":{"ATMOSPHERIC_PRESSURE":752},"Fri Feb 10 2023 13:00:00 GMT-0700 (Mountain Standard Time)":{"ATMOSPHERIC_PRESSURE":817},"Fri Feb 10 2023 13:30:00 GMT-0700 (Mountain Standard Time)":{"ATMOSPHERIC_PRESSURE":773}},"_msgid":"fa07d1744983b353","topic":"2023-02-10T20:30:00.000Z"}
My Flow:
[{"id":"675390fa474fb666","type":"function","z":"d03c03b6d2f91f47","name":"measurementPeriod","func":"msg.measurementPeriod = msg.payload.measurementPeriodBase * msg.payload.measurementPeriodFactor\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1040,"y":280,"wires":[["81378a84bc7ada6d","b4fbaa1219fbccd1"]]},{"id":"b834cdc9633bbe11","type":"debug","z":"d03c03b6d2f91f47","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1560,"y":580,"wires":[]},{"id":"81378a84bc7ada6d","type":"split","z":"d03c03b6d2f91f47","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":670,"y":380,"wires":[["181c60c6663f838a"]]},{"id":"181c60c6663f838a","type":"switch","z":"d03c03b6d2f91f47","name":"channels","property":"parts.key","propertyType":"msg","rules":[{"t":"eq","v":"channels","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":920,"y":380,"wires":[["99b009ee7b2a4861"],[]]},{"id":"90f0f2704d744d6d","type":"switch","z":"d03c03b6d2f91f47","name":"Measurment Type","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"MEASUREMENT_TYPE_OK_ALARM","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":710,"y":460,"wires":[["29106dad075e522f"],["55fcce9c68c3fcdc"]]},{"id":"29106dad075e522f","type":"function","z":"d03c03b6d2f91f47","name":" numberOfMeasurements","func":"msg.numberOfMeasurements = 1 + (Math.abs([msg.payload.sampleOffsets][-1]) - 1) / msg.measurementPeriod\nmsg.numberOfMeasurements1 = msg.payload.sampleOffsets.length\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":990,"y":460,"wires":[[]]},{"id":"55fcce9c68c3fcdc","type":"switch","z":"d03c03b6d2f91f47","name":"Measurment Type","property":"channel.type","propertyType":"msg","rules":[{"t":"eq","v":"MEASUREMENT_TYPE_TEMPERATURE","vt":"str"},{"t":"eq","v":"MEASUREMENT_TYPE_ATMOSPHERIC_PRESSURE","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":690,"y":560,"wires":[["04c5b21205f53640"],["c715af1f95976fb8"],["895b89714e6a2f24"]]},{"id":"99b009ee7b2a4861","type":"split","z":"d03c03b6d2f91f47","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":1130,"y":380,"wires":[["e5b123514aa7fceb"]]},{"id":"e5b123514aa7fceb","type":"function","z":"d03c03b6d2f91f47","name":"function 5","func":"var flowpayload = flow.get(\"payload\")\n\nmsg.channel = msg.payload\nmsg.payload = flowpayload\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1320,"y":380,"wires":[["90f0f2704d744d6d"]]},{"id":"b4fbaa1219fbccd1","type":"change","z":"d03c03b6d2f91f47","name":"","rules":[{"t":"set","p":"payload","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":280,"wires":[[]]},{"id":"04c5b21205f53640","type":"function","z":"d03c03b6d2f91f47","name":"TEMPERATURE","func":"\nfor (var i = 0; i < msg.channel.sampleOffsets.length; i++) {\n\n node.send({\n payload: {\n \n value: (msg.channel.startPoint + msg.channel.sampleOffsets[i]) /10,\n type: msg.channel.type.replace(\"MEASUREMENT_TYPE_\", \"\"),\n time: new Date((msg.channel.timestamp * 1000) + (msg.measurementPeriod * 1000 * i ))\n\n }\n })\n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":970,"y":540,"wires":[["85aeed48b93bb237"]]},{"id":"895b89714e6a2f24","type":"function","z":"d03c03b6d2f91f47","name":"Other","func":"\n// @ts-ignore\nfor (var i = 0; i < msg.channel.sampleOffsets.length; i++) {\n\n node.send({\n payload: {\n \n value: (msg.channel.startPoint + msg.channel.sampleOffsets[i]),\n type: msg.channel.type.replace(\"MEASUREMENT_TYPE_\", \"\"),\n time: new Date((msg.channel.timestamp * 1000) + (msg.measurementPeriod * 1000 * i))\n\n }\n })\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":950,"y":620,"wires":[["85aeed48b93bb237"]]},{"id":"c715af1f95976fb8","type":"function","z":"d03c03b6d2f91f47","name":"ATMOSPHERIC_PRESSURE","func":"\n// @ts-ignore\nfor (var i = 0; i < msg.channel.sampleOffsets.length; i++) {\n\n node.send({\n payload: {\n\n value: (msg.channel.startPoint + msg.channel.sampleOffsets[i]) /10,\n type: msg.channel.type.replace(\"MEASUREMENT_TYPE_\", \"\"),\n time: new Date((msg.channel.timestamp * 1000) + (msg.measurementPeriod * 1000 * i ))\n\n }\n })\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":970,"y":580,"wires":[["85aeed48b93bb237"]]},{"id":"85aeed48b93bb237","type":"function","z":"d03c03b6d2f91f47","name":"function 12","func":"msg.topic = msg.payload.time\n\nvar sensortype = msg.payload.type\nvar value = msg.payload.value\n\nmsg.payload = {\n [sensortype]: value\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1250,"y":580,"wires":[["ea2496f022fd62ef"]]},{"id":"ea2496f022fd62ef","type":"join","z":"d03c03b6d2f91f47","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1410,"y":580,"wires":[["b834cdc9633bbe11"]]},{"id":"46816d4ab6ab19a0","type":"inject","z":"d03c03b6d2f91f47","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":660,"y":280,"wires":[["b7e8a65c272e6e37"]]},{"id":"b7e8a65c272e6e37","type":"function","z":"d03c03b6d2f91f47","name":"function 14","func":"msg.payload = { \"serialNum\": \"EjRWeA==\", \"batteryStatus\": true, \"measurementPeriodBase\": 180, \"channels\": [{ \"type\": \"MEASUREMENT_TYPE_TEMPERATURE\", \"timestamp\": 1676055600, \"startPoint\": 650, \"sampleOffsets\": [0, 1330, -9, 1620] }, { \"type\": \"MEASUREMENT_TYPE_HUMIDITY\", \"timestamp\": 1676055600, \"startPoint\": 74, \"sampleOffsets\": [0, -2, -57, -47] }, { \"type\": \"MEASUREMENT_TYPE_ATMOSPHERIC_PRESSURE\", \"timestamp\": 1676055600, \"startPoint\": 8530, \"sampleOffsets\": [0, -1010, -360, -800] }], \"nextTransmissionAt\": 1676063488, \"transferReason\": 1, \"measurementPeriodFactor\": 10 }\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":830,"y":280,"wires":[["675390fa474fb666"]]}]