Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taking snapshot results in small, damaged JPEG #3

Open
cylinderStudio opened this issue Dec 15, 2014 · 13 comments
Open

Taking snapshot results in small, damaged JPEG #3

cylinderStudio opened this issue Dec 15, 2014 · 13 comments
Labels

Comments

@cylinderStudio
Copy link

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
Copy link
Owner

fvdm commented Dec 17, 2014

I'll look into it

@fvdm fvdm added the bug label Dec 17, 2014
fvdm added a commit that referenced this issue Dec 17, 2014
@fvdm
Copy link
Owner

fvdm commented Dec 17, 2014

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 added a commit that referenced this issue Dec 17, 2014
@cylinderStudio
Copy link
Author

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
Copy link
Owner

fvdm commented Dec 21, 2014

I'll check it out

fvdm added a commit that referenced this issue Dec 22, 2014
@fvdm
Copy link
Owner

fvdm commented Dec 22, 2014

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 😨

fvdm added a commit that referenced this issue Dec 22, 2014
@fvdm
Copy link
Owner

fvdm commented Dec 22, 2014

Yes that should work

@cylinderStudio
Copy link
Author

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

@fvdm
Copy link
Owner

fvdm commented Dec 22, 2014

hmz 😢

@cylinderStudio
Copy link
Author

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
Copy link
Owner

fvdm commented Dec 22, 2014

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

@cylinderStudio
Copy link
Author

<?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
Copy link
Owner

fvdm commented Dec 22, 2014

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

@fvdm fvdm added question and removed bug labels Dec 22, 2014
@cylinderStudio
Copy link
Author

Yep, emailing now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants