Broadcasting an image to a webpage [SOLVED]

Forum for questions and support relating to the 1.24.x releases only.
Locked
gazoo
Posts: 45
Joined: Mon Nov 30, 2009 1:04 pm

Broadcasting an image to a webpage [SOLVED]

Post by gazoo »

This has been asked before, but I could never find a good answer anywhere on the forum.

I have a few cameras an in addition to motion detect/record mode, I would also like to periodically ftp the image (say every 1 minute) to a server regardless of motion.

I currently have a windows program that does this, but I want to go away from it because it crashes often (windows, not so much the program) and uses lots of resources. I use the image to put it on a simple web page so I can get to it from anywhere (like from my phone.)

One of the cameras can do this on its own (I have a glitch, but that's another post), but the other two can't.

I've got the ZM up and running (ubuntu 9.10, ZM 1.24.x) using the /video.cgi function of each camera (they are IP based).
Last edited by gazoo on Sat Jan 02, 2010 1:16 am, edited 1 time in total.
User avatar
kingofkya
Posts: 1110
Joined: Mon Mar 26, 2007 6:07 am
Location: Las Vegas, Nevada

Post by kingofkya »

what if on the server that needs the image set up a cron job to wget the image from the zm server
http://serverip/zm/cgi-bin/nph-zms?mode ... uffer=1000
gazoo
Posts: 45
Joined: Mon Nov 30, 2009 1:04 pm

Post by gazoo »

That sounds like a great idea. It's a home ISP account, and I'm not sure of it's PHP capabilities. Although, I have no idea how to that on the server side and don't even know if it's a PHP issue. It would stand to reason that they have some basic server side capabilities, but you never know - they could have done without..

I still think it might be easier to do it from my machine. I don't know how to automate or script ftp uploads though. If it were a file manipulation (cp, move, etc.) I could do it, the FTP is what is throwing me off..
gazoo
Posts: 45
Joined: Mon Nov 30, 2009 1:04 pm

Post by gazoo »

I just found a simple bash script for FTP'ing stuff..real easy, should have just looked before I leaped. Now how do I pull a JPEG image off my monitors at any given time..that wget command? Will I be getting off of ZM or some raw part of the cameras? Will it have the timestamps?

So I figured I'll run CRON every minute on that script and the script will FTP my web server, pull an image off each camera, and PUT the JPEG into the directory.
gazoo
Posts: 45
Joined: Mon Nov 30, 2009 1:04 pm

Post by gazoo »

Any advice as how to save off a JPEG image from a ZM camera (locally)? Once I have it saved, I have a script to FTP it.
User avatar
kingofkya
Posts: 1110
Joined: Mon Mar 26, 2007 6:07 am
Location: Las Vegas, Nevada

Post by kingofkya »

ok take a look at http://www.adminschoice.com/docs/crontab.htm#Commands

and the comand you want to run is

wget http://serverip/zm/cgi-bin/nph-zms?mode ... uffer=1000 -O /savelocation
gazoo
Posts: 45
Joined: Mon Nov 30, 2009 1:04 pm

Post by gazoo »

kingofkya wrote:ok take a look at http://www.adminschoice.com/docs/crontab.htm#Commands

and the comand you want to run is

wget http://serverip/zm/cgi-bin/nph-zms?mode ... uffer=1000 -O /savelocation
So this wget command will save the it locally?

I was trying to save a jpeg on the zoneminder computer, and then ftp it over to another location..If I'm reading your response correctly, you are trying to save it off at the webserver, right?
gazoo
Posts: 45
Joined: Mon Nov 30, 2009 1:04 pm

Post by gazoo »

I tried this locally and got this file:
nph-zms?mode=single

but it isn't in avi, jpg, or any other type that I could read with an external viewer..
gazoo
Posts: 45
Joined: Mon Nov 30, 2009 1:04 pm

Post by gazoo »

Ok I played around with this command: http://192.168.1.235/cgi-bin/nph-zms?mo ... &monitor=1

I put this into a browser and I got a single JPG image. However, when I do it with wget I get unusable stuff, NOT an image. How do I get this saved off in a script using wget for example?

What gives? And it isn't renaming the file with the -O filename
gazoo
Posts: 45
Joined: Mon Nov 30, 2009 1:04 pm

Post by gazoo »

King, what do you think? The file I get on the single frame capture is not something I can save off and play anywhere else.
gazoo
Posts: 45
Joined: Mon Nov 30, 2009 1:04 pm

Post by gazoo »

Ok, I figured this out, mostly. I really wish this board was more interactive, but maybe there's just not a lot of people out there who need help on ZM.

Anyhow, hopefully this will help someone out in the future.

This is the command to get a single picture downloaded:
Replace monitor=1 with whatever number monitor.

THE QUOTES WAS WHAT WAS MISSING! Damn quotes.. :x

Now comes the cool part. I haven't done this yet, but I'm pretty sure it will work.

You have to write a script to pull down the stuff, and then FTP it. You set this script up to run on a CRONTAB every number of minutes/hours/whatever you want. Here's an EXAMPLE, I haven't done it yet so I don't know if this exact thing will work:
#!/bin/bash
#change directory to where you want to store your image
cd ~/imagestorage
#get image
wget -O picture.jpg "http://localhost/cgi-bin/nph-zms?mode=single&monitor=1"
#store FTP server variables here
HOST='www.*.com'
USER='*************'
PASSWD='*********'
#start FTP
ftp -n -v $HOST << EOT
ascii
user $USER $PASSWD
prompt
cd /{wherever you need to change to}
bin
put picture.jpg
bye
EOT
Got the FTP info from here: http://www.linuxforums.org/forum/linux- ... cript.html

I hope this works. It will be a while before I get a chance to vet this out. Also, this has NO error handling so maybe that must be taken care of too. This will pretty much suffice for me though..

This will pretty much upload a current image on an ftp server to be displayed on an HTML site every x time interval (crontab must be set to call the script though.)
gazoo
Posts: 45
Joined: Mon Nov 30, 2009 1:04 pm

Post by gazoo »

FYI-

I implemented this and it works like a charm! :D

I call it from cron every minute (*/1 * * * *) and it works awesome.

You have to make the script executable and away you go.
User avatar
henriquejf
Posts: 77
Joined: Tue Feb 10, 2009 12:01 pm
Location: Brazil

Post by henriquejf »

i have also implemented the same exact script here, and it works perfectly; using ubuntu 9.10 server and zm 1.24.2.2 from svn;

TKS for the script/solution to both of you !

think you should change the topic to solved;
-----------------------
Henrique Barbosa
Consultant
Juiz de Fora, MG - Brazil
Locked