Hi everyone.
i wanted to make time lapse with esp32 cam, the capture works and to save the picture works but only with predefined filename.
i have no idea how to change the file name with function, googled everything but nothing helps. maybe the structure of flow is wrong. [{"id":"f294910.f0d6b7","type":"http request","z":"b09f8b86.982948","name":"","method":"GET","ret":"bin","paytoqs":"ignore","url":"http://192.168.8.185/capture","tls":"","persist":false,"proxy":"","authType":"","x":330,"y":160,"wires":[["61466c09.36c0b4","124ca5a2.d78b6a"]],"outputLabels":["{{payload}}"]},{"id":"f3c9477d.0c36b8","type":"inject","z":"b09f8b86.982948","name":"get image","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"","payloadType":"date","x":520,"y":20,"wires":[["f294910.f0d6b7"]]},{"id":"ba89cb7c.457638","type":"debug","z":"b09f8b86.982948","name":"","active":true,"console":"false","complete":"payload","x":910,"y":120,"wires":[]},{"id":"5a301d20.a5cfe4","type":"file","z":"b09f8b86.982948","name":"save image","filename":"","appendNewline":false,"createDir":true,"overwriteFile":"true","x":1010,"y":60,"wires":[["3fe2de27.ec8322","d5e2c8f1.cd32a8"]]},{"id":"db28bec7.af775","type":"image","z":"b09f8b86.982948","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":720,"y":160,"wires":[]},{"id":"61466c09.36c0b4","type":"image viewer","z":"b09f8b86.982948","name":"","width":160,"data":"payload","dataType":"msg","x":490,"y":180,"wires":[[]]},{"id":"124ca5a2.d78b6a","type":"base64","z":"b09f8b86.982948","name":"","action":"","property":"payload","x":520,"y":120,"wires":[["db28bec7.af775","8b177b28.8fa588","5a301d20.a5cfe4"]]},{"id":"d5e2c8f1.cd32a8","type":"file in","z":"b09f8b86.982948","name":"","filename":"","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":1230,"y":60,"wires":[["2dd9c49a.5a23cc"]]},{"id":"2dd9c49a.5a23cc","type":"image","z":"b09f8b86.982948","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":1200,"y":140,"wires":[]},{"id":"3fe2de27.ec8322","type":"image","z":"b09f8b86.982948","name":"","width":160,"data":"payload","dataType":"msg","thumbnail":false,"active":true,"pass":false,"outputs":0,"x":1000,"y":160,"wires":[]},{"id":"8b177b28.8fa588","type":"function","z":"b09f8b86.982948","name":"","func":"var now = new Date();\n// Create formatted time\nvar yyyy = now.getFullYear();\nvar mm = now.getMonth() < 9 ? \"0\" + (now.getMonth() + 1) : (now.getMonth() + 1); // getMonth() is zero-based\nvar dd = now.getDate() < 10 ? \"0\" + now.getDate() : now.getDate();\nvar hh = now.getHours() < 10 ? \"0\" + now.getHours() : now.getHours();\nvar mmm = now.getMinutes() < 10 ? \"0\" + now.getMinutes() : now.getMinutes();\nvar ss = now.getSeconds() < 10 ? \"0\" + now.getSeconds() : now.getSeconds();\n\n// file path with / at the end\nvar path = \"/home/pi/bildessss/\"; // This is the path\nvar filename = \"cam3_\"+yyyy+mm+dd+\"-\"+hh+mm+ss+\".jpg\"; // file name\nreturn msg.filename;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":720,"y":60,"wires":[["5a301d20.a5cfe4","ba89cb7c.457638"]],"outputLabels":["msg.filename"]}]
Could you tell me which node image and image-viewer belong to?
From the code above it appears that you base64 is going to save. That save node needs a msg.filename to be sent with the rest of the mesage. I think if you disconnect the direct base64 to save and let the function node add the filename to the msg object you'll solve the issue (I think).
oops, sorry, not fully awake.
// file path with / at the end
var path = "/home/pi/bildessss/"; // This is the path
var filename = "cam3_"+yyyy+mm+dd+"-"+hh+mm+ss+".jpg"; // file name
return msg.filename;
Change the above (in the function node) to this:
// file path with / at the end
var path = "/home/pi/bildessss/"; // This is the path
var filename = "cam3_"+yyyy+mm+dd+"-"+hh+mm+ss+".jpg"; // file name
msg.filename = path + filename;
return msg;
What this does is to add the filename attribute to the msg.
And remove the wires between the base64 node and the save node.
wow thanks this works perfectly, o ok now i understand how the return works. thank you
YW, can you post the image nodes (what node-red-contrib-... name). When i looked image up I got at least half a dozen. Sorry I'm curious.
one is node-red-contrib-image-output https://flows.nodered.org/node/node-red-contrib-image-output
and other is node-red-contrib-image-tools https://flows.nodered.org/node/node-red-contrib-image-tools
output is only simple debug picture mode but tools it has some cool features like image scaling, invert ,text on top ... and other features like barcode output
Thanks! I haven't tackled cameras yet. A future project. I'm still trying to work out how to get the images to the TV which my likes to watch in some easy to use manner.
PS yes node-red is a different way of thinking (ex: async programming).
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.