-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcamera.js
57 lines (47 loc) · 1.67 KB
/
camera.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/
/*********************************************
This camera example takes a picture. If a
directory is specified with the --upload-dir
flag, the picture is saved to that directory.
*********************************************/
var tessel = require('tessel');
var camera = require('camera-vc0706').use(tessel.port['A']);
var notificationLED = tessel.led[3]; // Set up an LED to notify when we're taking a picture
// Wait for the camera module to say it's ready
camera.on('ready', function() {
notificationLED.high();
// Take the picture
camera.takePicture(function (err, imageBuffer) {
if (err) return console.error(err);
var request = http.request({
hostname: '192.168.2.30', // Where your other process is running
port: 3000,
path: '/upload-pic',
method: 'POST',
headers: {
'Content-Type': 'image/jpg',
'Content-Length': imageBuffer.length
}
});
request.write(imageBuffer);
});
// camera.takePicture(function(err, image) {
// if (err) {
// console.log('error taking image', err);
// } else {
// notificationLED.low();
// // Name the image
// var name = 'picture-' + Math.floor(Date.now()*1000) + '.jpg';
// // Save the image
// console.log('Picture saving as', name, '...');
// process.sendfile(name, image);
// console.log('done.');
// // Turn the camera off to end the script
// camera.disable();
// }
// });
});
camera.on('error', function(err) {
console.error(err);
});