Hi I want to make some adjustment to usb camera. So once the push button is pressed, webcam will capture the image but the problem is after it is captured, it will saved as 'image01.png' and next time when I press the button, the webcam will saved as 'image01.png' again. So there is only one photo although I have pressed push button several times. So I need some suggestion to capture and saved one photo at a time when I press the button.
You need to increment the number after the file name, or inject a timestamp... I haven't done it myself yet (no USB cam on my RPi) but this is probably done with a function node that replaces the "File Name" field in the usbcamera
node You can probably search for something similar in this forum.
PS blurry screenshots don't help. The proper way is to Export your flow and paste it (formatted with the </> key) here.
This is what I came up with to place in a function
node prior to the usbcamera
node
var now = new Date().toLocaleString("en-US");
now = now.replace(",",""); // clear out comma
now = now.replace(/\//g,"-"); // replace all slashes
now = now.replace(/ /g,"_"); // replace all spaces
msg.filename = "image_" + now;
return msg;
Or at least it seems to do the job in the error msg I get, what with not having a USB camera connected
USB Camera error: Error: Command failed: fswebcam -q -r 320x240 --jpeg 100 -D 2 --no-banner /home/pi/Pictures/image_7-8-2021_9:11:40_PM.jpg
/bin/sh: 1: fswebcam: not found
As shown here with a proper screen snipping
[{"id":"43641b25.40b524","type":"tab","label":"Flow 8","disabled":false,"info":""},{"id":"fa215a7c.a1dd78","type":"usbcamera","z":"43641b25.40b524","filemode":"1","filename":"{{filename}}","filedefpath":"1","filepath":"","fileformat":"jpeg","resolution":"1","name":"","x":610,"y":320,"wires":[["754da95e.5324e8"]]},{"id":"a8302fbf.07fcb","type":"inject","z":"43641b25.40b524","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":320,"wires":[["7db34e5a.61d7a"]]},{"id":"754da95e.5324e8","type":"debug","z":"43641b25.40b524","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":790,"y":320,"wires":[]},{"id":"7db34e5a.61d7a","type":"function","z":"43641b25.40b524","name":"To Date & Time","func":"var now = new Date().toLocaleString(\"en-US\");\nnow = now.replace(\",\",\"\"); // clear out comma\nnow = now.replace(/\\//g,\"-\"); // replace all slashes\nnow = now.replace(/ /g,\"_\"); // replace all spaces\nmsg.filename = \"image_\" + now;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":320,"wires":[["fa215a7c.a1dd78"]]}]
thank you Gunner I will try to do that now.
it works with timestamp but for me I want to capture image once the pushbutton is pressed. So once the push button is pressed, the logic is 0 or 1. So this 0 or 1 will trigger the camera to capture image so any chance on how to proceed with that? I mean how to write increment function?
flows.json (1.4 KB)
When it is this basic I shouldn't do it all for you
Just use your button node instead of the inject node, the timestamp comes from the new Date()
constructor in the function, not the inject node.
Nor do you need all those other change nodes, a 1 will trigger the camera and the date/time stamp will make each image separate from the rest (by the seconds).
Well, OK... the camera will trigger on a 0 as well, but then just wrap the function commands in a if()
condition
if (msg.payload == 1){
var now = new Date().toLocaleString("en-US");
now = now.replace(",",""); // clear out comma
now = now.replace(/\//g,"-"); // replace all slashes
now = now.replace(/ /g,"_"); // replace all spaces
msg.filename = "image_" + now;
return msg;
}
Thanks Gunner, it works and sorry to trouble you with basic stuff, as I am very new to nodered.
No trouble... what I meant by not doing it all was not giving you the entire flow again, just the info so you could put the pieces together, and you did! I don't mind helping those that show an interest and attempts in learning.
And besides, I am not that far ahead in learning NR myself
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.