Grabbing net cam images using vbscript only

General HouseBot discussion. Any issues that don't fit into any of the other topics belong here.
roussell
Advanced Member
Posts: 268
Joined: Wed Dec 15, 2004 9:07 am
Location: Pelham, AL

Grabbing net cam images using vbscript only

Post by roussell »

I have been using wget and a combination of batch files and vbscript to pull images from a few Axis 2100 network cameras. Everything is working fine, but I would like to get rid of wget and use a pure vbscript solution to grab and store images. I found a starter-script on the web and modified it to suit my needs:

Code: Select all

URL="http://10.10.220.100/axis-cgi/jpg/image.cgi"
TEMPPATH = "C:\temp\"
outputfile= "C:\Program Files\HouseBot\Config\images\garage.jpg" 
const ForReading = 1 , ForWriting = 2 , ForAppending = 8
Set fsoMain = CreateObject("Scripting.FileSystemObject")
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
Set fsResults = fsoMain.OpenTextFile(OUTPUTFILE,ForWriting, True)
Call objHTTP.Open("GET", url, FALSE)
objHTTP.Send
 
for i = 1 to lenb(objHTTP.ResponseBody)
 fsResults.write Chr(Ascb(midb(objHTTP.ResponseBody,i,1)))
Next
fsResults.Close()
This works, but is painfully slow. On average it will take 5-10 seconds to grab an image and write it to the disk. By comparison, wget will perform the same operation in less than 1 second. Processor utilization will also spike up pretty high while the script is running. I know I'm trying to fix something that isn't broken...but... does anyone have any suggestions for speeding up this process using only vbscript?

TIA,
Terry
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Post by Osler »

Try using XMLHTTP and the ADOStream object. Dunno if this will speed things up but it works for me:

Code: Select all

Dim URL
Dim File
Dim xmlHTTP
Dim ADOStream

URL = "http://www.goes.noaa.gov/GIFS/ECI8.JPG"
File = "C:\Test.JPG"

Set xmlHTTP = CreateObject("MSXML2.XMLHTTP")
Call xmlHTTP.Open("GET", URL, False)
xmlHTTP.Send()
Set ADOStream = CreateObject("ADODB.Stream")
With ADOStream
	.Type = 1
	.Open()
	.Write(xmlHTTP.responseBody)
	.SaveToFile File, 2
	.Close()
End With
Set ADOStream = Nothing
Set xmlHTTP = Nothing
Osler
roussell
Advanced Member
Posts: 268
Joined: Wed Dec 15, 2004 9:07 am
Location: Pelham, AL

Post by roussell »

That's much better, it's almost as fast as wget - only about .5 second behind. Thanks Osler!
Terry
raptor_demon
Senior Member
Posts: 141
Joined: Tue Jul 07, 2009 12:55 pm
Location: NC

Re: Grabbing net cam images using vbscript only

Post by raptor_demon »

Hi,

I am having a small issue that this script does not seem to get the latest image, i had it running every 5 seconds for 2 days and it did not update the image every 5 seconds, it looked more like every 4 hours.

Has anyone else had this issue?

raptor
roussell
Advanced Member
Posts: 268
Joined: Wed Dec 15, 2004 9:07 am
Location: Pelham, AL

Re: Grabbing net cam images using vbscript only

Post by roussell »

On the property that's storing the path to your image - make sure you have checked "Allow same value changes". That's usually the problem when you expect something to be updating in housebot and it isn't.

Terry
raptor_demon
Senior Member
Posts: 141
Joined: Tue Jul 07, 2009 12:55 pm
Location: NC

Re: Grabbing net cam images using vbscript only

Post by raptor_demon »

Hi,

It still doesnt work,

For some reason it just will not update... i told it to create a new file every 30 mins and it just doesn't want to update every time. After a few hours it finally changes images but that's it.

If i visit the cameras address say 192.168.1.1/img.jpg it works every time.


I have tried leaving hte video web page up and that did not help.

Any ideas?
UPDATE:

Restarting housebot allows it to capture the correct image once. after that it never get the image a second time.
Raptor
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Re: Grabbing net cam images using vbscript only

Post by Osler »

What type of machine is the software remote running on that you are using to view the images? I have issues with dynamic images on some of my devices that rdp into the server to access the software remote. Do the images show when you run the software remote on an actual PC (i.e., no rdp involved)?

Also, change the interval to 1 minute and ensure that the image in the theme folder is actually changing like you expect it to.

Osler
raptor_demon
Senior Member
Posts: 141
Joined: Tue Jul 07, 2009 12:55 pm
Location: NC

Re: Grabbing net cam images using vbscript only

Post by raptor_demon »

Hi,

I forgot to add i have not implemented this to a Software remote yet.

I have been looking at the folder where the images are stored and the files are being created ok but the files are the same.

I added some text to the script that creates a new filename every time the script is run to allow me to use it as a security camera.

The server is running windows home server with an Atom 330 processor and 2gb of ram.

I have noticed that if i restart housebot it works the first time no problem but after that it does not work.

Thanks in advance for your help.

Raptor
roussell
Advanced Member
Posts: 268
Joined: Wed Dec 15, 2004 9:07 am
Location: Pelham, AL

Re: Grabbing net cam images using vbscript only

Post by roussell »

Paste the script you're using here along with any relevant screenshots of the HB device/task that's executing the script. Perhaps that will help to shed some light on the problem.

Terry
raptor_demon
Senior Member
Posts: 141
Joined: Tue Jul 07, 2009 12:55 pm
Location: NC

Re: Grabbing net cam images using vbscript only

Post by raptor_demon »

Hi Terry,

Here is the code,

Code: Select all

Dim URL
Dim File
Dim xmlHTTP
Dim ADOStream
Dim Date1
Date1 = Day(Date)&"-"&Month(Date)&"-"&Year(Date)&"-"&hour(now)&"h"&minute(now)&"m"&second(now)
URL = "http://192.168.2.160/image.jpg"
File = "D:\shares\Photos\Security Cam\Security-"&Date1&".jpg"

Set xmlHTTP = CreateObject("MSXML2.XMLHTTP")
Call xmlHTTP.Open("GET", URL, False)
xmlHTTP.Send()
Set ADOStream = CreateObject("ADODB.Stream")
With ADOStream
   .Type = 1
   .Open()
   .Write(xmlHTTP.responseBody)
   .SaveToFile File, 2
   .Close()
End With
Set ADOStream = Nothing
Set xmlHTTP = Nothing
All i am doing is running the script as a device:

Any ideas?

Raptor
Attachments
Untitled.jpg
Untitled.jpg (156.04 KiB) Viewed 13887 times
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Re: Grabbing net cam images using vbscript only

Post by Osler »

Ok, try this instead. I have not debugged it but it should alleviate two possible problems. The first is with Microsoft.xmlhttp. I have experienced some goofiness with this particular object in the past. I have used WinHTTP to do the heavy lifting in this script and then transfer the data to ADOStream to save the binary file. The second is that you have network congestion and the camera is unresponsive. The script will catch this (i.e., camera server does not return 200 after the request) and pop an error message. If this solves the problem, great. If you start getting pop-ups...we can fix that as well with a bit more work. [NOTE: my code has not been debugged....but it should be close]

Code: Select all

Option Explicit

Dim URL
Dim File
Dim xmlHTTP
Dim ADOStream
Dim Date1

Date1 = Day(Date)&"-"&Month(Date)&"-"&Year(Date)&"-"&hour(now)&"h"&minute(now)&"m"&second(now)
URL = "http://192.168.2.160/image.jpg"
File = "D:\shares\Photos\Security Cam\Security-"&Date1&".jpg"

Set xmlHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
Call xmlHTTP.open ("GET", FullURL, False)
xmlHTTP.send()
Sleep(500)
If xmlHTTP.status = 200 Then
	Set ADOStream = CreateObject("ADODB.Stream")
	With ADOStream
   		Type = 1
   		Open()
   		Write(xmlHTTP.responseBody)
   		SaveToFile File, 2
   		Close()
	End With
	Set ADOStream = Nothing
Else
	MsgBox "There was an error."
End If
Set xmlHTTP = Nothing
Osler
raptor_demon
Senior Member
Posts: 141
Joined: Tue Jul 07, 2009 12:55 pm
Location: NC

Re: Grabbing net cam images using vbscript only

Post by raptor_demon »

Hi,

thanks for the reply,

Ha dto fix a few things but this code gives me the following error:

Code: Select all

Option Explicit

Dim URL
Dim File
Dim xmlHTTP
Dim ADOStream
Dim Date1

Date1 = Day(Date)&"-"&Month(Date)&"-"&Year(Date)&"-"&hour(now)&"h"&minute(now)&"m"&second(now)
URL = "http://192.168.2.160/image.jpg"
File = "D:\shares\Photos\Security Cam\Security-"&Date1&".jpg"

Set xmlHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
Call xmlHTTP.open ("GET", URL, False)
xmlHTTP.send()
Sleep(500)
If xmlHTTP.status = 200 Then
   Set ADOStream = CreateObject("ADODB.Stream")
   With ADOStream
         .Type = 1
         .Open()
         .Write(xmlHTTP.responseBody)
         .SaveToFile File, 2
         .Close()
   End With
   Set ADOStream = Nothing
Else
   MsgBox "There was an error."
End If
Set xmlHTTP = Nothing

error:
Error 0 a connection withthe server could not be estabilished...


Any ideas?

Any ideas?
Raptor
raptor_demon
Senior Member
Posts: 141
Joined: Tue Jul 07, 2009 12:55 pm
Location: NC

Re: Grabbing net cam images using vbscript only

Post by raptor_demon »

Just thought i would add I have tried the same script to grab the album art from squeeze center and it has the same behavior.
edgar
Member
Posts: 95
Joined: Tue Mar 24, 2009 11:14 pm
Location: Springfield, VA

Re: Grabbing net cam images using vbscript only

Post by edgar »

Hi All,

If you still are having touble getting your VB script to work may want to try AUTOHOTKEY. You can make scripts with it and also convert your scripts into .exe files (optional:which is what I do) and call them from HB. I use this to update wx images I pull off the web for example.

The UrlDownloadToFile command is what you need to pull your jpg off your IP camera at specified intervals.

Just a thought I would throw this out there as a possible solution.

BTW I have found that AUTOHOTKEY works very well along side HB. I also use it to control a SWRemtoe with a 2.4ghz $10 'presentation' remote designed to work with Powerpoint.

Best of Luck

Kevin
roussell
Advanced Member
Posts: 268
Joined: Wed Dec 15, 2004 9:07 am
Location: Pelham, AL

Re: Grabbing net cam images using vbscript only

Post by roussell »

What is the task that fires the device? where is the mechanism to make it repeatedly fire? You should have a property in you device that is the path to the image. That property is the one that you will use to display the image in a swremote. That property should have the "Allow same value changes" checkbox checked is the image is being updated but always has the same filename. You should then have a task that executes that script at whatever interval you decide. An alternative to the task is to have the script loop forever, however if you do that remember to insert a "sleep x" (where x is the interval in milliseconds) in teh script loop to prevent the script fro consuming all of your resources.
Terry
Post Reply