Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save conalllaverty/c51f76b5f04c4b50401d5b659918e1a0 to your computer and use it in GitHub Desktop.
Save conalllaverty/c51f76b5f04c4b50401d5b659918e1a0 to your computer and use it in GitHub Desktop.
Wia Raspberry Pi Camera
'use strict';
var wia = require('wia')('your-device-secret-key');
var fs = require('fs');
var RaspiCam = require("raspicam");
// Setup the camera
var camera = new RaspiCam({
mode: 'photo',
output: __dirname + '/photo.jpg',
encoding: 'jpg'
});
// Listen for the "start" event triggered when the start method has been successfully initiated
camera.on("start", function(){
console.log("Starting to take photo.");
});
// Listen for the "read" event triggered when each new photo/video is saved
camera.on("read", function(err, timestamp, filename){
console.log("New photo created.", timestamp, filename);
// Publish the photo to Wia
wia.events.publish({
name: 'photo',
file: fs.createReadStream(__dirname + '/' + filename)
});
});
// Take a photo
camera.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment