Created
May 22, 2018 13:37
-
-
Save conalllaverty/c51f76b5f04c4b50401d5b659918e1a0 to your computer and use it in GitHub Desktop.
Wia Raspberry Pi Camera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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