How to FTP a Snapshot to my Router FTP Server ?

Has anyone sent up a Vera 2 to FTP a camera snapshot directly to a FTP Server ? I have an ASUS RT-N16 with a FTP Server . I currently have Vera set up to send to MCV servers when I have a tripped condition on my Motion Detector. Sure would like to store the pictures directly to my Asus Router.
I have the router already setup for FTP and use it for other things but I guess I would need some Luup code to do it from Vera.
I’ve looked through the forums but all I could find was some code to save your logs to a FTP server.

Can anyone help ?

No responses…
Guess this is not possible, or nobody know how to do this.
I’ll keep researching the forum and see if I can find anything.

Thanks anyway

This is one of those things that you wish that Vera was more flexible with, and had this option as default!

Does your camera have any options to do this directly to an FTP server; maybe based on some sort of event like an external trigger (many have this); if it did then you could trigger it via a relay from Vera, and or a compatible alarm panel?! Some cameras also have an API for this sort of thing!

If not then I’m sure there is a way to hack around it with Vera!

@Strangely,

I’m currently using a Foscam 8910 that sends a picture via FTP to my routers USB stick based on motion. This works fine but light changes ect. cause more pictures to be sent than needed.

If there is a hack to have a picture sent from Vera based say by a zwave motion detector then that would be great ! I just would like to store the pic’s on my server. I have been able to use some luup code in a scene to do the PTZ controls, just need to trigger a picture and save it by FTP.

Thanks for any idea’s you or others might have.

Here’s one way to do it:

  1. Make a scene that runs when your motion detector is tripped.
  2. Add Lua code to get the image from your camera with curl and store it somewhere in /tmp, then ftpput it to your router.

If you can, I strongly recommend against [tt]ftpput[/tt]. It’s part of the reason that Vera needs frequent reboots, albeit somewhat indirectly[sup]*[/sup].

Instead use [tt]curl[/tt] for both legs of the transmission, just using the FTP options for the second leg.

Also, make liberal use of the timeout options on [tt]curl[/tt], like [tt]–max-time, --connect-timeout[/tt], etc, to avoid the script from locking up when the other end doesn’t respond. If the script [overall] takes too long to run it’ll cause Vera itself to restart.

[sup]*[/sup][tt]ftpput[/tt] has no timeouts and will lockup when Vera’s FTP servers go south, which they do from time to time, and logs eventually pile up until the Vera unit fails…

Thanks guys for the info !
Could you be kind enough to supply some example code to do this. I’m a beginner using luup but an example would be great.

Thanks again

You should first experiment using [tt]curl[/tt] on the command line of Vera. This will get you familiar with the component parts, which you can then string together in Luup (using [tt]os.execute(…)[/tt] )

You can login to the command line using:
http://wiki.micasaverde.com/index.php/Logon_Vera_SSH

an example command might be:

    curl http://www.google.com

This will send the output to the screen, then you can save that to a file[sup]*[/sup] like:

    curl --output /tmp/myimage.jpg http://www.google.com

for other options, use

    curl --help

or you can read the manual pages for the tool here:
curl - How To Use

Once you get them working there, you can put them into Luup using:

    os.execute(...)

eg. [tt]os.execute(‘curl --output /tmp/myimage.jpg http://www.google.com’)[/tt]

[sup]*[/sup] Note this saves to a single file, so only one “transfer” can occur at any time. There are more advanced techniques if required.

@ Guessed

That is exactly what I was looking for. I will spend some time experimenting with the info you have supplied. I don’t want to be a pest !

Thanks again

Whew !

Well after a whole lot of reading,head scratching,trial & error,and some cussing, I came up with these two lines of code that actually work sort of for a Foscam.

os.execute(‘curl -o /tmp/Outside.jpg [name]:[pass]@xxx.xxx.xx.xx:[port]/snapshot.cgi’)

os.execute (‘ftpput xxx.xxx.xx.xx -u [name] -p [pass] /MyStuff/Vera/PIC$(date +%m%d_% H%M).jpg /tmp/Outside.jpg’)

The file shows up in Vera \tmp
The file also shows up on my FTP server.

The only problem I get is when I run it in the TEST Luup in Vera I get “Code failed” but it still works.
I must be missing something stupid on my part.
Got any idea’s on what I’m doing wrong ? ???

Not sure what would cause the Code failed error, but you can look at the log [tt]/var/log/cmh/LuaUPnP.log[/tt] on Vera and it’ll have a log output corresponding to whatever the problem is.

Also, you should use [tt]curl[/tt] for both the HTTP-based GET as well as the FTP-based PUT. The “-T” option (hyperlinked in doc above) is the pointer.

In both cases you’ll also want to liberally use the timeout options of CURL to protect yourself against a device being offline, hung (etc) as this will cause Vera to restart in very bad ways.

@guessed,

Could you please show me how to fix this. I understand that this is a learning experience for me but My head is mush trying to figure this out. (Lua,Luup,Curl,FTP ect) Help !

EDIT:
Got the -T command to work finally so I’m now able to use curl for both as you recommended.
Next to tackle is the timeout -m I think…
Took me two glasses of wine tonight to get this far ! ;D

Collectively, from the command line, it’ll be something like:

curl --connect-timeout 5 --max-time 20 --silent --trace tmp.out \ --user logs:logspassword --create-dirs --upload-file tmp1.lua \ ftp://logs1.mios.com/31234567/

You can remove the [tt]–trace[/tt] option, since I put it in there to debug some stuff, but it’s handy when you need it.

@guessed

Many Thanks for all the help you have done for me on this!
So this is what I’m using to Get the image… curl --connect-timeout 5 --max-time 20 -o /tmp/myimage.jpg [my camera url]

Seems to work fine, one thing I’m not clear on is the difference between “-o” and “–output” , does it make a difference in my case ?

Thanks again

Cool, glad its working for you.

Looks like the -o and --output-file options are the same:
curl - How To Use

So based on the findings, what was the exact luup code needed to be placed into the luup tab when it finally worked? Also, is there a way to add to the file name the date and time for organization purposes? (i.e. “MyImg-01-30-2013-1130.jpg”, where 1130 is 11:30am)

This feature highly interests me since you are currently unable to email images from vera. I’d love to be able to instantly send an image from my camera that way to any of my ftp accounts.