node-raspicam icon indicating copy to clipboard operation
node-raspicam copied to clipboard

Cant get the standard code example to work on rpi3

Open Olian04 opened this issue 7 years ago • 3 comments

I'm trying to get the standards code example to work.

var RaspiCam = require("raspicam");

var camera = new RaspiCam({ 
    mode: 'photo',
    output: './img/photo.png'
});

//listen for the "start" event triggered when the start method has been successfully initiated
camera.on("start", function(){
	console.log('Camera started!');
});

//listen for the "read" event triggered when each new photo/video is saved
camera.on("read", function(err, timestamp, filename){ 
	console.log('File saved: "' + filename + '"');
});

//listen for the "stop" event triggered when the stop method was called
camera.on("stop", function(){
	console.log('Camera stoped!');
});

//listen for the process to exit when the timeout has been reached
camera.on("exit", function(){
    console.log('Exiting program...');
});

camera.start();

setTimeout(() => camera.stop(), 500); // Stop after 0.5s

It creates the img folder, however it doesn't output a file, nor does it fire the event for reading data.

Output:

calling....
/opt/vc/bin/raspistill --output ./img/photo.png --width 640 --height 480
Camera started!
Camera stoped!
Exiting program...

However i can get the util to work the "normal" way: raspistill -o cam.jpg

Olian04 avatar Sep 01 '17 16:09 Olian04

What happens if you use the encoding and/or timeout options here: https://github.com/troyth/node-raspicam/blob/69e31b875b1b25b39340827740771fbb16c24427/eg/photo.js. They should be optional, but I just realized that I am always setting both in my code.

lynnaloo avatar Oct 21 '17 03:10 lynnaloo

I am running the examples on Linux so I changed the raspicam.js line 2 to read: //This only works on windows //spawn = require("child_process").spawn, spawn = require("child_process").exec,

as per the node.js docs spawn only works on windoze platforms: The importance of the distinction between child_process.exec() and child_process.execFile() can vary based on platform. On Unix-type operating systems (Unix, Linux, macOS) child_process.execFile() can be more efficient because it does not spawn a shell. On Windows, however, .bat and .cmd files are not executable on their own without a terminal, and therefore cannot be launched using child_process.execFile(). When running on Windows, .bat and .cmd files can be invoked using child_process.spawn()

cujo0072 avatar Jan 11 '18 14:01 cujo0072

@cujo0072 could you open a pr including a os check and then this code?

Olian04 avatar Jan 11 '18 14:01 Olian04