fvdm / nodejs-foscam

Remote control, view and config a Foscam or compatible IP camera
https://www.npmjs.com/package/foscam
The Unlicense
124 stars 31 forks source link

Taking snapshot results in small, damaged JPEG #3

Open cylinderStudio opened 9 years ago

cylinderStudio commented 9 years ago

I have a Foscam FI9831W which appears to function well, as I can login and changes settings, check the live feed of it at 720p. The library loads fine in my NodeJS application, but the snapshot() method takes a picture and saves it as a JPEG with 344 bytes that's damaged or truncated and can't be opened.

var cam1 = require('foscam');

cam1.setup({
    host: '192.168.1.3',
    port: 88,
    user: 'myCamera',
    pass: 'myPassword'
}, function(status) {
    if (!status) {
        console.log('Error connecting to Cam1');
    }
});

cam1.snapshot('cam1.jpg', console.log);
fvdm commented 9 years ago

I'll look into it

fvdm commented 9 years ago

My own camera went awol so I can't test here. Could you please install the module from temporary branch issue3 and see if it works?

npm install fvdm/nodejs-foscam#issue3

cylinderStudio commented 9 years ago

Unfortunately that didn't work for me.

I noticed in the snapshot() method that you're using fs.writeFile(). Right now, I'm accessing my Foscams by direct http requests to the cameras, and I see the same truncated/corrupt file issue when using fs.writeFile(). When using the node 'request' module for my requests, and using fs.createWriteStream() in the code below, it saves the image correctly. Could that fs.writeFile() be the problem here, as well?

request.get('http://192.168.1.2:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=camAdmin&pwd=myPassword).pipe(fs.createWriteStream('images/save.jpg'));
fvdm commented 9 years ago

I'll check it out

fvdm commented 9 years ago

I found the problem, fs.createWriteStream is indeed the solution. My camera had a lower resolution than your 720p, the filesize might have been just within range for fs.writeFile.

Can you please retry? I'm flying blind without a camera to test on and the code is kind of ancient :fearful:

fvdm commented 9 years ago

Yes that should work

cylinderStudio commented 9 years ago

OK, installing from the same... npm install fvdm/nodejs-foscam#issue3 I'm still getting a corrupt image, 345 bytes.

fvdm commented 9 years ago

hmz :cry:

cylinderStudio commented 9 years ago

Bummer! It must be something related to this model of Foscam. Using the code below, the rotation doesn't occur either:

var cam = require('foscam')

cam.setup({
  host: '192.168.1.2',
  port: 88,
  user: 'myUsername',
  pass: 'myPassword'
})

// start rotating left
cam.control.decoder('left', function() {

  // stop rotation
  cam.control.decoder('stop left', function() {

    // take a picture and store it on your computer
    cam.snapshot('path/save.jpg', console.log)

  })

})
fvdm commented 9 years ago

What do you get when you open the 345 bytes file in a plain text editor?

cylinderStudio commented 9 years ago
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <title>404 - Not Found</title>
 </head>
 <body>
  <h1>404 - Not Found</h1>
 </body>
</html>
fvdm commented 9 years ago

Ah that explains a lot. Can you provide the HTML of one of the web interface pages that has those control buttons?

cylinderStudio commented 9 years ago

Yep, emailing now.