nodejs-foscam icon indicating copy to clipboard operation
nodejs-foscam copied to clipboard

Taking snapshot results in small, damaged JPEG

Open cylinderStudio opened this issue 10 years ago • 13 comments

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);

cylinderStudio avatar Dec 15 '14 23:12 cylinderStudio

I'll look into it

fvdm avatar Dec 17 '14 07:12 fvdm

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

fvdm avatar Dec 17 '14 08:12 fvdm

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'));

cylinderStudio avatar Dec 18 '14 17:12 cylinderStudio

I'll check it out

fvdm avatar Dec 21 '14 22:12 fvdm

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 avatar Dec 22 '14 19:12 fvdm

Yes that should work

fvdm avatar Dec 22 '14 20:12 fvdm

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

cylinderStudio avatar Dec 22 '14 20:12 cylinderStudio

hmz :cry:

fvdm avatar Dec 22 '14 20:12 fvdm

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)

  })

})

cylinderStudio avatar Dec 22 '14 20:12 cylinderStudio

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

fvdm avatar Dec 22 '14 20:12 fvdm

<?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>

cylinderStudio avatar Dec 22 '14 21:12 cylinderStudio

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

fvdm avatar Dec 22 '14 23:12 fvdm

Yep, emailing now.

cylinderStudio avatar Dec 22 '14 23:12 cylinderStudio