I've been trying to fix this error for two days now, it seems to happen at: wia.event.publish. The picture is taken successfully but publishing an event seems to be an issue.
'use strict';
const Wia = require('wia');
var wia = new Wia('my-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.event.publish({
name: 'photo',
file: fs.createReadStream(__dirname + '/' + filename)
});
});
// Take a photo
camera.start();