async problem?
DanielWeeber opened this issue · comments
I am using your library to fetch a snapshot from multiple cameras at once and save them to the local filesystem.
Sometimes it is just working fine, sometimes I have the problem that the same image from the same camera is saved in the wrong file.
I am assuming I've did something wrong with the async function or something similar, so I am looking for help here. :)
const` onvif = require('node-onvif');
const fs = require('fs');
async function kamera_screenshot(ip) {
let device = new onvif.OnvifDevice({
xaddr: "http://" + ip + "/onvif/device_service",
user : 'admin',
pass : 'admin'
});
device.init().then(() => {
return device.fetchSnapshot().then((res) => {
fs.writeFile("/tmp/" + ip + ".jpg", res.body, {encoding: 'binary'}, function (fd, err) {
if (err) throw err;
});
});
});
return;
}
kamera_screenshot("192.168.0.1");
kamera_screenshot("192.168.0.2");
kamera_screenshot("192.168.0.3");
kamera_screenshot("192.168.0.4");
So, in this example, I have two pictures from camera 192.168.0.1 in the 192.168.0.1.jpg AND 192.168.0.2.jpg (or any other combination)