Hi @George_Santiago
We have released a new version of the plugin with some improvements. For your use case it may resolve some of your issues and make your flows simpler. Check it out and let us know how we can improve.
Indeed, this flow is not really adequate for your use case, and you would need to have a number of intermediate nodes that can bring all the necessary information together before calling the endpoint.
I’ve tried to achieve your requirements with a flow, I’ll leave it here so you can test it out and import it into your instance.
[{"id":"a14c5e72386ffa8c","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"e3fb8ac7b3202db0","type":"inject","z":"a14c5e72386ffa8c","name":"every 40 mins","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"2400","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":140,"y":60,"wires":[["fe1bc17ed8808139"]]},{"id":"fe1bc17ed8808139","type":"asset-iterator","z":"a14c5e72386ffa8c","name":"get all buckets","asset":"bucket","filter":".*","assetType":"","assetGroup":"","server":"e227a9126e2fd92c","x":380,"y":60,"wires":[["d81471d9b3334a4b"]]},{"id":"8642e90719bdeaa3","type":"function","z":"a14c5e72386ffa8c","name":"set 'last_ts' for not records between 30/40 mins?","func":"console.log(msg.payload);\n\nif (msg.payload.length > 0) {\n \n let millis = Date.now() - msg.payload[0].ts;\n let minutes = Math.floor(millis/60000);\n\n payload = {};\n let lastTs;\n if (minutes > 30 && minutes < 40) {\n lastTs = (new Date(msg.payload[0].ts)).toUTCString();\n }\n payload[\"last_ts\"] = lastTs;\n payload[\"complete\"] = true;\n return payload;\n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":240,"wires":[["594569c280f3f784"]]},{"id":"61b6a49484dc24ed","type":"bucket-read","z":"a14c5e72386ffa8c","name":"read last","bucket":"","filter":"simple","timespanSequence":"","timespanValue":"","timespanUnits":"","maxTs":"","minTs":"","items":"1","limit":"","aggregation":"","aggregationType":"","sort":"desc","server":"e227a9126e2fd92c","x":560,"y":180,"wires":[["8642e90719bdeaa3"]]},{"id":"d81471d9b3334a4b","type":"change","z":"a14c5e72386ffa8c","name":"get bucket & device","rules":[{"t":"set","p":"bucket","pt":"msg","to":"payload.bucket","tot":"msg","dc":true},{"t":"set","p":"device","pt":"msg","to":"payload.config.device","tot":"msg","dc":true},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":60,"wires":[["016d2d35099bed1a"]]},{"id":"594569c280f3f784","type":"join","z":"a14c5e72386ffa8c","name":"join bucket with last_ts","mode":"custom","build":"merged","property":"","propertyType":"full","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"30","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":540,"y":320,"wires":[["237f60f677cc51d2"]]},{"id":"016d2d35099bed1a","type":"switch","z":"a14c5e72386ffa8c","name":"Only buckets containing device","property":"device","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":890,"y":60,"wires":[["11ba1e2ac6291973"]]},{"id":"11ba1e2ac6291973","type":"delay","z":"a14c5e72386ffa8c","name":"one msg every 5s","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"5","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":190,"y":180,"wires":[["61b6a49484dc24ed","594569c280f3f784"]]},{"id":"2df54b4067186659","type":"change","z":"a14c5e72386ffa8c","name":"clean message","rules":[{"t":"delete","p":"bucket","pt":"msg"},{"t":"delete","p":"device","pt":"msg"},{"t":"delete","p":"last_ts","pt":"msg"},{"t":"delete","p":"payload.complete","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":400,"wires":[["07dfdb481f4e6306"]]},{"id":"237f60f677cc51d2","type":"switch","z":"a14c5e72386ffa8c","name":"remove messages without last_ts","property":"last_ts","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":860,"y":320,"wires":[["2df54b4067186659"]]},{"id":"07dfdb481f4e6306","type":"batch","z":"a14c5e72386ffa8c","name":"sets messages batch by time","mode":"interval","count":10,"overlap":0,"interval":"20","allowEmptySequence":false,"topics":[],"x":800,"y":400,"wires":[["9adf2fb97d12f982"]]},{"id":"2ad545ea5a725de6","type":"comment","z":"a14c5e72386ffa8c","name":"also sets trigger time","info":"","x":810,"y":440,"wires":[]},{"id":"9adf2fb97d12f982","type":"join","z":"a14c5e72386ffa8c","name":"joins batch","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1040,"y":400,"wires":[["64e174db32df1d24"]]},{"id":"64e174db32df1d24","type":"endpoint-call","z":"a14c5e72386ffa8c","name":"","endpoint":"test_endpoint","server":"e227a9126e2fd92c","x":740,"y":540,"wires":[[]]},{"id":"89df0fa5d86c3b23","type":"comment","z":"a14c5e72386ffa8c","name":"sets last_ts","info":"","x":860,"y":240,"wires":[]},{"id":"57335e6983a5d71c","type":"comment","z":"a14c5e72386ffa8c","name":"checks last_ts existence","info":"","x":1120,"y":320,"wires":[]},{"id":"e227a9126e2fd92c","type":"thinger-server","host":"console.thinger.io","name":"","ssl":true}]
The result message would be something like this:
[
{
"bucket": "drybox",
"device": "esp32_example",
"last_ts": "Mon, 22 Nov 2021 19:28:40 GMT"
},
{
"bucket": "number",
"device": "esp32_example",
"last_ts": "Mon, 22 Nov 2021 19:48:41 GMT"
},
{
"bucket": "string",
"device": "esp32_example",
"last_ts": "Mon, 22 Nov 2021 19:48:41 GMT"
}
]
I encourage you to check it out as well as the new possibilities with the new Node-RED Plugin version
Regards!